Debian Codegraph @

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