ManPageArchiveWriteOpen3.wiki 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ARCHIVE_WRITE_OPEN(3) manual page
  2. == NAME ==
  3. '''archive_write_open''',
  4. '''archive_write_open2''',
  5. '''archive_write_open_fd''',
  6. '''archive_write_open_FILE''',
  7. '''archive_write_open_filename''',
  8. '''archive_write_open_memory'''
  9. - functions for creating 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_write_open'''(''struct archive *'', ''void *client_data'', ''archive_open_callback *'', ''archive_write_callback *'', ''archive_close_callback *'');
  18. <br>
  19. ''int''
  20. <br>
  21. '''archive_write_open2'''(''struct archive *'', ''void *client_data'', ''archive_open_callback *'', ''archive_write_callback *'', ''archive_close_callback *'', ''archive_free_callback *'');
  22. <br>
  23. ''int''
  24. <br>
  25. '''archive_write_open_fd'''(''struct archive *'', ''int fd'');
  26. <br>
  27. ''int''
  28. <br>
  29. '''archive_write_open_FILE'''(''struct archive *'', ''FILE *file'');
  30. <br>
  31. ''int''
  32. <br>
  33. '''archive_write_open_filename'''(''struct archive *'', ''const char *filename'');
  34. <br>
  35. ''int''
  36. <br>
  37. '''archive_write_open_memory'''(''struct archive *'', ''void *buffer'', ''size_t bufferSize'', ''size_t *outUsed'');
  38. == DESCRIPTION ==
  39. <dl>
  40. <dt>'''archive_write_open'''()</dt><dd>
  41. Freeze the settings, open the archive, and prepare for writing entries.
  42. This is the most generic form of this function, which accepts
  43. pointers to three callback functions which will be invoked by
  44. the compression layer to write the constructed archive.
  45. This does not alter the default archive padding.
  46. </dd><dt>'''archive_write_open2'''()</dt><dd>
  47. Same as
  48. '''archive_write_open'''()
  49. with an additional fourth free callback. This function should be preferred to
  50. '''archive_write_open'''().
  51. </dd><dt>'''archive_write_open_fd'''()</dt><dd>
  52. A convenience form of
  53. '''archive_write_open'''()
  54. that accepts a file descriptor.
  55. The
  56. '''archive_write_open_fd'''()
  57. function is safe for use with tape drives or other
  58. block-oriented devices.
  59. </dd><dt>'''archive_write_open_FILE'''()</dt><dd>
  60. A convenience form of
  61. '''archive_write_open'''()
  62. that accepts a
  63. ''FILE *''
  64. pointer.
  65. Note that
  66. '''archive_write_open_FILE'''()
  67. is not safe for writing to tape drives or other devices
  68. that require correct blocking.
  69. </dd><dt>'''archive_write_open_file'''()</dt><dd>
  70. A deprecated synonym for
  71. '''archive_write_open_filename'''().
  72. </dd><dt>'''archive_write_open_filename'''()</dt><dd>
  73. A convenience form of
  74. '''archive_write_open'''()
  75. that accepts a filename.
  76. A NULL argument indicates that the output should be written to standard output;
  77. an argument of
  78. "-"
  79. will open a file with that name.
  80. If you have not invoked
  81. '''archive_write_set_bytes_in_last_block'''(),
  82. then
  83. '''archive_write_open_filename'''()
  84. will adjust the last-block padding depending on the file:
  85. it will enable padding when writing to standard output or
  86. to a character or block device node, it will disable padding otherwise.
  87. You can override this by manually invoking
  88. '''archive_write_set_bytes_in_last_block'''()
  89. before calling
  90. '''archive_write_open2'''().
  91. The
  92. '''archive_write_open_filename'''()
  93. function is safe for use with tape drives or other
  94. block-oriented devices.
  95. </dd><dt>'''archive_write_open_memory'''()</dt><dd>
  96. A convenience form of
  97. '''archive_write_open2'''()
  98. that accepts a pointer to a block of memory that will receive
  99. the archive.
  100. The final
  101. ''size_t *''
  102. argument points to a variable that will be updated
  103. after each write to reflect how much of the buffer
  104. is currently in use.
  105. You should be careful to ensure that this variable
  106. remains allocated until after the archive is
  107. closed.
  108. This function will disable padding unless you
  109. have specifically set the block size.
  110. </dd></dl>
  111. More information about the
  112. ''struct'' archive
  113. object and the overall design of the library can be found in the
  114. [[ManPageLibarchive3]]
  115. overview.
  116. Note that the convenience forms above vary in how
  117. they block the output.
  118. See
  119. [[ManPageArchiveWriteBlocksize3]]
  120. if you need to control the block size used for writes
  121. or the end-of-file padding behavior.
  122. == CLIENT CALLBACKS ==
  123. To use this library, you will need to define and register
  124. callback functions that will be invoked to write data to the
  125. resulting archive.
  126. These functions are registered by calling
  127. '''archive_write_open2'''():
  128. <ul>
  129. <li>
  130. ''typedef int''
  131. '''archive_open_callback'''(''struct archive *'', ''void *client_data'')
  132. </li></ul>
  133. The open callback is invoked by
  134. '''archive_write_open'''().
  135. It should return
  136. '''ARCHIVE_OK'''
  137. if the underlying file or data source is successfully
  138. opened.
  139. If the open fails, it should call
  140. '''archive_set_error'''()
  141. to register an error code and message and return
  142. '''ARCHIVE_FATAL'''.
  143. Please note that if open fails, close is not called and resources must be
  144. freed inside the open callback or with the free callback.
  145. <ul>
  146. <li>
  147. ''typedef la_ssize_t''
  148. '''archive_write_callback'''(''struct archive *'', ''void *client_data'', ''const void *buffer'', ''size_t length'')
  149. </li></ul>
  150. The write callback is invoked whenever the library
  151. needs to write raw bytes to the archive.
  152. For correct blocking, each call to the write callback function
  153. should translate into a single
  154. [[write(2)|http://www.freebsd.org/cgi/man.cgi?query=write&sektion=2]]
  155. system call.
  156. This is especially critical when writing archives to tape drives.
  157. On success, the write callback should return the
  158. number of bytes actually written.
  159. On error, the callback should invoke
  160. '''archive_set_error'''()
  161. to register an error code and message and return -1.
  162. <ul>
  163. <li>
  164. ''typedef int''
  165. '''archive_close_callback'''(''struct archive *'', ''void *client_data'')
  166. </li></ul>
  167. The close callback is invoked by archive_close when
  168. the archive processing is complete. If the open callback fails, the close
  169. callback is not invoked.
  170. The callback should return
  171. '''ARCHIVE_OK'''
  172. on success.
  173. On failure, the callback should invoke
  174. '''archive_set_error'''()
  175. to register an error code and message and
  176. return
  177. '''ARCHIVE_FATAL'''.
  178. <ul>
  179. <li>
  180. ''typedef int''
  181. '''archive_free_callback'''(''struct archive *'', ''void *client_data'')
  182. </li></ul>
  183. The free callback is always invoked on archive_free.
  184. The return code of this callback is not processed.
  185. Note that if the client-provided write callback function
  186. returns a non-zero value, that error will be propagated back to the caller
  187. through whatever API function resulted in that call, which
  188. may include
  189. '''archive_write_header'''(),
  190. '''archive_write_data'''(),
  191. '''archive_write_close'''(),
  192. '''archive_write_finish'''(),
  193. or
  194. '''archive_write_free'''().
  195. The client callback can call
  196. '''archive_set_error'''()
  197. to provide values that can then be retrieved by
  198. '''archive_errno'''()
  199. and
  200. '''archive_error_string'''().
  201. == RETURN VALUES ==
  202. These functions return
  203. '''ARCHIVE_OK'''
  204. on success, or
  205. '''ARCHIVE_FATAL'''.
  206. == ERRORS ==
  207. Detailed error codes and textual descriptions are available from the
  208. '''archive_errno'''()
  209. and
  210. '''archive_error_string'''()
  211. functions.
  212. == SEE ALSO ==
  213. [[ManPageBsdtar1]],
  214. [[ManPageArchiveWrite3]],
  215. [[ManPageArchiveWriteBlocksize3]],
  216. [[ManPageArchiveWriteFilter3]],
  217. [[ManPageArchiveWriteFormat3]],
  218. [[ManPageArchiveWriteNew3]],
  219. [[ManPageArchiveWriteSetOptions3]],
  220. [[ManPageLibarchive3]],
  221. [[ManPageCpio5]],
  222. [[ManPageMtree5]],
  223. [[ManPageTar5]]