Debian Codegraph @

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