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