Imported Upstream version 3.3.1
[platform/upstream/libarchive.git] / doc / wiki / ManPageArchiveReadOpen3.wiki
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 *'', ''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
90 A complete description of the 
91 '''struct archive''' 
92 and 
93 '''struct archive_entry''' 
94 objects can be found in the overview manual page for 
95 [[ManPageLibarchive3]]. 
96 == CLIENT CALLBACKS == 
97 The callback functions must match the following prototypes: 
98 <ul> 
99 <li> 
100 ''typedef la_ssize_t'' 
101 '''archive_read_callback'''(''struct archive *'', ''void *client_data'', ''const void **buffer'') 
102 </li><li> 
103 ''typedef la_int64_t'' 
104 '''archive_skip_callback'''(''struct archive *'', ''void *client_data'', ''off_t request'') 
105 </li><li> 
106 ''typedef int'' 
107 '''archive_open_callback'''(''struct archive *'', ''void *client_data'') 
108 </li><li> 
109 ''typedef int'' 
110 '''archive_close_callback'''(''struct archive *'', ''void *client_data'') 
111 </li></ul> 
112
113 The open callback is invoked by 
114 '''archive_open'''(). 
115 It should return 
116 '''ARCHIVE_OK''' 
117 if the underlying file or data source is successfully 
118 opened. 
119 If the open fails, it should call 
120 '''archive_set_error'''() 
121 to register an error code and message and return 
122 '''ARCHIVE_FATAL'''. 
123
124 The read callback is invoked whenever the library 
125 requires raw bytes from the archive. 
126 The read callback should read data into a buffer, 
127 set the 
128 ```text
129 const void **buffer 
130 ```
131 argument to point to the available data, and 
132 return a count of the number of bytes available. 
133 The library will invoke the read callback again 
134 only after it has consumed this data. 
135 The library imposes no constraints on the size 
136 of the data blocks returned. 
137 On end-of-file, the read callback should 
138 return zero. 
139 On error, the read callback should invoke 
140 '''archive_set_error'''() 
141 to register an error code and message and 
142 return -1. 
143
144 The skip callback is invoked when the 
145 library wants to ignore a block of data. 
146 The return value is the number of bytes actually 
147 skipped, which may differ from the request. 
148 If the callback cannot skip data, it should return 
149 zero. 
150 If the skip callback is not provided (the 
151 function pointer is 
152 NULL ), 
153 the library will invoke the read function 
154 instead and simply discard the result. 
155 A skip callback can provide significant 
156 performance gains when reading uncompressed 
157 archives from slow disk drives or other media 
158 that can skip quickly. 
159
160 The close callback is invoked by archive_close when 
161 the archive processing is complete. 
162 The callback should return 
163 '''ARCHIVE_OK''' 
164 on success. 
165 On failure, the callback should invoke 
166 '''archive_set_error'''() 
167 to register an error code and message and 
168 return 
169 '''ARCHIVE_FATAL.''' 
170 == RETURN VALUES == 
171 These functions return 
172 '''ARCHIVE_OK''' 
173 on success, or 
174 '''ARCHIVE_FATAL'''. 
175 == ERRORS == 
176 Detailed error codes and textual descriptions are available from the 
177 '''archive_errno'''() 
178 and 
179 '''archive_error_string'''() 
180 functions. 
181 == SEE ALSO == 
182 [[ManPageBsdtar1]], 
183 [[ManPageLibarchive3]], 
184 [[ManPageArchiveRead3]], 
185 [[ManPageArchiveReadData3]], 
186 [[ManPageArchiveReadFilter3]], 
187 [[ManPageArchiveReadFormat3]], 
188 [[ManPageArchiveReadSetOptions3]], 
189 [[ManPageArchiveUtil3]], 
190 [[ManPageTar5]]