Debian Codegraph @

upstream/mageia-cauldron/man3pm/IO::Uncompress::AnyInflate.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "IO::Uncompress::AnyInflate 3pm"
61 .TH IO::Uncompress::AnyInflate 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 IO::Uncompress::AnyInflate \- Uncompress zlib\-based (zip, gzip) file/buffer
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
72 \&
73 \& my $status = anyinflate $input => $output [,OPTS]
74 \& or die "anyinflate failed: $AnyInflateError\en";
75 \&
76 \& my $z = IO::Uncompress::AnyInflate\->new( $input [OPTS] )
77 \& or die "anyinflate failed: $AnyInflateError\en";
78 \&
79 \& $status = $z\->read($buffer)
80 \& $status = $z\->read($buffer, $length)
81 \& $status = $z\->read($buffer, $length, $offset)
82 \& $line = $z\->getline()
83 \& $char = $z\->getc()
84 \& $char = $z\->ungetc()
85 \& $char = $z\->opened()
86 \&
87 \& $status = $z\->inflateSync()
88 \&
89 \& $data = $z\->trailingData()
90 \& $status = $z\->nextStream()
91 \& $data = $z\->getHeaderInfo()
92 \& $z\->tell()
93 \& $z\->seek($position, $whence)
94 \& $z\->binmode()
95 \& $z\->fileno()
96 \& $z\->eof()
97 \& $z\->close()
98 \&
99 \& $AnyInflateError ;
100 \&
101 \& # IO::File mode
102 \&
103 \& <$z>
104 \& read($z, $buffer);
105 \& read($z, $buffer, $length);
106 \& read($z, $buffer, $length, $offset);
107 \& tell($z)
108 \& seek($z, $position, $whence)
109 \& binmode($z)
110 \& fileno($z)
111 \& eof($z)
112 \& close($z)
113 .Ve
114 .SH DESCRIPTION
115 .IX Header "DESCRIPTION"
116 This module provides a Perl interface that allows the reading of
117 files/buffers that have been compressed in a number of formats that use the
118 zlib compression library.
119 .PP
120 The formats supported are
121 .IP "RFC 1950" 5
122 .IX Item "RFC 1950"
123 .PD 0
124 .IP "RFC 1951 (optionally)" 5
125 .IX Item "RFC 1951 (optionally)"
126 .IP "gzip (RFC 1952)" 5
127 .IX Item "gzip (RFC 1952)"
128 .IP zip 5
129 .IX Item "zip"
130 .PD
131 .PP
132 The module will auto\-detect which, if any, of the supported
133 compression formats is being used.
134 .SH "Functional Interface"
135 .IX Header "Functional Interface"
136 A top\-level function, \f(CW\*(C`anyinflate\*(C'\fR, is provided to carry out
137 "one\-shot" uncompression between buffers and/or files. For finer
138 control over the uncompression process, see the "OO Interface"
139 section.
140 .PP
141 .Vb 1
142 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
143 \&
144 \& anyinflate $input_filename_or_reference => $output_filename_or_reference [,OPTS]
145 \& or die "anyinflate failed: $AnyInflateError\en";
146 .Ve
147 .PP
148 The functional interface needs Perl5.005 or better.
149 .ie n .SS "anyinflate $input_filename_or_reference => $output_filename_or_reference [, OPTS]"
150 .el .SS "anyinflate \f(CW$input_filename_or_reference\fP => \f(CW$output_filename_or_reference\fP [, OPTS]"
151 .IX Subsection "anyinflate $input_filename_or_reference => $output_filename_or_reference [, OPTS]"
152 \&\f(CW\*(C`anyinflate\*(C'\fR expects at least two parameters,
153 \&\f(CW$input_filename_or_reference\fR and \f(CW$output_filename_or_reference\fR
154 and zero or more optional parameters (see "Optional Parameters")
155 .PP
156 \fIThe \fR\f(CI$input_filename_or_reference\fR\fI parameter\fR
157 .IX Subsection "The $input_filename_or_reference parameter"
158 .PP
159 The parameter, \f(CW$input_filename_or_reference\fR, is used to define the
160 source of the compressed data.
161 .PP
162 It can take one of the following forms:
163 .IP "A filename" 5
164 .IX Item "A filename"
165 If the \f(CW$input_filename_or_reference\fR parameter is a simple scalar, it is
166 assumed to be a filename. This file will be opened for reading and the
167 input data will be read from it.
168 .IP "A filehandle" 5
169 .IX Item "A filehandle"
170 If the \f(CW$input_filename_or_reference\fR parameter is a filehandle, the input
171 data will be read from it. The string \*(Aq\-\*(Aq can be used as an alias for
172 standard input.
173 .IP "A scalar reference" 5
174 .IX Item "A scalar reference"
175 If \f(CW$input_filename_or_reference\fR is a scalar reference, the input data
176 will be read from \f(CW$$input_filename_or_reference\fR.
177 .IP "An array reference" 5
178 .IX Item "An array reference"
179 If \f(CW$input_filename_or_reference\fR is an array reference, each element in
180 the array must be a filename.
181 .Sp
182 The input data will be read from each file in turn.
183 .Sp
184 The complete array will be walked to ensure that it only
185 contains valid filenames before any data is uncompressed.
186 .IP "An Input FileGlob string" 5
187 .IX Item "An Input FileGlob string"
188 If \f(CW$input_filename_or_reference\fR is a string that is delimited by the
189 characters "<" and ">" \f(CW\*(C`anyinflate\*(C'\fR will assume that it is an
190 \&\fIinput fileglob string\fR. The input is the list of files that match the
191 fileglob.
192 .Sp
193 See File::GlobMapper for more details.
194 .PP
195 If the \f(CW$input_filename_or_reference\fR parameter is any other type,
196 \&\f(CW\*(C`undef\*(C'\fR will be returned.
197 .PP
198 \fIThe \fR\f(CI$output_filename_or_reference\fR\fI parameter\fR
199 .IX Subsection "The $output_filename_or_reference parameter"
200 .PP
201 The parameter \f(CW$output_filename_or_reference\fR is used to control the
202 destination of the uncompressed data. This parameter can take one of
203 these forms.
204 .IP "A filename" 5
205 .IX Item "A filename"
206 If the \f(CW$output_filename_or_reference\fR parameter is a simple scalar, it is
207 assumed to be a filename. This file will be opened for writing and the
208 uncompressed data will be written to it.
209 .IP "A filehandle" 5
210 .IX Item "A filehandle"
211 If the \f(CW$output_filename_or_reference\fR parameter is a filehandle, the
212 uncompressed data will be written to it. The string \*(Aq\-\*(Aq can be used as
213 an alias for standard output.
214 .IP "A scalar reference" 5
215 .IX Item "A scalar reference"
216 If \f(CW$output_filename_or_reference\fR is a scalar reference, the
217 uncompressed data will be stored in \f(CW$$output_filename_or_reference\fR.
218 .IP "An Array Reference" 5
219 .IX Item "An Array Reference"
220 If \f(CW$output_filename_or_reference\fR is an array reference,
221 the uncompressed data will be pushed onto the array.
222 .IP "An Output FileGlob" 5
223 .IX Item "An Output FileGlob"
224 If \f(CW$output_filename_or_reference\fR is a string that is delimited by the
225 characters "<" and ">" \f(CW\*(C`anyinflate\*(C'\fR will assume that it is an
226 \&\fIoutput fileglob string\fR. The output is the list of files that match the
227 fileglob.
228 .Sp
229 When \f(CW$output_filename_or_reference\fR is an fileglob string,
230 \&\f(CW$input_filename_or_reference\fR must also be a fileglob string. Anything
231 else is an error.
232 .Sp
233 See File::GlobMapper for more details.
234 .PP
235 If the \f(CW$output_filename_or_reference\fR parameter is any other type,
236 \&\f(CW\*(C`undef\*(C'\fR will be returned.
237 .SS Notes
238 .IX Subsection "Notes"
239 When \f(CW$input_filename_or_reference\fR maps to multiple compressed
240 files/buffers and \f(CW$output_filename_or_reference\fR is
241 a single file/buffer, after uncompression \f(CW$output_filename_or_reference\fR will contain a
242 concatenation of all the uncompressed data from each of the input
243 files/buffers.
244 .SS "Optional Parameters"
245 .IX Subsection "Optional Parameters"
246 The optional parameters for the one\-shot function \f(CW\*(C`anyinflate\*(C'\fR
247 are (for the most part) identical to those used with the OO interface defined in the
248 "Constructor Options" section. The exceptions are listed below
249 .ie n .IP """AutoClose => 0|1""" 5
250 .el .IP "\f(CWAutoClose => 0|1\fR" 5
251 .IX Item "AutoClose => 0|1"
252 This option applies to any input or output data streams to
253 \&\f(CW\*(C`anyinflate\*(C'\fR that are filehandles.
254 .Sp
255 If \f(CW\*(C`AutoClose\*(C'\fR is specified, and the value is true, it will result in all
256 input and/or output filehandles being closed once \f(CW\*(C`anyinflate\*(C'\fR has
257 completed.
258 .Sp
259 This parameter defaults to 0.
260 .ie n .IP """BinModeOut => 0|1""" 5
261 .el .IP "\f(CWBinModeOut => 0|1\fR" 5
262 .IX Item "BinModeOut => 0|1"
263 This option is now a no\-op. All files will be written in binmode.
264 .ie n .IP """Append => 0|1""" 5
265 .el .IP "\f(CWAppend => 0|1\fR" 5
266 .IX Item "Append => 0|1"
267 The behaviour of this option is dependent on the type of output data
268 stream.
269 .RS 5
270 .IP \(bu 5
271 A Buffer
272 .Sp
273 If \f(CW\*(C`Append\*(C'\fR is enabled, all uncompressed data will be append to the end of
274 the output buffer. Otherwise the output buffer will be cleared before any
275 uncompressed data is written to it.
276 .IP \(bu 5
277 A Filename
278 .Sp
279 If \f(CW\*(C`Append\*(C'\fR is enabled, the file will be opened in append mode. Otherwise
280 the contents of the file, if any, will be truncated before any uncompressed
281 data is written to it.
282 .IP \(bu 5
283 A Filehandle
284 .Sp
285 If \f(CW\*(C`Append\*(C'\fR is enabled, the filehandle will be positioned to the end of
286 the file via a call to \f(CW\*(C`seek\*(C'\fR before any uncompressed data is
287 written to it. Otherwise the file pointer will not be moved.
288 .RE
289 .RS 5
290 .Sp
291 When \f(CW\*(C`Append\*(C'\fR is specified, and set to true, it will \fIappend\fR all uncompressed
292 data to the output data stream.
293 .Sp
294 So when the output is a filehandle it will carry out a seek to the eof
295 before writing any uncompressed data. If the output is a filename, it will be opened for
296 appending. If the output is a buffer, all uncompressed data will be
297 appended to the existing buffer.
298 .Sp
299 Conversely when \f(CW\*(C`Append\*(C'\fR is not specified, or it is present and is set to
300 false, it will operate as follows.
301 .Sp
302 When the output is a filename, it will truncate the contents of the file
303 before writing any uncompressed data. If the output is a filehandle
304 its position will not be changed. If the output is a buffer, it will be
305 wiped before any uncompressed data is output.
306 .Sp
307 Defaults to 0.
308 .RE
309 .ie n .IP """MultiStream => 0|1""" 5
310 .el .IP "\f(CWMultiStream => 0|1\fR" 5
311 .IX Item "MultiStream => 0|1"
312 If the input file/buffer contains multiple compressed data streams, this
313 option will uncompress the whole lot as a single data stream.
314 .Sp
315 Defaults to 0.
316 .ie n .IP """TrailingData => $scalar""" 5
317 .el .IP "\f(CWTrailingData => $scalar\fR" 5
318 .IX Item "TrailingData => $scalar"
319 Returns the data, if any, that is present immediately after the compressed
320 data stream once uncompression is complete.
321 .Sp
322 This option can be used when there is useful information immediately
323 following the compressed data stream, and you don\*(Aqt know the length of the
324 compressed data stream.
325 .Sp
326 If the input is a buffer, \f(CW\*(C`trailingData\*(C'\fR will return everything from the
327 end of the compressed data stream to the end of the buffer.
328 .Sp
329 If the input is a filehandle, \f(CW\*(C`trailingData\*(C'\fR will return the data that is
330 left in the filehandle input buffer once the end of the compressed data
331 stream has been reached. You can then use the filehandle to read the rest
332 of the input file.
333 .Sp
334 Don\*(Aqt bother using \f(CW\*(C`trailingData\*(C'\fR if the input is a filename.
335 .Sp
336 If you know the length of the compressed data stream before you start
337 uncompressing, you can avoid having to use \f(CW\*(C`trailingData\*(C'\fR by setting the
338 \&\f(CW\*(C`InputLength\*(C'\fR option.
339 .SS "OneShot Examples"
340 .IX Subsection "OneShot Examples"
341 To read the contents of the file \f(CW\*(C`file1.txt.Compressed\*(C'\fR and write the
342 uncompressed data to the file \f(CW\*(C`file1.txt\*(C'\fR.
343 .PP
344 .Vb 3
345 \& use strict ;
346 \& use warnings ;
347 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
348 \&
349 \& my $input = "file1.txt.Compressed";
350 \& my $output = "file1.txt";
351 \& anyinflate $input => $output
352 \& or die "anyinflate failed: $AnyInflateError\en";
353 .Ve
354 .PP
355 To read from an existing Perl filehandle, \f(CW$input\fR, and write the
356 uncompressed data to a buffer, \f(CW$buffer\fR.
357 .PP
358 .Vb 4
359 \& use strict ;
360 \& use warnings ;
361 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
362 \& use IO::File ;
363 \&
364 \& my $input = IO::File\->new( "<file1.txt.Compressed" )
365 \& or die "Cannot open \*(Aqfile1.txt.Compressed\*(Aq: $!\en" ;
366 \& my $buffer ;
367 \& anyinflate $input => \e$buffer
368 \& or die "anyinflate failed: $AnyInflateError\en";
369 .Ve
370 .PP
371 To uncompress all files in the directory "/my/home" that match "*.txt.Compressed" and store the compressed data in the same directory
372 .PP
373 .Vb 3
374 \& use strict ;
375 \& use warnings ;
376 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
377 \&
378 \& anyinflate \*(Aq</my/home/*.txt.Compressed>\*(Aq => \*(Aq</my/home/#1.txt>\*(Aq
379 \& or die "anyinflate failed: $AnyInflateError\en";
380 .Ve
381 .PP
382 and if you want to compress each file one at a time, this will do the trick
383 .PP
384 .Vb 3
385 \& use strict ;
386 \& use warnings ;
387 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
388 \&
389 \& for my $input ( glob "/my/home/*.txt.Compressed" )
390 \& {
391 \& my $output = $input;
392 \& $output =~ s/.Compressed// ;
393 \& anyinflate $input => $output
394 \& or die "Error compressing \*(Aq$input\*(Aq: $AnyInflateError\en";
395 \& }
396 .Ve
397 .SH "OO Interface"
398 .IX Header "OO Interface"
399 .SS Constructor
400 .IX Subsection "Constructor"
401 The format of the constructor for IO::Uncompress::AnyInflate is shown below
402 .PP
403 .Vb 2
404 \& my $z = IO::Uncompress::AnyInflate\->new( $input [OPTS] )
405 \& or die "IO::Uncompress::AnyInflate failed: $AnyInflateError\en";
406 .Ve
407 .PP
408 The constructor takes one mandatory parameter, \f(CW$input\fR, defined below, and
409 zero or more \f(CW\*(C`OPTS\*(C'\fR, defined in "Constructor Options".
410 .PP
411 Returns an \f(CW\*(C`IO::Uncompress::AnyInflate\*(C'\fR object on success and undef on failure.
412 The variable \f(CW$AnyInflateError\fR will contain an error message on failure.
413 .PP
414 If you are running Perl 5.005 or better the object, \f(CW$z\fR, returned from
415 IO::Uncompress::AnyInflate can be used exactly like an IO::File filehandle.
416 This means that all normal input file operations can be carried out with
417 \&\f(CW$z\fR. For example, to read a line from a compressed file/buffer you can
418 use either of these forms
419 .PP
420 .Vb 2
421 \& $line = $z\->getline();
422 \& $line = <$z>;
423 .Ve
424 .PP
425 Below is a simple exaple of using the OO interface to read the compressed file
426 \&\f(CW\*(C`myfile.Compressed\*(C'\fR and write its contents to stdout.
427 .PP
428 .Vb 3
429 \& my $filename = "myfile.Compressed";
430 \& my $z = IO::Uncompress::AnyInflate\->new($filename)
431 \& or die "IO::Uncompress::AnyInflate failed: $AnyInflateError\en";
432 \&
433 \& while (<$z>) {
434 \& print $_;
435 \& }
436 \& $z\->close();
437 .Ve
438 .PP
439 See "EXAMPLES" for further examples
440 .PP
441 The mandatory parameter \f(CW$input\fR is used to determine the source of the
442 compressed data. This parameter can take one of three forms.
443 .IP "A filename" 5
444 .IX Item "A filename"
445 If the \f(CW$input\fR parameter is a scalar, it is assumed to be a filename. This
446 file will be opened for reading and the compressed data will be read from it.
447 .IP "A filehandle" 5
448 .IX Item "A filehandle"
449 If the \f(CW$input\fR parameter is a filehandle, the compressed data will be
450 read from it.
451 The string \*(Aq\-\*(Aq can be used as an alias for standard input.
452 .IP "A scalar reference" 5
453 .IX Item "A scalar reference"
454 If \f(CW$input\fR is a scalar reference, the compressed data will be read from
455 \&\f(CW$$input\fR.
456 .SS "Constructor Options"
457 .IX Subsection "Constructor Options"
458 The option names defined below are case insensitive and can be optionally
459 prefixed by a \*(Aq\-\*(Aq. So all of the following are valid
460 .PP
461 .Vb 4
462 \& \-AutoClose
463 \& \-autoclose
464 \& AUTOCLOSE
465 \& autoclose
466 .Ve
467 .PP
468 OPTS is a combination of the following options:
469 .ie n .IP """AutoClose => 0|1""" 5
470 .el .IP "\f(CWAutoClose => 0|1\fR" 5
471 .IX Item "AutoClose => 0|1"
472 This option is only valid when the \f(CW$input\fR parameter is a filehandle. If
473 specified, and the value is true, it will result in the file being closed once
474 either the \f(CW\*(C`close\*(C'\fR method is called or the IO::Uncompress::AnyInflate object is
475 destroyed.
476 .Sp
477 This parameter defaults to 0.
478 .ie n .IP """MultiStream => 0|1""" 5
479 .el .IP "\f(CWMultiStream => 0|1\fR" 5
480 .IX Item "MultiStream => 0|1"
481 Allows multiple concatenated compressed streams to be treated as a single
482 compressed stream. Decompression will stop once either the end of the
483 file/buffer is reached, an error is encountered (premature eof, corrupt
484 compressed data) or the end of a stream is not immediately followed by the
485 start of another stream.
486 .Sp
487 This parameter defaults to 0.
488 .ie n .IP """Prime => $string""" 5
489 .el .IP "\f(CWPrime => $string\fR" 5
490 .IX Item "Prime => $string"
491 This option will uncompress the contents of \f(CW$string\fR before processing the
492 input file/buffer.
493 .Sp
494 This option can be useful when the compressed data is embedded in another
495 file/data structure and it is not possible to work out where the compressed
496 data begins without having to read the first few bytes. If this is the
497 case, the uncompression can be \fIprimed\fR with these bytes using this
498 option.
499 .ie n .IP """Transparent => 0|1""" 5
500 .el .IP "\f(CWTransparent => 0|1\fR" 5
501 .IX Item "Transparent => 0|1"
502 If this option is set and the input file/buffer is not compressed data,
503 the module will allow reading of it anyway.
504 .Sp
505 In addition, if the input file/buffer does contain compressed data and
506 there is non\-compressed data immediately following it, setting this option
507 will make this module treat the whole file/buffer as a single data stream.
508 .Sp
509 This option defaults to 1.
510 .ie n .IP """BlockSize => $num""" 5
511 .el .IP "\f(CWBlockSize => $num\fR" 5
512 .IX Item "BlockSize => $num"
513 When reading the compressed input data, IO::Uncompress::AnyInflate will read it in
514 blocks of \f(CW$num\fR bytes.
515 .Sp
516 This option defaults to 4096.
517 .ie n .IP """InputLength => $size""" 5
518 .el .IP "\f(CWInputLength => $size\fR" 5
519 .IX Item "InputLength => $size"
520 When present this option will limit the number of compressed bytes read
521 from the input file/buffer to \f(CW$size\fR. This option can be used in the
522 situation where there is useful data directly after the compressed data
523 stream and you know beforehand the exact length of the compressed data
524 stream.
525 .Sp
526 This option is mostly used when reading from a filehandle, in which case
527 the file pointer will be left pointing to the first byte directly after the
528 compressed data stream.
529 .Sp
530 This option defaults to off.
531 .ie n .IP """Append => 0|1""" 5
532 .el .IP "\f(CWAppend => 0|1\fR" 5
533 .IX Item "Append => 0|1"
534 This option controls what the \f(CW\*(C`read\*(C'\fR method does with uncompressed data.
535 .Sp
536 If set to 1, all uncompressed data will be appended to the output parameter
537 of the \f(CW\*(C`read\*(C'\fR method.
538 .Sp
539 If set to 0, the contents of the output parameter of the \f(CW\*(C`read\*(C'\fR method
540 will be overwritten by the uncompressed data.
541 .Sp
542 Defaults to 0.
543 .ie n .IP """Strict => 0|1""" 5
544 .el .IP "\f(CWStrict => 0|1\fR" 5
545 .IX Item "Strict => 0|1"
546 This option controls whether the extra checks defined below are used when
547 carrying out the decompression. When Strict is on, the extra tests are
548 carried out, when Strict is off they are not.
549 .Sp
550 The default for this option is off.
551 .Sp
552 If the input is an RFC 1950 data stream, the following will be checked:
553 .RS 5
554 .IP 1. 5
555 The ADLER32 checksum field must be present.
556 .IP 2. 5
557 The value of the ADLER32 field read must match the adler32 value of the
558 uncompressed data actually contained in the file.
559 .RE
560 .RS 5
561 .Sp
562 If the input is a gzip (RFC 1952) data stream, the following will be checked:
563 .IP 1. 5
564 If the FHCRC bit is set in the gzip FLG header byte, the CRC16 bytes in the
565 header must match the crc16 value of the gzip header actually read.
566 .IP 2. 5
567 If the gzip header contains a name field (FNAME) it consists solely of ISO
568 8859\-1 characters.
569 .IP 3. 5
570 If the gzip header contains a comment field (FCOMMENT) it consists solely
571 of ISO 8859\-1 characters plus line\-feed.
572 .IP 4. 5
573 If the gzip FEXTRA header field is present it must conform to the sub\-field
574 structure as defined in RFC 1952.
575 .IP 5. 5
576 The CRC32 and ISIZE trailer fields must be present.
577 .IP 6. 5
578 The value of the CRC32 field read must match the crc32 value of the
579 uncompressed data actually contained in the gzip file.
580 .IP 7. 5
581 The value of the ISIZE fields read must match the length of the
582 uncompressed data actually read from the file.
583 .RE
584 .RS 5
585 .RE
586 .ie n .IP """RawInflate => 0|1""" 5
587 .el .IP "\f(CWRawInflate => 0|1\fR" 5
588 .IX Item "RawInflate => 0|1"
589 When auto\-detecting the compressed format, try to test for raw\-deflate (RFC
590 1951) content using the \f(CW\*(C`IO::Uncompress::RawInflate\*(C'\fR module.
591 .Sp
592 The reason this is not default behaviour is because RFC 1951 content can
593 only be detected by attempting to uncompress it. This process is error
594 prone and can result is false positives.
595 .Sp
596 Defaults to 0.
597 .ie n .IP """ParseExtra => 0|1"" If the gzip FEXTRA header field is present and this option is set, it will force the module to check that it conforms to the sub\-field structure as defined in RFC 1952." 5
598 .el .IP "\f(CWParseExtra => 0|1\fR If the gzip FEXTRA header field is present and this option is set, it will force the module to check that it conforms to the sub\-field structure as defined in RFC 1952." 5
599 .IX Item "ParseExtra => 0|1 If the gzip FEXTRA header field is present and this option is set, it will force the module to check that it conforms to the sub-field structure as defined in RFC 1952."
600 If the \f(CW\*(C`Strict\*(C'\fR is on it will automatically enable this option.
601 .Sp
602 Defaults to 0.
603 .SH Methods
604 .IX Header "Methods"
605 .SS read
606 .IX Subsection "read"
607 Usage is
608 .PP
609 .Vb 1
610 \& $status = $z\->read($buffer)
611 .Ve
612 .PP
613 Reads a block of compressed data (the size of the compressed block is
614 determined by the \f(CW\*(C`Buffer\*(C'\fR option in the constructor), uncompresses it and
615 writes any uncompressed data into \f(CW$buffer\fR. If the \f(CW\*(C`Append\*(C'\fR parameter is
616 set in the constructor, the uncompressed data will be appended to the
617 \&\f(CW$buffer\fR parameter. Otherwise \f(CW$buffer\fR will be overwritten.
618 .PP
619 Returns the number of uncompressed bytes written to \f(CW$buffer\fR, zero if eof
620 or a negative number on error.
621 .SS read
622 .IX Subsection "read"
623 Usage is
624 .PP
625 .Vb 2
626 \& $status = $z\->read($buffer, $length)
627 \& $status = $z\->read($buffer, $length, $offset)
628 \&
629 \& $status = read($z, $buffer, $length)
630 \& $status = read($z, $buffer, $length, $offset)
631 .Ve
632 .PP
633 Attempt to read \f(CW$length\fR bytes of uncompressed data into \f(CW$buffer\fR.
634 .PP
635 The main difference between this form of the \f(CW\*(C`read\*(C'\fR method and the
636 previous one, is that this one will attempt to return \fIexactly\fR \f(CW$length\fR
637 bytes. The only circumstances that this function will not is if end\-of\-file
638 or an IO error is encountered.
639 .PP
640 Returns the number of uncompressed bytes written to \f(CW$buffer\fR, zero if eof
641 or a negative number on error.
642 .SS getline
643 .IX Subsection "getline"
644 Usage is
645 .PP
646 .Vb 2
647 \& $line = $z\->getline()
648 \& $line = <$z>
649 .Ve
650 .PP
651 Reads a single line.
652 .PP
653 This method fully supports the use of the variable \f(CW$/\fR (or
654 \&\f(CW$INPUT_RECORD_SEPARATOR\fR or \f(CW$RS\fR when \f(CW\*(C`English\*(C'\fR is in use) to
655 determine what constitutes an end of line. Paragraph mode, record mode and
656 file slurp mode are all supported.
657 .SS getc
658 .IX Subsection "getc"
659 Usage is
660 .PP
661 .Vb 1
662 \& $char = $z\->getc()
663 .Ve
664 .PP
665 Read a single character.
666 .SS ungetc
667 .IX Subsection "ungetc"
668 Usage is
669 .PP
670 .Vb 1
671 \& $char = $z\->ungetc($string)
672 .Ve
673 .SS inflateSync
674 .IX Subsection "inflateSync"
675 Usage is
676 .PP
677 .Vb 1
678 \& $status = $z\->inflateSync()
679 .Ve
680 .PP
681 TODO
682 .SS getHeaderInfo
683 .IX Subsection "getHeaderInfo"
684 Usage is
685 .PP
686 .Vb 2
687 \& $hdr = $z\->getHeaderInfo();
688 \& @hdrs = $z\->getHeaderInfo();
689 .Ve
690 .PP
691 This method returns either a hash reference (in scalar context) or a list
692 or hash references (in array context) that contains information about each
693 of the header fields in the compressed data stream(s).
694 .SS tell
695 .IX Subsection "tell"
696 Usage is
697 .PP
698 .Vb 2
699 \& $z\->tell()
700 \& tell $z
701 .Ve
702 .PP
703 Returns the uncompressed file offset.
704 .SS eof
705 .IX Subsection "eof"
706 Usage is
707 .PP
708 .Vb 2
709 \& $z\->eof();
710 \& eof($z);
711 .Ve
712 .PP
713 Returns true if the end of the compressed input stream has been reached.
714 .SS seek
715 .IX Subsection "seek"
716 .Vb 2
717 \& $z\->seek($position, $whence);
718 \& seek($z, $position, $whence);
719 .Ve
720 .PP
721 Provides a sub\-set of the \f(CW\*(C`seek\*(C'\fR functionality, with the restriction
722 that it is only legal to seek forward in the input file/buffer.
723 It is a fatal error to attempt to seek backward.
724 .PP
725 Note that the implementation of \f(CW\*(C`seek\*(C'\fR in this module does not provide
726 true random access to a compressed file/buffer. It works by uncompressing
727 data from the current offset in the file/buffer until it reaches the
728 uncompressed offset specified in the parameters to \f(CW\*(C`seek\*(C'\fR. For very small
729 files this may be acceptable behaviour. For large files it may cause an
730 unacceptable delay.
731 .PP
732 The \f(CW$whence\fR parameter takes one the usual values, namely SEEK_SET,
733 SEEK_CUR or SEEK_END.
734 .PP
735 Returns 1 on success, 0 on failure.
736 .SS binmode
737 .IX Subsection "binmode"
738 Usage is
739 .PP
740 .Vb 2
741 \& $z\->binmode
742 \& binmode $z ;
743 .Ve
744 .PP
745 This is a noop provided for completeness.
746 .SS opened
747 .IX Subsection "opened"
748 .Vb 1
749 \& $z\->opened()
750 .Ve
751 .PP
752 Returns true if the object currently refers to a opened file/buffer.
753 .SS autoflush
754 .IX Subsection "autoflush"
755 .Vb 2
756 \& my $prev = $z\->autoflush()
757 \& my $prev = $z\->autoflush(EXPR)
758 .Ve
759 .PP
760 If the \f(CW$z\fR object is associated with a file or a filehandle, this method
761 returns the current autoflush setting for the underlying filehandle. If
762 \&\f(CW\*(C`EXPR\*(C'\fR is present, and is non\-zero, it will enable flushing after every
763 write/print operation.
764 .PP
765 If \f(CW$z\fR is associated with a buffer, this method has no effect and always
766 returns \f(CW\*(C`undef\*(C'\fR.
767 .PP
768 \&\fBNote\fR that the special variable \f(CW$|\fR \fBcannot\fR be used to set or
769 retrieve the autoflush setting.
770 .SS input_line_number
771 .IX Subsection "input_line_number"
772 .Vb 2
773 \& $z\->input_line_number()
774 \& $z\->input_line_number(EXPR)
775 .Ve
776 .PP
777 Returns the current uncompressed line number. If \f(CW\*(C`EXPR\*(C'\fR is present it has
778 the effect of setting the line number. Note that setting the line number
779 does not change the current position within the file/buffer being read.
780 .PP
781 The contents of \f(CW$/\fR are used to determine what constitutes a line
782 terminator.
783 .SS fileno
784 .IX Subsection "fileno"
785 .Vb 2
786 \& $z\->fileno()
787 \& fileno($z)
788 .Ve
789 .PP
790 If the \f(CW$z\fR object is associated with a file or a filehandle, \f(CW\*(C`fileno\*(C'\fR
791 will return the underlying file descriptor. Once the \f(CW\*(C`close\*(C'\fR method is
792 called \f(CW\*(C`fileno\*(C'\fR will return \f(CW\*(C`undef\*(C'\fR.
793 .PP
794 If the \f(CW$z\fR object is associated with a buffer, this method will return
795 \&\f(CW\*(C`undef\*(C'\fR.
796 .SS close
797 .IX Subsection "close"
798 .Vb 2
799 \& $z\->close() ;
800 \& close $z ;
801 .Ve
802 .PP
803 Closes the output file/buffer.
804 .PP
805 For most versions of Perl this method will be automatically invoked if
806 the IO::Uncompress::AnyInflate object is destroyed (either explicitly or by the
807 variable with the reference to the object going out of scope). The
808 exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
809 these cases, the \f(CW\*(C`close\*(C'\fR method will be called automatically, but
810 not until global destruction of all live objects when the program is
811 terminating.
812 .PP
813 Therefore, if you want your scripts to be able to run on all versions
814 of Perl, you should call \f(CW\*(C`close\*(C'\fR explicitly and not rely on automatic
815 closing.
816 .PP
817 Returns true on success, otherwise 0.
818 .PP
819 If the \f(CW\*(C`AutoClose\*(C'\fR option has been enabled when the IO::Uncompress::AnyInflate
820 object was created, and the object is associated with a file, the
821 underlying file will also be closed.
822 .SS nextStream
823 .IX Subsection "nextStream"
824 Usage is
825 .PP
826 .Vb 1
827 \& my $status = $z\->nextStream();
828 .Ve
829 .PP
830 Skips to the next compressed data stream in the input file/buffer. If a new
831 compressed data stream is found, the eof marker will be cleared and \f(CW$.\fR
832 will be reset to 0.
833 .PP
834 Returns 1 if a new stream was found, 0 if none was found, and \-1 if an
835 error was encountered.
836 .SS trailingData
837 .IX Subsection "trailingData"
838 Usage is
839 .PP
840 .Vb 1
841 \& my $data = $z\->trailingData();
842 .Ve
843 .PP
844 Returns the data, if any, that is present immediately after the compressed
845 data stream once uncompression is complete. It only makes sense to call
846 this method once the end of the compressed data stream has been
847 encountered.
848 .PP
849 This option can be used when there is useful information immediately
850 following the compressed data stream, and you don\*(Aqt know the length of the
851 compressed data stream.
852 .PP
853 If the input is a buffer, \f(CW\*(C`trailingData\*(C'\fR will return everything from the
854 end of the compressed data stream to the end of the buffer.
855 .PP
856 If the input is a filehandle, \f(CW\*(C`trailingData\*(C'\fR will return the data that is
857 left in the filehandle input buffer once the end of the compressed data
858 stream has been reached. You can then use the filehandle to read the rest
859 of the input file.
860 .PP
861 Don\*(Aqt bother using \f(CW\*(C`trailingData\*(C'\fR if the input is a filename.
862 .PP
863 If you know the length of the compressed data stream before you start
864 uncompressing, you can avoid having to use \f(CW\*(C`trailingData\*(C'\fR by setting the
865 \&\f(CW\*(C`InputLength\*(C'\fR option in the constructor.
866 .SH Importing
867 .IX Header "Importing"
868 No symbolic constants are required by IO::Uncompress::AnyInflate at present.
869 .IP :all 5
870 .IX Item ":all"
871 Imports \f(CW\*(C`anyinflate\*(C'\fR and \f(CW$AnyInflateError\fR.
872 Same as doing this
873 .Sp
874 .Vb 1
875 \& use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
876 .Ve
877 .SH EXAMPLES
878 .IX Header "EXAMPLES"
879 .SS "Working with Net::FTP"
880 .IX Subsection "Working with Net::FTP"
881 See IO::Compress::FAQ
882 .SH SUPPORT
883 .IX Header "SUPPORT"
884 General feedback/questions/bug reports should be sent to
885 <https://github.com/pmqs/IO\-Compress/issues> (preferred) or
886 <https://rt.cpan.org/Public/Dist/Display.html?Name=IO\-Compress>.
887 .SH "SEE ALSO"
888 .IX Header "SEE ALSO"
889 Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate, IO::Uncompress::Inflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate, IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma, IO::Uncompress::UnLzma, IO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzip, IO::Uncompress::UnLzip, IO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Compress::Zstd, IO::Uncompress::UnZstd, IO::Uncompress::AnyUncompress
890 .PP
891 IO::Compress::FAQ
892 .PP
893 File::GlobMapper, Archive::Zip,
894 Archive::Tar,
895 IO::Zlib
896 .PP
897 For RFC 1950, 1951 and 1952 see
898 <https://datatracker.ietf.org/doc/html/rfc1950>,
899 <https://datatracker.ietf.org/doc/html/rfc1951> and
900 <https://datatracker.ietf.org/doc/html/rfc1952>
901 .PP
902 The \fIzlib\fR compression library was written by Jean\-loup Gailly
903 \&\f(CW\*(C`[email protected]\*(C'\fR and Mark Adler \f(CW\*(C`[email protected]\*(C'\fR.
904 .PP
905 The primary site for the \fIzlib\fR compression library is
906 <http://www.zlib.org>.
907 .PP
908 The primary site for the \fIzlib\-ng\fR compression library is
909 <https://github.com/zlib\-ng/zlib\-ng>.
910 .PP
911 The primary site for gzip is <http://www.gzip.org>.
912 .SH AUTHOR
913 .IX Header "AUTHOR"
914 This module was written by Paul Marquess, \f(CW\*(C`[email protected]\*(C'\fR.
915 .SH "MODIFICATION HISTORY"
916 .IX Header "MODIFICATION HISTORY"
917 See the Changes file.
918 .SH "COPYRIGHT AND LICENSE"
919 .IX Header "COPYRIGHT AND LICENSE"
920 Copyright (c) 2005\-2024 Paul Marquess. All rights reserved.
921 .PP
922 This program is free software; you can redistribute it and/or
923 modify it under the same terms as Perl itself.