1 ARCHIVE_WRITE_OPEN(3) manual page
3 '''archive_write_open''',
4 '''archive_write_open_fd''',
5 '''archive_write_open_FILE''',
6 '''archive_write_open_filename''',
7 '''archive_write_open_memory'''
8 - functions for creating archives
10 Streaming Archive Library (libarchive, -larchive)
12 '''<nowiki>#include <archive.h></nowiki>'''
16 '''archive_write_open'''(''struct archive *'', ''void *client_data'', ''archive_open_callback *'', ''archive_write_callback *'', ''archive_close_callback *'');
20 '''archive_write_open_fd'''(''struct archive *'', ''int fd'');
24 '''archive_write_open_FILE'''(''struct archive *'', ''FILE *file'');
28 '''archive_write_open_filename'''(''struct archive *'', ''const char *filename'');
32 '''archive_write_open_memory'''(''struct archive *'', ''void *buffer'', ''size_t bufferSize'', ''size_t *outUsed'');
35 <dt>'''archive_write_open'''()</dt><dd>
36 Freeze the settings, open the archive, and prepare for writing entries.
37 This is the most generic form of this function, which accepts
38 pointers to three callback functions which will be invoked by
39 the compression layer to write the constructed archive.
40 This does not alter the default archive padding.
41 </dd><dt>'''archive_write_open_fd'''()</dt><dd>
43 '''archive_write_open'''()
44 that accepts a file descriptor.
46 '''archive_write_open_fd'''()
47 function is safe for use with tape drives or other
48 block-oriented devices.
49 </dd><dt>'''archive_write_open_FILE'''()</dt><dd>
51 '''archive_write_open'''()
56 '''archive_write_open_FILE'''()
57 is not safe for writing to tape drives or other devices
58 that require correct blocking.
59 </dd><dt>'''archive_write_open_file'''()</dt><dd>
60 A deprecated synonym for
61 '''archive_write_open_filename'''().
62 </dd><dt>'''archive_write_open_filename'''()</dt><dd>
64 '''archive_write_open'''()
65 that accepts a filename.
66 A NULL argument indicates that the output should be written to standard output;
69 will open a file with that name.
70 If you have not invoked
71 '''archive_write_set_bytes_in_last_block'''(),
73 '''archive_write_open_filename'''()
74 will adjust the last-block padding depending on the file:
75 it will enable padding when writing to standard output or
76 to a character or block device node, it will disable padding otherwise.
77 You can override this by manually invoking
78 '''archive_write_set_bytes_in_last_block'''()
80 '''archive_write_open'''().
82 '''archive_write_open_filename'''()
83 function is safe for use with tape drives or other
84 block-oriented devices.
85 </dd><dt>'''archive_write_open_memory'''()</dt><dd>
87 '''archive_write_open'''()
88 that accepts a pointer to a block of memory that will receive
92 argument points to a variable that will be updated
93 after each write to reflect how much of the buffer
95 You should be careful to ensure that this variable
96 remains allocated until after the archive is
98 This function will disable padding unless you
99 have specifically set the block size.
101 More information about the
103 object and the overall design of the library can be found in the
104 [[ManPageibarchive3]]
107 Note that the convenience forms above vary in how
108 they block the output.
110 [[ManPagerchiveritelocksize3]]
111 if you need to control the block size used for writes
112 or the end-of-file padding behavior.
113 == CLIENT CALLBACKS ==
114 To use this library, you will need to define and register
115 callback functions that will be invoked to write data to the
117 These functions are registered by calling
118 '''archive_write_open'''():
122 '''archive_open_callback'''(''struct archive *'', ''void *client_data'')
125 The open callback is invoked by
126 '''archive_write_open'''().
129 if the underlying file or data source is successfully
131 If the open fails, it should call
132 '''archive_set_error'''()
133 to register an error code and message and return
137 ''typedef la_ssize_t''
138 '''archive_write_callback'''(''struct archive *'', ''void *client_data'', ''const void *buffer'', ''size_t length'')
141 The write callback is invoked whenever the library
142 needs to write raw bytes to the archive.
143 For correct blocking, each call to the write callback function
144 should translate into a single
145 [[write(2)|http://www.freebsd.org/cgi/man.cgi?query=write&sektion=2]]
147 This is especially critical when writing archives to tape drives.
148 On success, the write callback should return the
149 number of bytes actually written.
150 On error, the callback should invoke
151 '''archive_set_error'''()
152 to register an error code and message and return -1.
156 '''archive_close_callback'''(''struct archive *'', ''void *client_data'')
159 The close callback is invoked by archive_close when
160 the archive processing is complete.
161 The callback should return
164 On failure, the callback should invoke
165 '''archive_set_error'''()
166 to register an error code and message and
170 Note that if the client-provided write callback function
171 returns a non-zero value, that error will be propagated back to the caller
172 through whatever API function resulted in that call, which
174 '''archive_write_header'''(),
175 '''archive_write_data'''(),
176 '''archive_write_close'''(),
177 '''archive_write_finish'''(),
179 '''archive_write_free'''().
180 The client callback can call
181 '''archive_set_error'''()
182 to provide values that can then be retrieved by
183 '''archive_errno'''()
185 '''archive_error_string'''().
187 These functions return
192 Detailed error codes and textual descriptions are available from the
193 '''archive_errno'''()
195 '''archive_error_string'''()
199 [[ManPageibarchive3]],
200 [[ManPagerchiverite3]],
201 [[ManPagerchiveritelocksize3]],
202 [[ManPagerchiveriteilter3]],
203 [[ManPagerchiveriteormat3]],
204 [[ManPagerchiveriteew3]],
205 [[ManPagerchiveriteetptions3]],