Debian Codegraph @

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