buffered_file_stream.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <storage/storage.h>
  4. #include "stream.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /**
  9. * Allocate a file stream with buffered read operations
  10. * @return Stream*
  11. */
  12. Stream* buffered_file_stream_alloc(Storage* storage);
  13. /**
  14. * Opens an existing file or creates a new one.
  15. * @param stream pointer to file stream object.
  16. * @param path path to file
  17. * @param access_mode access mode from FS_AccessMode
  18. * @param open_mode open mode from FS_OpenMode
  19. * @return True on success, False on failure. You need to close the file even if the open operation failed.
  20. */
  21. bool buffered_file_stream_open(
  22. Stream* stream,
  23. const char* path,
  24. FS_AccessMode access_mode,
  25. FS_OpenMode open_mode);
  26. /**
  27. * Closes the file.
  28. * @param stream pointer to file stream object.
  29. * @return True on success, False on failure.
  30. */
  31. bool buffered_file_stream_close(Stream* stream);
  32. /**
  33. * Forces write from cache to the underlying file.
  34. * @param stream pointer to file stream object.
  35. * @return True on success, False on failure.
  36. */
  37. bool buffered_file_stream_sync(Stream* stream);
  38. /**
  39. * Retrieves the error id from the file object
  40. * @param stream pointer to stream object.
  41. * @return FS_Error error id
  42. */
  43. FS_Error buffered_file_stream_get_error(Stream* stream);
  44. #ifdef __cplusplus
  45. }
  46. #endif