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