Debian Codegraph @

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