Debian Codegraph @

upstream/debian-unstable/man3/IO::Uncompress::AnyInflate.3perl

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