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