tar_archive.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <storage/storage.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef struct TarArchive TarArchive;
  9. typedef struct Storage Storage;
  10. typedef enum {
  11. TAR_OPEN_MODE_READ = 'r',
  12. TAR_OPEN_MODE_WRITE = 'w',
  13. TAR_OPEN_MODE_STDOUT = 's' /* to be implemented */
  14. } TarOpenMode;
  15. TarArchive* tar_archive_alloc(Storage* storage);
  16. bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode);
  17. void tar_archive_free(TarArchive* archive);
  18. /* High-level API - assumes archive is open */
  19. bool tar_archive_unpack_to(
  20. TarArchive* archive,
  21. const char* destination,
  22. Storage_name_converter converter);
  23. bool tar_archive_add_file(
  24. TarArchive* archive,
  25. const char* fs_file_path,
  26. const char* archive_fname,
  27. const int32_t file_size);
  28. bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const char* path_prefix);
  29. int32_t tar_archive_get_entries_count(TarArchive* archive);
  30. bool tar_archive_unpack_file(
  31. TarArchive* archive,
  32. const char* archive_fname,
  33. const char* destination);
  34. /* Optional per-entry callback on unpacking - return false to skip entry */
  35. typedef bool (*tar_unpack_file_cb)(const char* name, bool is_directory, void* context);
  36. void tar_archive_set_file_callback(TarArchive* archive, tar_unpack_file_cb callback, void* context);
  37. /* Low-level API */
  38. bool tar_archive_dir_add_element(TarArchive* archive, const char* dirpath);
  39. bool tar_archive_file_add_header(TarArchive* archive, const char* path, const int32_t data_len);
  40. bool tar_archive_file_add_data_block(
  41. TarArchive* archive,
  42. const uint8_t* data_block,
  43. const int32_t block_len);
  44. bool tar_archive_file_finalize(TarArchive* archive);
  45. bool tar_archive_store_data(
  46. TarArchive* archive,
  47. const char* path,
  48. const uint8_t* data,
  49. const int32_t data_len);
  50. bool tar_archive_finalize(TarArchive* archive);
  51. #ifdef __cplusplus
  52. }
  53. #endif