1package IO::Uncompress::Bunzip2 ;
2
3use strict ;
4use warnings;
5use bytes;
6
7use IO::Compress::Base::Common 2.212 qw(:Status );
8
9use IO::Uncompress::Base 2.212 ;
10use IO::Uncompress::Adapter::Bunzip2 2.212 ;
11
12require Exporter ;
13our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $Bunzip2Error);
14
15$VERSION = '2.212';
16$Bunzip2Error = '';
17
18@ISA    = qw(IO::Uncompress::Base Exporter);
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
134                  # ASCII:  B   Z   h    0    9
135    return $buffer =~ qr/^\x42\x5A\x68[\x30-\x39]$/;
136}
137
1381 ;
139
140__END__
141
142
143=head1 NAME
144
145IO::Uncompress::Bunzip2 - Read bzip2 files/buffers
146
147=head1 SYNOPSIS
148
149    use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error) ;
150
151    my $status = bunzip2 $input => $output [,OPTS]
152        or die "bunzip2 failed: $Bunzip2Error\n";
153
154    my $z = IO::Uncompress::Bunzip2->new( $input [OPTS] )
155        or die "bunzip2 failed: $Bunzip2Error\n";
156
157    $status = $z->read($buffer)
158    $status = $z->read($buffer, $length)
159    $status = $z->read($buffer, $length, $offset)
160    $line = $z->getline()
161    $char = $z->getc()
162    $char = $z->ungetc()
163    $char = $z->opened()
164
165    $data = $z->trailingData()
166    $status = $z->nextStream()
167    $data = $z->getHeaderInfo()
168    $z->tell()
169    $z->seek($position, $whence)
170    $z->binmode()
171    $z->fileno()
172    $z->eof()
173    $z->close()
174
175    $Bunzip2Error ;
176
177    # IO::File mode
178
179    <$z>
180    read($z, $buffer);
181    read($z, $buffer, $length);
182    read($z, $buffer, $length, $offset);
183    tell($z)
184    seek($z, $position, $whence)
185    binmode($z)
186    fileno($z)
187    eof($z)
188    close($z)
189
190=head1 DESCRIPTION
191
192This module provides a Perl interface that allows the reading of
193bzip2 files/buffers.
194
195For writing bzip2 files/buffers, see the companion module IO::Compress::Bzip2.
196
197=head1 Functional Interface
198
199A top-level function, C<bunzip2>, is provided to carry out
200"one-shot" uncompression between buffers and/or files. For finer
201control over the uncompression process, see the L</"OO Interface">
202section.
203
204    use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error) ;
205
206    bunzip2 $input_filename_or_reference => $output_filename_or_reference [,OPTS]
207        or die "bunzip2 failed: $Bunzip2Error\n";
208
209The functional interface needs Perl5.005 or better.
210
211=head2 bunzip2 $input_filename_or_reference => $output_filename_or_reference [, OPTS]
212
213C<bunzip2> expects at least two parameters,
214C<$input_filename_or_reference> and C<$output_filename_or_reference>
215and zero or more optional parameters (see L</Optional Parameters>)
216
217=head3 The C<$input_filename_or_reference> parameter
218
219The parameter, C<$input_filename_or_reference>, is used to define the
220source of the compressed data.
221
222It can take one of the following forms:
223
224=over 5
225
226=item A filename
227
228If the C<$input_filename_or_reference> parameter is a simple scalar, it is
229assumed to be a filename. This file will be opened for reading and the
230input data will be read from it.
231
232=item A filehandle
233
234If the C<$input_filename_or_reference> parameter is a filehandle, the input
235data will be read from it.  The string '-' can be used as an alias for
236standard input.
237
238=item A scalar reference
239
240If C<$input_filename_or_reference> is a scalar reference, the input data
241will be read from C<$$input_filename_or_reference>.
242
243=item An array reference
244
245If C<$input_filename_or_reference> is an array reference, each element in
246the array must be a filename.
247
248The input data will be read from each file in turn.
249
250The complete array will be walked to ensure that it only
251contains valid filenames before any data is uncompressed.
252
253=item An Input FileGlob string
254
255If C<$input_filename_or_reference> is a string that is delimited by the
256characters "<" and ">" C<bunzip2> will assume that it is an
257I<input fileglob string>. The input is the list of files that match the
258fileglob.
259
260See L<File::GlobMapper|File::GlobMapper> for more details.
261
262=back
263
264If the C<$input_filename_or_reference> parameter is any other type,
265C<undef> will be returned.
266
267=head3 The C<$output_filename_or_reference> parameter
268
269The parameter C<$output_filename_or_reference> is used to control the
270destination of the uncompressed data. This parameter can take one of
271these forms.
272
273=over 5
274
275=item A filename
276
277If the C<$output_filename_or_reference> parameter is a simple scalar, it is
278assumed to be a filename.  This file will be opened for writing and the
279uncompressed data will be written to it.
280
281=item A filehandle
282
283If the C<$output_filename_or_reference> parameter is a filehandle, the
284uncompressed data will be written to it.  The string '-' can be used as
285an alias for standard output.
286
287=item A scalar reference
288
289If C<$output_filename_or_reference> is a scalar reference, the
290uncompressed data will be stored in C<$$output_filename_or_reference>.
291
292=item An Array Reference
293
294If C<$output_filename_or_reference> is an array reference,
295the uncompressed data will be pushed onto the array.
296
297=item An Output FileGlob
298
299If C<$output_filename_or_reference> is a string that is delimited by the
300characters "<" and ">" C<bunzip2> will assume that it is an
301I<output fileglob string>. The output is the list of files that match the
302fileglob.
303
304When C<$output_filename_or_reference> is an fileglob string,
305C<$input_filename_or_reference> must also be a fileglob string. Anything
306else is an error.
307
308See L<File::GlobMapper|File::GlobMapper> for more details.
309
310=back
311
312If the C<$output_filename_or_reference> parameter is any other type,
313C<undef> will be returned.
314
315=head2 Notes
316
317When C<$input_filename_or_reference> maps to multiple compressed
318files/buffers and C<$output_filename_or_reference> is
319a single file/buffer, after uncompression C<$output_filename_or_reference> will contain a
320concatenation of all the uncompressed data from each of the input
321files/buffers.
322
323=head2 Optional Parameters
324
325The optional parameters for the one-shot function C<bunzip2>
326are (for the most part) identical to those used with the OO interface defined in the
327L</"Constructor Options"> section. The exceptions are listed below
328
329=over 5
330
331=item C<< AutoClose => 0|1 >>
332
333This option applies to any input or output data streams to
334C<bunzip2> that are filehandles.
335
336If C<AutoClose> is specified, and the value is true, it will result in all
337input and/or output filehandles being closed once C<bunzip2> has
338completed.
339
340This parameter defaults to 0.
341
342=item C<< BinModeOut => 0|1 >>
343
344This option is now a no-op. All files will be written  in binmode.
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 OneShot 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 = IO::File->new( "<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 = IO::Uncompress::Bunzip2->new( $input [OPTS] )
481        or die "IO::Uncompress::Bunzip2 failed: $Bunzip2Error\n";
482
483The constructor takes one mandatory parameter, C<$input>, defined below, and
484zero or more C<OPTS>, defined in L<Constructor Options>.
485
486Returns an C<IO::Uncompress::Bunzip2> object on success and undef on failure.
487The variable C<$Bunzip2Error> will contain an error message on failure.
488
489If you are running Perl 5.005 or better the object, C<$z>, returned from
490IO::Uncompress::Bunzip2 can be used exactly like an L<IO::File|IO::File> filehandle.
491This means that all normal input file operations can be carried out with
492C<$z>.  For example, to read a line from a compressed file/buffer you can
493use either of these forms
494
495    $line = $z->getline();
496    $line = <$z>;
497
498Below is a simple exaple of using the OO interface to read the compressed file
499C<myfile.bz2> and write its contents to stdout.
500
501    my $filename = "myfile.bz2";
502    my $z = IO::Uncompress::Bunzip2->new($filename)
503        or die "IO::Uncompress::Bunzip2 failed: $Bunzip2Error\n";
504
505    while (<$z>) {
506        print $_;
507    }
508    $z->close();
509
510See L</EXAMPLES> for further examples
511
512The mandatory parameter C<$input> is used to determine the source of the
513compressed data. This parameter can take one of three forms.
514
515=over 5
516
517=item A filename
518
519If the C<$input> parameter is a scalar, it is assumed to be a filename. This
520file will be opened for reading and the compressed data will be read from it.
521
522=item A filehandle
523
524If the C<$input> parameter is a filehandle, the compressed data will be
525read from it.
526The string '-' can be used as an alias for standard input.
527
528=item A scalar reference
529
530If C<$input> is a scalar reference, the compressed data will be read from
531C<$$input>.
532
533=back
534
535=head2 Constructor Options
536
537The option names defined below are case insensitive and can be optionally
538prefixed by a '-'.  So all of the following are valid
539
540    -AutoClose
541    -autoclose
542    AUTOCLOSE
543    autoclose
544
545OPTS is a combination of the following options:
546
547=over 5
548
549=item C<< AutoClose => 0|1 >>
550
551This option is only valid when the C<$input> parameter is a filehandle. If
552specified, and the value is true, it will result in the file being closed once
553either the C<close> method is called or the IO::Uncompress::Bunzip2 object is
554destroyed.
555
556This parameter defaults to 0.
557
558=item C<< MultiStream => 0|1 >>
559
560Allows multiple concatenated compressed streams to be treated as a single
561compressed stream. Decompression will stop once either the end of the
562file/buffer is reached, an error is encountered (premature eof, corrupt
563compressed data) or the end of a stream is not immediately followed by the
564start of another stream.
565
566This parameter defaults to 0.
567
568=item C<< Prime => $string >>
569
570This option will uncompress the contents of C<$string> before processing the
571input file/buffer.
572
573This option can be useful when the compressed data is embedded in another
574file/data structure and it is not possible to work out where the compressed
575data begins without having to read the first few bytes. If this is the
576case, the uncompression can be I<primed> with these bytes using this
577option.
578
579=item C<< Transparent => 0|1 >>
580
581If this option is set and the input file/buffer is not compressed data,
582the module will allow reading of it anyway.
583
584In addition, if the input file/buffer does contain compressed data and
585there is non-compressed data immediately following it, setting this option
586will make this module treat the whole file/buffer as a single data stream.
587
588This option defaults to 1.
589
590=item C<< BlockSize => $num >>
591
592When reading the compressed input data, IO::Uncompress::Bunzip2 will read it in
593blocks of C<$num> bytes.
594
595This option defaults to 4096.
596
597=item C<< InputLength => $size >>
598
599When present this option will limit the number of compressed bytes read
600from the input file/buffer to C<$size>. This option can be used in the
601situation where there is useful data directly after the compressed data
602stream and you know beforehand the exact length of the compressed data
603stream.
604
605This option is mostly used when reading from a filehandle, in which case
606the file pointer will be left pointing to the first byte directly after the
607compressed data stream.
608
609This option defaults to off.
610
611=item C<< Append => 0|1 >>
612
613This option controls what the C<read> method does with uncompressed data.
614
615If set to 1, all uncompressed data will be appended to the output parameter
616of the C<read> method.
617
618If set to 0, the contents of the output parameter of the C<read> method
619will be overwritten by the uncompressed data.
620
621Defaults to 0.
622
623=item C<< Strict => 0|1 >>
624
625This option is a no-op.
626
627=item C<< Small => 0|1 >>
628
629When non-zero this options will make bzip2 use a decompression algorithm
630that uses less memory at the expense of increasing the amount of time
631taken for decompression.
632
633Default is 0.
634
635=back
636
637=head1 Methods
638
639=head2 read
640
641Usage is
642
643    $status = $z->read($buffer)
644
645Reads a block of compressed data (the size of the compressed block is
646determined by the C<Buffer> option in the constructor), uncompresses it and
647writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
648set in the constructor, the uncompressed data will be appended to the
649C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
650
651Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
652or a negative number on error.
653
654=head2 read
655
656Usage is
657
658    $status = $z->read($buffer, $length)
659    $status = $z->read($buffer, $length, $offset)
660
661    $status = read($z, $buffer, $length)
662    $status = read($z, $buffer, $length, $offset)
663
664Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
665
666The main difference between this form of the C<read> method and the
667previous one, is that this one will attempt to return I<exactly> C<$length>
668bytes. The only circumstances that this function will not is if end-of-file
669or an IO error is encountered.
670
671Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
672or a negative number on error.
673
674=head2 getline
675
676Usage is
677
678    $line = $z->getline()
679    $line = <$z>
680
681Reads a single line.
682
683This method fully supports the use of the variable C<$/> (or
684C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
685determine what constitutes an end of line. Paragraph mode, record mode and
686file slurp mode are all supported.
687
688=head2 getc
689
690Usage is
691
692    $char = $z->getc()
693
694Read a single character.
695
696=head2 ungetc
697
698Usage is
699
700    $char = $z->ungetc($string)
701
702=head2 getHeaderInfo
703
704Usage is
705
706    $hdr  = $z->getHeaderInfo();
707    @hdrs = $z->getHeaderInfo();
708
709This method returns either a hash reference (in scalar context) or a list
710or hash references (in array context) that contains information about each
711of the header fields in the compressed data stream(s).
712
713=head2 tell
714
715Usage is
716
717    $z->tell()
718    tell $z
719
720Returns the uncompressed file offset.
721
722=head2 eof
723
724Usage is
725
726    $z->eof();
727    eof($z);
728
729Returns true if the end of the compressed input stream has been reached.
730
731=head2 seek
732
733    $z->seek($position, $whence);
734    seek($z, $position, $whence);
735
736Provides a sub-set of the C<seek> functionality, with the restriction
737that it is only legal to seek forward in the input file/buffer.
738It is a fatal error to attempt to seek backward.
739
740Note that the implementation of C<seek> in this module does not provide
741true random access to a compressed file/buffer. It  works by uncompressing
742data from the current offset in the file/buffer until it reaches the
743uncompressed offset specified in the parameters to C<seek>. For very small
744files this may be acceptable behaviour. For large files it may cause an
745unacceptable delay.
746
747The C<$whence> parameter takes one the usual values, namely SEEK_SET,
748SEEK_CUR or SEEK_END.
749
750Returns 1 on success, 0 on failure.
751
752=head2 binmode
753
754Usage is
755
756    $z->binmode
757    binmode $z ;
758
759This is a noop provided for completeness.
760
761=head2 opened
762
763    $z->opened()
764
765Returns true if the object currently refers to a opened file/buffer.
766
767=head2 autoflush
768
769    my $prev = $z->autoflush()
770    my $prev = $z->autoflush(EXPR)
771
772If the C<$z> object is associated with a file or a filehandle, this method
773returns the current autoflush setting for the underlying filehandle. If
774C<EXPR> is present, and is non-zero, it will enable flushing after every
775write/print operation.
776
777If C<$z> is associated with a buffer, this method has no effect and always
778returns C<undef>.
779
780B<Note> that the special variable C<$|> B<cannot> be used to set or
781retrieve the autoflush setting.
782
783=head2 input_line_number
784
785    $z->input_line_number()
786    $z->input_line_number(EXPR)
787
788Returns the current uncompressed line number. If C<EXPR> is present it has
789the effect of setting the line number. Note that setting the line number
790does not change the current position within the file/buffer being read.
791
792The contents of C<$/> are used to determine what constitutes a line
793terminator.
794
795=head2 fileno
796
797    $z->fileno()
798    fileno($z)
799
800If the C<$z> object is associated with a file or a filehandle, C<fileno>
801will return the underlying file descriptor. Once the C<close> method is
802called C<fileno> will return C<undef>.
803
804If the C<$z> object is associated with a buffer, this method will return
805C<undef>.
806
807=head2 close
808
809    $z->close() ;
810    close $z ;
811
812Closes the output file/buffer.
813
814For most versions of Perl this method will be automatically invoked if
815the IO::Uncompress::Bunzip2 object is destroyed (either explicitly or by the
816variable with the reference to the object going out of scope). The
817exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
818these cases, the C<close> method will be called automatically, but
819not until global destruction of all live objects when the program is
820terminating.
821
822Therefore, if you want your scripts to be able to run on all versions
823of Perl, you should call C<close> explicitly and not rely on automatic
824closing.
825
826Returns true on success, otherwise 0.
827
828If the C<AutoClose> option has been enabled when the IO::Uncompress::Bunzip2
829object was created, and the object is associated with a file, the
830underlying file will also be closed.
831
832=head2 nextStream
833
834Usage is
835
836    my $status = $z->nextStream();
837
838Skips to the next compressed data stream in the input file/buffer. If a new
839compressed data stream is found, the eof marker will be cleared and C<$.>
840will be reset to 0.
841
842Returns 1 if a new stream was found, 0 if none was found, and -1 if an
843error was encountered.
844
845=head2 trailingData
846
847Usage is
848
849    my $data = $z->trailingData();
850
851Returns the data, if any, that is present immediately after the compressed
852data stream once uncompression is complete. It only makes sense to call
853this method once the end of the compressed data stream has been
854encountered.
855
856This option can be used when there is useful information immediately
857following the compressed data stream, and you don't know the length of the
858compressed data stream.
859
860If the input is a buffer, C<trailingData> will return everything from the
861end of the compressed data stream to the end of the buffer.
862
863If the input is a filehandle, C<trailingData> will return the data that is
864left in the filehandle input buffer once the end of the compressed data
865stream has been reached. You can then use the filehandle to read the rest
866of the input file.
867
868Don't bother using C<trailingData> if the input is a filename.
869
870If you know the length of the compressed data stream before you start
871uncompressing, you can avoid having to use C<trailingData> by setting the
872C<InputLength> option in the constructor.
873
874=head1 Importing
875
876No symbolic constants are required by IO::Uncompress::Bunzip2 at present.
877
878=over 5
879
880=item :all
881
882Imports C<bunzip2> and C<$Bunzip2Error>.
883Same as doing this
884
885    use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error) ;
886
887=back
888
889=head1 EXAMPLES
890
891=head2 Working with Net::FTP
892
893See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
894
895=head1 SUPPORT
896
897General feedback/questions/bug reports should be sent to
898L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
899L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
900
901=head1 SEE ALSO
902
903L<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::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
904
905L<IO::Compress::FAQ|IO::Compress::FAQ>
906
907L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
908L<Archive::Tar|Archive::Tar>,
909L<IO::Zlib|IO::Zlib>
910
911The primary site for the bzip2 program is L<https://sourceware.org/bzip2/>.
912
913See the module L<Compress::Bzip2|Compress::Bzip2>
914
915=head1 AUTHOR
916
917This module was written by Paul Marquess, C<pmqs@cpan.org>.
918
919=head1 MODIFICATION HISTORY
920
921See the Changes file.
922
923=head1 COPYRIGHT AND LICENSE
924
925Copyright (c) 2005-2024 Paul Marquess. All rights reserved.
926
927This program is free software; you can redistribute it and/or
928modify it under the same terms as Perl itself.
929