#ifndef FILE_IO_HPP_
#define FILE_IO_HPP_

#ifdef _WIN32
#   include <windows.h>
#else
#   include <fcntl.h>
#   include <unistd.h>
#endif

#include <string>

/**
 * @brief A thread-safe, cross-platform file handler, with more features than stdlib.
 */
class FileIO final
{
private:
#ifdef _WIN32
    HANDLE hFile = NULL;
#else
    int fd = -1;
#endif

public:
    ~FileIO();

    bool create(std::string path);
    bool open(std::string path);
    bool lock();
    void close();

    bool read(size_t offset, void *data, size_t size);
    bool write(size_t offset, const void *data, size_t size);

    bool sync();

    bool isOpen();

    size_t size();
};

#endif