ManPageArchiveReadOpen3.wiki 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ARCHIVE_READ_OPEN(3) manual page
  2. == NAME ==
  3. '''archive_read_open''',
  4. '''archive_read_open2''',
  5. '''archive_read_open_fd''',
  6. '''archive_read_open_FILE''',
  7. '''archive_read_open_filename''',
  8. '''archive_read_open_memory'''
  9. - functions for reading streaming archives
  10. == LIBRARY ==
  11. Streaming Archive Library (libarchive, -larchive)
  12. == SYNOPSIS ==
  13. '''<nowiki>#include <archive.h></nowiki>'''
  14. <br>
  15. ''int''
  16. <br>
  17. '''archive_read_open'''(''struct archive *'', ''void *client_data'', ''archive_open_callback *'', ''archive_read_callback *'', ''archive_close_callback *'');
  18. <br>
  19. ''int''
  20. <br>
  21. '''archive_read_open2'''(''struct archive *'', ''void *client_data'', ''archive_open_callback *'', ''archive_read_callback *'', ''archive_skip_callback *'', ''archive_close_callback *'');
  22. <br>
  23. ''int''
  24. <br>
  25. '''archive_read_open_FILE'''(''struct archive *'', ''FILE *file'');
  26. <br>
  27. ''int''
  28. <br>
  29. '''archive_read_open_fd'''(''struct archive *'', ''int fd'', ''size_t block_size'');
  30. <br>
  31. ''int''
  32. <br>
  33. '''archive_read_open_filename'''(''struct archive *'', ''const char *filename'', ''size_t block_size'');
  34. <br>
  35. ''int''
  36. <br>
  37. '''archive_read_open_memory'''(''struct archive *'', ''const void *buff'', ''size_t size'');
  38. == DESCRIPTION ==
  39. <dl>
  40. <dt>'''archive_read_open'''()</dt><dd>
  41. The same as
  42. '''archive_read_open2'''(),
  43. except that the skip callback is assumed to be
  44. NULL.
  45. </dd><dt>'''archive_read_open2'''()</dt><dd>
  46. Freeze the settings, open the archive, and prepare for reading entries.
  47. This is the most generic version of this call, which accepts
  48. four callback functions.
  49. Most clients will want to use
  50. '''archive_read_open_filename'''(),
  51. '''archive_read_open_FILE'''(),
  52. '''archive_read_open_fd'''(),
  53. or
  54. '''archive_read_open_memory'''()
  55. instead.
  56. The library invokes the client-provided functions to obtain
  57. raw bytes from the archive.
  58. </dd><dt>'''archive_read_open_FILE'''()</dt><dd>
  59. Like
  60. '''archive_read_open'''(),
  61. except that it accepts a
  62. ''FILE *''
  63. pointer.
  64. This function should not be used with tape drives or other devices
  65. that require strict I/O blocking.
  66. </dd><dt>'''archive_read_open_fd'''()</dt><dd>
  67. Like
  68. '''archive_read_open'''(),
  69. except that it accepts a file descriptor and block size rather than
  70. a set of function pointers.
  71. Note that the file descriptor will not be automatically closed at
  72. end-of-archive.
  73. This function is safe for use with tape drives or other blocked devices.
  74. </dd><dt>'''archive_read_open_file'''()</dt><dd>
  75. This is a deprecated synonym for
  76. '''archive_read_open_filename'''().
  77. </dd><dt>'''archive_read_open_filename'''()</dt><dd>
  78. Like
  79. '''archive_read_open'''(),
  80. except that it accepts a simple filename and a block size.
  81. A NULL filename represents standard input.
  82. This function is safe for use with tape drives or other blocked devices.
  83. </dd><dt>'''archive_read_open_memory'''()</dt><dd>
  84. Like
  85. '''archive_read_open'''(),
  86. except that it accepts a pointer and size of a block of
  87. memory containing the archive data.
  88. </dd></dl>
  89. A complete description of the
  90. '''struct archive'''
  91. and
  92. '''struct archive_entry'''
  93. objects can be found in the overview manual page for
  94. [[ManPageLibarchive3]].
  95. == CLIENT CALLBACKS ==
  96. The callback functions must match the following prototypes:
  97. <ul>
  98. <li>
  99. ''typedef la_ssize_t''
  100. '''archive_read_callback'''(''struct archive *'', ''void *client_data'', ''const void **buffer'')
  101. </li><li>
  102. ''typedef la_int64_t''
  103. '''archive_skip_callback'''(''struct archive *'', ''void *client_data'', ''off_t request'')
  104. </li><li>
  105. ''typedef int''
  106. '''archive_open_callback'''(''struct archive *'', ''void *client_data'')
  107. </li><li>
  108. ''typedef int''
  109. '''archive_close_callback'''(''struct archive *'', ''void *client_data'')
  110. </li></ul>
  111. The open callback is invoked by
  112. '''archive_open'''().
  113. It should return
  114. '''ARCHIVE_OK'''
  115. if the underlying file or data source is successfully
  116. opened.
  117. If the open fails, it should call
  118. '''archive_set_error'''()
  119. to register an error code and message and return
  120. '''ARCHIVE_FATAL'''.
  121. The read callback is invoked whenever the library
  122. requires raw bytes from the archive.
  123. The read callback should read data into a buffer,
  124. set the
  125. ```text
  126. const void **buffer
  127. ```
  128. argument to point to the available data, and
  129. return a count of the number of bytes available.
  130. The library will invoke the read callback again
  131. only after it has consumed this data.
  132. The library imposes no constraints on the size
  133. of the data blocks returned.
  134. On end-of-file, the read callback should
  135. return zero.
  136. On error, the read callback should invoke
  137. '''archive_set_error'''()
  138. to register an error code and message and
  139. return -1.
  140. The skip callback is invoked when the
  141. library wants to ignore a block of data.
  142. The return value is the number of bytes actually
  143. skipped, which may differ from the request.
  144. If the callback cannot skip data, it should return
  145. zero.
  146. If the skip callback is not provided (the
  147. function pointer is
  148. NULL ),
  149. the library will invoke the read function
  150. instead and simply discard the result.
  151. A skip callback can provide significant
  152. performance gains when reading uncompressed
  153. archives from slow disk drives or other media
  154. that can skip quickly.
  155. The close callback is invoked by archive_close when
  156. the archive processing is complete.
  157. The callback should return
  158. '''ARCHIVE_OK'''
  159. on success.
  160. On failure, the callback should invoke
  161. '''archive_set_error'''()
  162. to register an error code and message and
  163. return
  164. '''ARCHIVE_FATAL'''.
  165. == RETURN VALUES ==
  166. These functions return
  167. '''ARCHIVE_OK'''
  168. on success, or
  169. '''ARCHIVE_FATAL'''.
  170. == ERRORS ==
  171. Detailed error codes and textual descriptions are available from the
  172. '''archive_errno'''()
  173. and
  174. '''archive_error_string'''()
  175. functions.
  176. == SEE ALSO ==
  177. [[ManPageBsdtar1]],
  178. [[ManPageArchiveRead3]],
  179. [[ManPageArchiveReadData3]],
  180. [[ManPageArchiveReadFilter3]],
  181. [[ManPageArchiveReadFormat3]],
  182. [[ManPageArchiveReadSetOptions3]],
  183. [[ManPageArchiveUtil3]],
  184. [[ManPageLibarchive3]],
  185. [[ManPageTar5]]