Debian Codegraph @

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