#ifndef _LIBIOUTIL_FILEWRITER_H
#define _LIBIOUTIL_FILEWRITER_H

#include <path_defs.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#define FW_OK                0
#define FW_VOLUME_OPEN_ERROR 1
#define FW_DESC_ERROR        2
#define FW_NOT_FILE          3
#define FW_VOLUME_NOT_OPENED 4
#define FW_WRITE_ERROR       5
#define FW_CURSOR_OOB        6
#define FW_CREATE_FILE_ERROR 7

#define FW_CREATE_FILE (1 << 0)
#define FW_APPEND      (1 << 1)
#define FW_OPEN        (1 << 31)

struct filewriter {
  char volume[VOLUME_MAX];
  char path[PATH_MAX];
  size_t write_cursor;
  size_t file_size;
  uint32_t flags;
};

int filewriter_init (struct filewriter* fw, const char* volume, const char* path, uint32_t flags);

int filewriter_fini (struct filewriter* fw);

int filewriter_write (struct filewriter* fw, uint8_t* buffer, size_t buffer_size);

#endif // _LIBIOUTIL_FILEWRITER_H
