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