1 .\" Copyright (c) 2003-2011 Tim Kientzle
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .Dt ARCHIVE_WRITE_OPEN 3
31 .Nm archive_write_open ,
32 .Nm archive_write_open2 ,
33 .Nm archive_write_open_fd ,
34 .Nm archive_write_open_FILE ,
35 .Nm archive_write_open_filename ,
36 .Nm archive_write_open_memory
37 .Nd functions for creating archives
39 Streaming Archive Library (libarchive, -larchive)
43 .Fo archive_write_open
44 .Fa "struct archive *"
45 .Fa "void *client_data"
46 .Fa "archive_open_callback *"
47 .Fa "archive_write_callback *"
48 .Fa "archive_close_callback *"
51 .Fo archive_write_open2
52 .Fa "struct archive *"
53 .Fa "void *client_data"
54 .Fa "archive_open_callback *"
55 .Fa "archive_write_callback *"
56 .Fa "archive_close_callback *"
57 .Fa "archive_free_callback *"
60 .Fn archive_write_open_fd "struct archive *" "int fd"
62 .Fn archive_write_open_FILE "struct archive *" "FILE *file"
64 .Fn archive_write_open_filename "struct archive *" "const char *filename"
66 .Fo archive_write_open_memory
67 .Fa "struct archive *"
69 .Fa "size_t bufferSize"
73 .Bl -tag -width indent
74 .It Fn archive_write_open
75 Freeze the settings, open the archive, and prepare for writing entries.
76 This is the most generic form of this function, which accepts
77 pointers to three callback functions which will be invoked by
78 the compression layer to write the constructed archive.
79 This does not alter the default archive padding.
80 .It Fn archive_write_open2
82 .Fn archive_write_open
83 with an additional fourth free callback. This function should be preferred to
84 .Fn archive_write_open .
85 .It Fn archive_write_open_fd
87 .Fn archive_write_open
88 that accepts a file descriptor.
90 .Fn archive_write_open_fd
91 function is safe for use with tape drives or other
92 block-oriented devices.
93 .It Fn archive_write_open_FILE
95 .Fn archive_write_open
100 .Fn archive_write_open_FILE
101 is not safe for writing to tape drives or other devices
102 that require correct blocking.
103 .It Fn archive_write_open_file
104 A deprecated synonym for
105 .Fn archive_write_open_filename .
106 .It Fn archive_write_open_filename
107 A convenience form of
108 .Fn archive_write_open
109 that accepts a filename.
110 A NULL argument indicates that the output should be written to standard output;
113 will open a file with that name.
114 If you have not invoked
115 .Fn archive_write_set_bytes_in_last_block ,
117 .Fn archive_write_open_filename
118 will adjust the last-block padding depending on the file:
119 it will enable padding when writing to standard output or
120 to a character or block device node, it will disable padding otherwise.
121 You can override this by manually invoking
122 .Fn archive_write_set_bytes_in_last_block
124 .Fn archive_write_open2 .
126 .Fn archive_write_open_filename
127 function is safe for use with tape drives or other
128 block-oriented devices.
129 .It Fn archive_write_open_memory
130 A convenience form of
131 .Fn archive_write_open2
132 that accepts a pointer to a block of memory that will receive
136 argument points to a variable that will be updated
137 after each write to reflect how much of the buffer
139 You should be careful to ensure that this variable
140 remains allocated until after the archive is
142 This function will disable padding unless you
143 have specifically set the block size.
145 More information about the
147 object and the overall design of the library can be found in the
151 Note that the convenience forms above vary in how
152 they block the output.
154 .Xr archive_write_blocksize 3
155 if you need to control the block size used for writes
156 or the end-of-file padding behavior.
159 To use this library, you will need to define and register
160 callback functions that will be invoked to write data to the
162 These functions are registered by calling
163 .Fn archive_write_open2 :
164 .Bl -item -offset indent
167 .Fn archive_open_callback "struct archive *" "void *client_data"
170 The open callback is invoked by
171 .Fn archive_write_open .
174 if the underlying file or data source is successfully
176 If the open fails, it should call
177 .Fn archive_set_error
178 to register an error code and message and return
180 Please note that if open fails, close is not called and resources must be
181 freed inside the open callback or with the free callback.
182 .Bl -item -offset indent
184 .Ft typedef la_ssize_t
185 .Fo archive_write_callback
186 .Fa "struct archive *"
187 .Fa "void *client_data"
188 .Fa "const void *buffer"
193 The write callback is invoked whenever the library
194 needs to write raw bytes to the archive.
195 For correct blocking, each call to the write callback function
196 should translate into a single
199 This is especially critical when writing archives to tape drives.
200 On success, the write callback should return the
201 number of bytes actually written.
202 On error, the callback should invoke
203 .Fn archive_set_error
204 to register an error code and message and return -1.
205 .Bl -item -offset indent
208 .Fn archive_close_callback "struct archive *" "void *client_data"
211 The close callback is invoked by archive_close when
212 the archive processing is complete. If the open callback fails, the close
213 callback is not invoked.
214 The callback should return
217 On failure, the callback should invoke
218 .Fn archive_set_error
219 to register an error code and message and
221 .Bl -item -offset indent
224 .Fn archive_free_callback "struct archive *" "void *client_data"
227 The free callback is always invoked on archive_free.
228 The return code of this callback is not processed.
230 Note that if the client-provided write callback function
231 returns a non-zero value, that error will be propagated back to the caller
232 through whatever API function resulted in that call, which
234 .Fn archive_write_header ,
235 .Fn archive_write_data ,
236 .Fn archive_write_close ,
237 .Fn archive_write_finish ,
239 .Fn archive_write_free .
240 The client callback can call
241 .Fn archive_set_error
242 to provide values that can then be retrieved by
245 .Fn archive_error_string .
248 These functions return
254 Detailed error codes and textual descriptions are available from the
257 .Fn archive_error_string
262 .Xr archive_write 3 ,
263 .Xr archive_write_blocksize 3 ,
264 .Xr archive_write_filter 3 ,
265 .Xr archive_write_format 3 ,
266 .Xr archive_write_new 3 ,
267 .Xr archive_write_set_options 3 ,