archive.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifndef MUPDF_FITZ_ARCHIVE_H
  2. #define MUPDF_FITZ_ARCHIVE_H
  3. #include "mupdf/fitz/system.h"
  4. #include "mupdf/fitz/context.h"
  5. #include "mupdf/fitz/buffer.h"
  6. #include "mupdf/fitz/stream.h"
  7. typedef struct fz_archive_s fz_archive;
  8. struct fz_archive_s
  9. {
  10. fz_stream *file;
  11. const char *format;
  12. void (*drop_archive)(fz_context *ctx, fz_archive *arch);
  13. int (*count_entries)(fz_context *ctx, fz_archive *arch);
  14. const char *(*list_entry)(fz_context *ctx, fz_archive *arch, int idx);
  15. int (*has_entry)(fz_context *ctx, fz_archive *arch, const char *name);
  16. fz_buffer *(*read_entry)(fz_context *ctx, fz_archive *arch, const char *name);
  17. fz_stream *(*open_entry)(fz_context *ctx, fz_archive *arch, const char *name);
  18. };
  19. /*
  20. fz_new_archive: Create and initialize an archive struct.
  21. */
  22. fz_archive *fz_new_archive_of_size(fz_context *ctx, fz_stream *file, int size);
  23. #define fz_new_derived_archive(C,F,M) \
  24. ((M*)Memento_label(fz_new_archive_of_size(C, F, sizeof(M)), #M))
  25. /*
  26. fz_open_archive: Open a zip or tar archive
  27. Open a file and identify its archive type based on the archive
  28. signature contained inside.
  29. filename: a path to a file as it would be given to open(2).
  30. */
  31. fz_archive *fz_open_archive(fz_context *ctx, const char *filename);
  32. /*
  33. fz_open_archive_with_stream: Open zip or tar archive stream.
  34. Open an archive using a seekable stream object rather than
  35. opening a file or directory on disk.
  36. */
  37. fz_archive *fz_open_archive_with_stream(fz_context *ctx, fz_stream *file);
  38. /*
  39. fz_open_directory: Open a directory as if it was an archive.
  40. A special case where a directory is opened as if it was an
  41. archive.
  42. Note that for directories it is not possible to retrieve the
  43. number of entries or list the entries. It is however possible
  44. to check if the archive has a particular entry.
  45. path: a path to a directory as it would be given to opendir(3).
  46. */
  47. fz_archive *fz_open_directory(fz_context *ctx, const char *path);
  48. /*
  49. fz_drop_archive: Release an open archive.
  50. Any allocations for the archive are freed.
  51. */
  52. void fz_drop_archive(fz_context *ctx, fz_archive *arch);
  53. /*
  54. fz_archive_format: Returns the name of the archive format.
  55. */
  56. const char *fz_archive_format(fz_context *ctx, fz_archive *arch);
  57. /*
  58. fz_count_archive_entries: Number of entries in archive.
  59. Will always return a value >= 0.
  60. */
  61. int fz_count_archive_entries(fz_context *ctx, fz_archive *arch);
  62. /*
  63. fz_list_archive_entry: Get listed name of entry position idx.
  64. idx: Must be a value >= 0 < return value from
  65. fz_count_archive_entries. If not in range NULL will be
  66. returned.
  67. */
  68. const char *fz_list_archive_entry(fz_context *ctx, fz_archive *arch, int idx);
  69. /*
  70. fz_has_archive_entry: Check if entry by given name exists.
  71. If named entry does not exist 0 will be returned, if it does
  72. exist 1 is returned.
  73. name: Entry name to look for, this must be an exact match to
  74. the entry name in the archive.
  75. */
  76. int fz_has_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);
  77. /*
  78. fz_open_archive_entry: Opens an archive entry as a stream.
  79. name: Entry name to look for, this must be an exact match to
  80. the entry name in the archive.
  81. */
  82. fz_stream *fz_open_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);
  83. /*
  84. fz_read_archive_entry: Reads all bytes in an archive entry
  85. into a buffer.
  86. name: Entry name to look for, this must be an exact match to
  87. the entry name in the archive.
  88. */
  89. fz_buffer *fz_read_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);
  90. /*
  91. fz_is_tar_archive: Detect if stream object is a tar achieve.
  92. Assumes that the stream object is seekable.
  93. */
  94. int fz_is_tar_archive(fz_context *ctx, fz_stream *file);
  95. /*
  96. fz_open_tar_archive: Open a tar archive file.
  97. An exception is throw if the file is not a tar archive as
  98. indicated by the presence of a tar signature.
  99. filename: a path to a tar archive file as it would be given to
  100. open(2).
  101. */
  102. fz_archive *fz_open_tar_archive(fz_context *ctx, const char *filename);
  103. /*
  104. fz_open_tar_archive_with_stream: Open a tar archive stream.
  105. Open an archive using a seekable stream object rather than
  106. opening a file or directory on disk.
  107. An exception is throw if the stream is not a tar archive as
  108. indicated by the presence of a tar signature.
  109. */
  110. fz_archive *fz_open_tar_archive_with_stream(fz_context *ctx, fz_stream *file);
  111. /*
  112. fz_is_zip_archive: Detect if stream object is a zip archive.
  113. Assumes that the stream object is seekable.
  114. */
  115. int fz_is_zip_archive(fz_context *ctx, fz_stream *file);
  116. /*
  117. fz_open_zip_archive: Open a zip archive file.
  118. An exception is throw if the file is not a zip archive as
  119. indicated by the presence of a zip signature.
  120. filename: a path to a zip archive file as it would be given to
  121. open(2).
  122. */
  123. fz_archive *fz_open_zip_archive(fz_context *ctx, const char *path);
  124. /*
  125. fz_open_zip_archive: Open a zip archive stream.
  126. Open an archive using a seekable stream object rather than
  127. opening a file or directory on disk.
  128. An exception is throw if the stream is not a zip archive as
  129. indicated by the presence of a zip signature.
  130. */
  131. fz_archive *fz_open_zip_archive_with_stream(fz_context *ctx, fz_stream *file);
  132. typedef struct fz_zip_writer_s fz_zip_writer;
  133. fz_zip_writer *fz_new_zip_writer(fz_context *ctx, const char *filename);
  134. void fz_write_zip_entry(fz_context *ctx, fz_zip_writer *zip, const char *name, fz_buffer *buf, int compress);
  135. void fz_close_zip_writer(fz_context *ctx, fz_zip_writer *zip);
  136. void fz_drop_zip_writer(fz_context *ctx, fz_zip_writer *zip);
  137. #endif