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