Debian Codegraph @

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