file_helper.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <stdint.h>
  3. #include <mlib/m-string.h>
  4. #include <storage/storage.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. extern const char flipper_file_eoln;
  9. extern const char flipper_file_eolr;
  10. /**
  11. * Negative seek helper
  12. * @param file
  13. * @param offset
  14. * @return bool
  15. */
  16. bool file_helper_seek(File* file, int32_t offset);
  17. /**
  18. * Writes data to a file as a hexadecimal array.
  19. * @param file
  20. * @param data
  21. * @param data_size
  22. * @return true on success write
  23. */
  24. bool file_helper_write_hex(File* file, const uint8_t* data, const uint16_t data_size);
  25. /**
  26. * Reads data as a string from the stored rw pointer to the \\n symbol position. Ignores \r.
  27. * @param file
  28. * @param str_result
  29. * @return true on success read
  30. */
  31. bool file_helper_read_line(File* file, string_t str_result);
  32. /**
  33. * Moves the RW pointer to the beginning of the next line
  34. * @param file
  35. * @return bool
  36. */
  37. bool file_helper_seek_to_next_line(File* file);
  38. /**
  39. * Read one value from array-like string (separated by ' ')
  40. * @param file
  41. * @param value
  42. * @return bool
  43. */
  44. bool file_helper_read_value(File* file, string_t value, bool* last);
  45. /**
  46. * Write helper
  47. * @param file
  48. * @param data
  49. * @param data_size
  50. * @return bool
  51. */
  52. bool file_helper_write(File* file, const void* data, uint16_t data_size);
  53. /**
  54. * Write EOL
  55. * @param file
  56. * @return bool
  57. */
  58. bool file_helper_write_eol(File* file);
  59. /**
  60. * Appends part of one file to the end of another file
  61. * @param file_from
  62. * @param file_to
  63. * @param start_offset
  64. * @param stop_offset
  65. * @return bool
  66. */
  67. bool file_helper_copy(File* file_from, File* file_to, uint64_t start_offset, uint64_t stop_offset);
  68. #ifdef __cplusplus
  69. }
  70. #endif