1IO::Uncompress::InflateU(s3e)r Contributed Perl DocumentaItOi:o:nUncompress::Inflate(3)
2
3
4
6 IO::Uncompress::Inflate - Read RFC 1950 files/buffers
7
9 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
10
11 my $status = inflate $input => $output [,OPTS]
12 or die "inflate failed: $InflateError\n";
13
14 my $z = new IO::Uncompress::Inflate $input [OPTS]
15 or die "inflate failed: $InflateError\n";
16
17 $status = $z->read($buffer)
18 $status = $z->read($buffer, $length)
19 $status = $z->read($buffer, $length, $offset)
20 $line = $z->getline()
21 $char = $z->getc()
22 $char = $z->ungetc()
23 $char = $z->opened()
24
25 $status = $z->inflateSync()
26
27 $data = $z->trailingData()
28 $status = $z->nextStream()
29 $data = $z->getHeaderInfo()
30 $z->tell()
31 $z->seek($position, $whence)
32 $z->binmode()
33 $z->fileno()
34 $z->eof()
35 $z->close()
36
37 $InflateError ;
38
39 # IO::File mode
40
41 <$z>
42 read($z, $buffer);
43 read($z, $buffer, $length);
44 read($z, $buffer, $length, $offset);
45 tell($z)
46 seek($z, $position, $whence)
47 binmode($z)
48 fileno($z)
49 eof($z)
50 close($z)
51
53 This module provides a Perl interface that allows the reading of
54 files/buffers that conform to RFC 1950.
55
56 For writing RFC 1950 files/buffers, see the companion module IO::Com‐
57 press::Deflate.
58
60 A top-level function, "inflate", is provided to carry out "one-shot"
61 uncompression between buffers and/or files. For finer control over the
62 uncompression process, see the "OO Interface" section.
63
64 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
65
66 inflate $input => $output [,OPTS]
67 or die "inflate failed: $InflateError\n";
68
69 The functional interface needs Perl5.005 or better.
70
71 inflate $input => $output [, OPTS]
72
73 "inflate" expects at least two parameters, $input and $output.
74
75 The $input parameter
76
77 The parameter, $input, is used to define the source of the compressed
78 data.
79
80 It can take one of the following forms:
81
82 A filename
83 If the $input parameter is a simple scalar, it is assumed to be a
84 filename. This file will be opened for reading and the input data
85 will be read from it.
86
87 A filehandle
88 If the $input parameter is a filehandle, the input data will be
89 read from it. The string '-' can be used as an alias for standard
90 input.
91
92 A scalar reference
93 If $input is a scalar reference, the input data will be read from
94 $$input.
95
96 An array reference
97 If $input is an array reference, each element in the array must be
98 a filename.
99
100 The input data will be read from each file in turn.
101
102 The complete array will be walked to ensure that it only contains
103 valid filenames before any data is uncompressed.
104
105 An Input FileGlob string
106 If $input is a string that is delimited by the characters "<" and
107 ">" "inflate" will assume that it is an input fileglob string. The
108 input is the list of files that match the fileglob.
109
110 If the fileglob does not match any files ...
111
112 See File::GlobMapper for more details.
113
114 If the $input parameter is any other type, "undef" will be returned.
115
116 The $output parameter
117
118 The parameter $output is used to control the destination of the uncom‐
119 pressed data. This parameter can take one of these forms.
120
121 A filename
122 If the $output parameter is a simple scalar, it is assumed to be a
123 filename. This file will be opened for writing and the uncom‐
124 pressed data will be written to it.
125
126 A filehandle
127 If the $output parameter is a filehandle, the uncompressed data
128 will be written to it. The string '-' can be used as an alias for
129 standard output.
130
131 A scalar reference
132 If $output is a scalar reference, the uncompressed data will be
133 stored in $$output.
134
135 An Array Reference
136 If $output is an array reference, the uncompressed data will be
137 pushed onto the array.
138
139 An Output FileGlob
140 If $output is a string that is delimited by the characters "<" and
141 ">" "inflate" will assume that it is an output fileglob string.
142 The output is the list of files that match the fileglob.
143
144 When $output is an fileglob string, $input must also be a fileglob
145 string. Anything else is an error.
146
147 If the $output parameter is any other type, "undef" will be returned.
148
149 Notes
150
151 When $input maps to multiple compressed files/buffers and $output is a
152 single file/buffer, after uncompression $output will contain a concate‐
153 nation of all the uncompressed data from each of the input files/buf‐
154 fers.
155
156 Optional Parameters
157
158 Unless specified below, the optional parameters for "inflate", "OPTS",
159 are the same as those used with the OO interface defined in the "Con‐
160 structor Options" section below.
161
162 "AutoClose => 0⎪1"
163 This option applies to any input or output data streams to
164 "inflate" that are filehandles.
165
166 If "AutoClose" is specified, and the value is true, it will result
167 in all input and/or output filehandles being closed once "inflate"
168 has completed.
169
170 This parameter defaults to 0.
171
172 "BinModeOut => 0⎪1"
173 When writing to a file or filehandle, set "binmode" before writing
174 to the file.
175
176 Defaults to 0.
177
178 "Append => 0⎪1"
179 TODO
180
181 "MultiStream => 0⎪1"
182 If the input file/buffer contains multiple compressed data
183 streams, this option will uncompress the whole lot as a single
184 data stream.
185
186 Defaults to 0.
187
188 "TrailingData => $scalar"
189 Returns the data, if any, that is present immediately after the
190 compressed data stream once uncompression is complete.
191
192 This option can be used when there is useful information immedi‐
193 ately following the compressed data stream, and you don't know the
194 length of the compressed data stream.
195
196 If the input is a buffer, "trailingData" will return everything
197 from the end of the compressed data stream to the end of the buf‐
198 fer.
199
200 If the input is a filehandle, "trailingData" will return the data
201 that is left in the filehandle input buffer once the end of the
202 compressed data stream has been reached. You can then use the
203 filehandle to read the rest of the input file.
204
205 Don't bother using "trailingData" if the input is a filename.
206
207 If you know the length of the compressed data stream before you
208 start uncompressing, you can avoid having to use "trailingData" by
209 setting the "InputLength" option.
210
211 Examples
212
213 To read the contents of the file "file1.txt.1950" and write the com‐
214 pressed data to the file "file1.txt".
215
216 use strict ;
217 use warnings ;
218 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
219
220 my $input = "file1.txt.1950";
221 my $output = "file1.txt";
222 inflate $input => $output
223 or die "inflate failed: $InflateError\n";
224
225 To read from an existing Perl filehandle, $input, and write the uncom‐
226 pressed data to a buffer, $buffer.
227
228 use strict ;
229 use warnings ;
230 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
231 use IO::File ;
232
233 my $input = new IO::File "<file1.txt.1950"
234 or die "Cannot open 'file1.txt.1950': $!\n" ;
235 my $buffer ;
236 inflate $input => \$buffer
237 or die "inflate failed: $InflateError\n";
238
239 To uncompress all files in the directory "/my/home" that match
240 "*.txt.1950" and store the compressed data in the same directory
241
242 use strict ;
243 use warnings ;
244 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
245
246 inflate '</my/home/*.txt.1950>' => '</my/home/#1.txt>'
247 or die "inflate failed: $InflateError\n";
248
249 and if you want to compress each file one at a time, this will do the
250 trick
251
252 use strict ;
253 use warnings ;
254 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
255
256 for my $input ( glob "/my/home/*.txt.1950" )
257 {
258 my $output = $input;
259 $output =~ s/.1950// ;
260 inflate $input => $output
261 or die "Error compressing '$input': $InflateError\n";
262 }
263
265 Constructor
266
267 The format of the constructor for IO::Uncompress::Inflate is shown
268 below
269
270 my $z = new IO::Uncompress::Inflate $input [OPTS]
271 or die "IO::Uncompress::Inflate failed: $InflateError\n";
272
273 Returns an "IO::Uncompress::Inflate" object on success and undef on
274 failure. The variable $InflateError will contain an error message on
275 failure.
276
277 If you are running Perl 5.005 or better the object, $z, returned from
278 IO::Uncompress::Inflate can be used exactly like an IO::File filehan‐
279 dle. This means that all normal input file operations can be carried
280 out with $z. For example, to read a line from a compressed file/buffer
281 you can use either of these forms
282
283 $line = $z->getline();
284 $line = <$z>;
285
286 The mandatory parameter $input is used to determine the source of the
287 compressed data. This parameter can take one of three forms.
288
289 A filename
290 If the $input parameter is a scalar, it is assumed to be a file‐
291 name. This file will be opened for reading and the compressed data
292 will be read from it.
293
294 A filehandle
295 If the $input parameter is a filehandle, the compressed data will
296 be read from it. The string '-' can be used as an alias for stan‐
297 dard input.
298
299 A scalar reference
300 If $input is a scalar reference, the compressed data will be read
301 from $$output.
302
303 Constructor Options
304
305 The option names defined below are case insensitive and can be option‐
306 ally prefixed by a '-'. So all of the following are valid
307
308 -AutoClose
309 -autoclose
310 AUTOCLOSE
311 autoclose
312
313 OPTS is a combination of the following options:
314
315 "AutoClose => 0⎪1"
316 This option is only valid when the $input parameter is a filehan‐
317 dle. If specified, and the value is true, it will result in the
318 file being closed once either the "close" method is called or the
319 IO::Uncompress::Inflate object is destroyed.
320
321 This parameter defaults to 0.
322
323 "MultiStream => 0⎪1"
324 Allows multiple concatenated compressed streams to be treated as a
325 single compressed stream. Decompression will stop once either the
326 end of the file/buffer is reached, an error is encountered (prema‐
327 ture eof, corrupt compressed data) or the end of a stream is not
328 immediately followed by the start of another stream.
329
330 This parameter defaults to 0.
331
332 "Prime => $string"
333 This option will uncompress the contents of $string before pro‐
334 cessing the input file/buffer.
335
336 This option can be useful when the compressed data is embedded in
337 another file/data structure and it is not possible to work out
338 where the compressed data begins without having to read the first
339 few bytes. If this is the case, the uncompression can be primed
340 with these bytes using this option.
341
342 "Transparent => 0⎪1"
343 If this option is set and the input file/buffer is not compressed
344 data, the module will allow reading of it anyway.
345
346 In addition, if the input file/buffer does contain compressed data
347 and there is non-compressed data immediately following it, setting
348 this option will make this module treat the whole file/bufffer as
349 a single data stream.
350
351 This option defaults to 1.
352
353 "BlockSize => $num"
354 When reading the compressed input data, IO::Uncompress::Inflate
355 will read it in blocks of $num bytes.
356
357 This option defaults to 4096.
358
359 "InputLength => $size"
360 When present this option will limit the number of compressed bytes
361 read from the input file/buffer to $size. This option can be used
362 in the situation where there is useful data directly after the
363 compressed data stream and you know beforehand the exact length of
364 the compressed data stream.
365
366 This option is mostly used when reading from a filehandle, in
367 which case the file pointer will be left pointing to the first
368 byte directly after the compressed data stream.
369
370 This option defaults to off.
371
372 "Append => 0⎪1"
373 This option controls what the "read" method does with uncompressed
374 data.
375
376 If set to 1, all uncompressed data will be appended to the output
377 parameter of the "read" method.
378
379 If set to 0, the contents of the output parameter of the "read"
380 method will be overwritten by the uncompressed data.
381
382 Defaults to 0.
383
384 "Strict => 0⎪1"
385 This option controls whether the extra checks defined below are
386 used when carrying out the decompression. When Strict is on, the
387 extra tests are carried out, when Strict is off they are not.
388
389 The default for this option is off.
390
391 1 The ADLER32 checksum field must be present.
392
393 2 The value of the ADLER32 field read must match the adler32
394 value of the uncompressed data actually contained in the
395 file.
396
397 Examples
398
399 TODO
400
402 read
403
404 Usage is
405
406 $status = $z->read($buffer)
407
408 Reads a block of compressed data (the size the the compressed block is
409 determined by the "Buffer" option in the constructor), uncompresses it
410 and writes any uncompressed data into $buffer. If the "Append" parame‐
411 ter is set in the constructor, the uncompressed data will be appended
412 to the $buffer parameter. Otherwise $buffer will be overwritten.
413
414 Returns the number of uncompressed bytes written to $buffer, zero if
415 eof or a negative number on error.
416
417 read
418
419 Usage is
420
421 $status = $z->read($buffer, $length)
422 $status = $z->read($buffer, $length, $offset)
423
424 $status = read($z, $buffer, $length)
425 $status = read($z, $buffer, $length, $offset)
426
427 Attempt to read $length bytes of uncompressed data into $buffer.
428
429 The main difference between this form of the "read" method and the pre‐
430 vious one, is that this one will attempt to return exactly $length
431 bytes. The only circumstances that this function will not is if end-of-
432 file or an IO error is encountered.
433
434 Returns the number of uncompressed bytes written to $buffer, zero if
435 eof or a negative number on error.
436
437 getline
438
439 Usage is
440
441 $line = $z->getline()
442 $line = <$z>
443
444 Reads a single line.
445
446 This method fully supports the use of of the variable $/ (or
447 $INPUT_RECORD_SEPARATOR or $RS when "English" is in use) to determine
448 what constitutes an end of line. Paragraph mode, record mode and file
449 slurp mode are all supported.
450
451 getc
452
453 Usage is
454
455 $char = $z->getc()
456
457 Read a single character.
458
459 ungetc
460
461 Usage is
462
463 $char = $z->ungetc($string)
464
465 inflateSync
466
467 Usage is
468
469 $status = $z->inflateSync()
470
471 TODO
472
473 getHeaderInfo
474
475 Usage is
476
477 $hdr = $z->getHeaderInfo();
478 @hdrs = $z->getHeaderInfo();
479
480 This method returns either a hash reference (in scalar context) or a
481 list or hash references (in array context) that contains information
482 about each of the header fields in the compressed data stream(s).
483
484 tell
485
486 Usage is
487
488 $z->tell()
489 tell $z
490
491 Returns the uncompressed file offset.
492
493 eof
494
495 Usage is
496
497 $z->eof();
498 eof($z);
499
500 Returns true if the end of the compressed input stream has been
501 reached.
502
503 seek
504
505 $z->seek($position, $whence);
506 seek($z, $position, $whence);
507
508 Provides a sub-set of the "seek" functionality, with the restriction
509 that it is only legal to seek forward in the input file/buffer. It is
510 a fatal error to attempt to seek backward.
511
512 The $whence parameter takes one the usual values, namely SEEK_SET,
513 SEEK_CUR or SEEK_END.
514
515 Returns 1 on success, 0 on failure.
516
517 binmode
518
519 Usage is
520
521 $z->binmode
522 binmode $z ;
523
524 This is a noop provided for completeness.
525
526 opened
527
528 $z->opened()
529
530 Returns true if the object currently refers to a opened file/buffer.
531
532 autoflush
533
534 my $prev = $z->autoflush()
535 my $prev = $z->autoflush(EXPR)
536
537 If the $z object is associated with a file or a filehandle, this method
538 returns the current autoflush setting for the underlying filehandle. If
539 "EXPR" is present, and is non-zero, it will enable flushing after every
540 write/print operation.
541
542 If $z is associated with a buffer, this method has no effect and always
543 returns "undef".
544
545 Note that the special variable $⎪ cannot be used to set or retrieve the
546 autoflush setting.
547
548 input_line_number
549
550 $z->input_line_number()
551 $z->input_line_number(EXPR)
552
553 Returns the current uncompressed line number. If "EXPR" is present it
554 has the effect of setting the line number. Note that setting the line
555 number does not change the current position within the file/buffer
556 being read.
557
558 The contents of $/ are used to to determine what constitutes a line
559 terminator.
560
561 fileno
562
563 $z->fileno()
564 fileno($z)
565
566 If the $z object is associated with a file or a filehandle, this method
567 will return the underlying file descriptor.
568
569 If the $z object is is associated with a buffer, this method will
570 return undef.
571
572 close
573
574 $z->close() ;
575 close $z ;
576
577 Closes the output file/buffer.
578
579 For most versions of Perl this method will be automatically invoked if
580 the IO::Uncompress::Inflate object is destroyed (either explicitly or
581 by the variable with the reference to the object going out of scope).
582 The exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
583 these cases, the "close" method will be called automatically, but not
584 until global destruction of all live objects when the program is termi‐
585 nating.
586
587 Therefore, if you want your scripts to be able to run on all versions
588 of Perl, you should call "close" explicitly and not rely on automatic
589 closing.
590
591 Returns true on success, otherwise 0.
592
593 If the "AutoClose" option has been enabled when the IO::Uncom‐
594 press::Inflate object was created, and the object is associated with a
595 file, the underlying file will also be closed.
596
597 nextStream
598
599 Usage is
600
601 my $status = $z->nextStream();
602
603 Skips to the next compressed data stream in the input file/buffer. If a
604 new compressed data stream is found, the eof marker will be cleared and
605 $. will be reset to 0.
606
607 Returns 1 if a new stream was found, 0 if none was found, and -1 if an
608 error was encountered.
609
610 trailingData
611
612 Usage is
613
614 my $data = $z->trailingData();
615
616 Returns the data, if any, that is present immediately after the com‐
617 pressed data stream once uncompression is complete. It only makes sense
618 to call this method once the end of the compressed data stream has been
619 encountered.
620
621 This option can be used when there is useful information immediately
622 following the compressed data stream, and you don't know the length of
623 the compressed data stream.
624
625 If the input is a buffer, "trailingData" will return everything from
626 the end of the compressed data stream to the end of the buffer.
627
628 If the input is a filehandle, "trailingData" will return the data that
629 is left in the filehandle input buffer once the end of the compressed
630 data stream has been reached. You can then use the filehandle to read
631 the rest of the input file.
632
633 Don't bother using "trailingData" if the input is a filename.
634
635 If you know the length of the compressed data stream before you start
636 uncompressing, you can avoid having to use "trailingData" by setting
637 the "InputLength" option in the constructor.
638
640 No symbolic constants are required by this IO::Uncompress::Inflate at
641 present.
642
643 :all Imports "inflate" and $InflateError. Same as doing this
644
645 use IO::Uncompress::Inflate qw(inflate $InflateError) ;
646
649 Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Com‐
650 press::Deflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate,
651 IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzop,
652 IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf,
653 IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress
654
655 Compress::Zlib::FAQ
656
657 File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
658
659 For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html,
660 http://www.faqs.org/rfcs/rfc1951.html and
661 http://www.faqs.org/rfcs/rfc1952.html
662
663 The zlib compression library was written by Jean-loup Gailly
664 gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
665
666 The primary site for the zlib compression library is
667 http://www.zlib.org.
668
669 The primary site for gzip is http://www.gzip.org.
670
672 This module was written by Paul Marquess, pmqs@cpan.org.
673
675 See the Changes file.
676
678 Copyright (c) 2005-2007 Paul Marquess. All rights reserved.
679
680 This program is free software; you can redistribute it and/or modify it
681 under the same terms as Perl itself.
682
683
684
685perl v5.8.8 2007-06-18 IO::Uncompress::Inflate(3)