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