1IO::Uncompress::AnyInflUasteer(3C)ontributed Perl DocumeInOt:a:tUinocnompress::AnyInflate(3)
2
3
4

NAME

6       IO::Uncompress::AnyInflate - Uncompress zlib-based (zip, gzip)
7       file/buffer
8

SYNOPSIS

10           use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
11
12           my $status = anyinflate $input => $output [,OPTS]
13               or die "anyinflate failed: $AnyInflateError\n";
14
15           my $z = new IO::Uncompress::AnyInflate $input [OPTS]
16               or die "anyinflate failed: $AnyInflateError\n";
17
18           $status = $z->read($buffer)
19           $status = $z->read($buffer, $length)
20           $status = $z->read($buffer, $length, $offset)
21           $line = $z->getline()
22           $char = $z->getc()
23           $char = $z->ungetc()
24           $char = $z->opened()
25
26           $status = $z->inflateSync()
27
28           $data = $z->trailingData()
29           $status = $z->nextStream()
30           $data = $z->getHeaderInfo()
31           $z->tell()
32           $z->seek($position, $whence)
33           $z->binmode()
34           $z->fileno()
35           $z->eof()
36           $z->close()
37
38           $AnyInflateError ;
39
40           # IO::File mode
41
42           <$z>
43           read($z, $buffer);
44           read($z, $buffer, $length);
45           read($z, $buffer, $length, $offset);
46           tell($z)
47           seek($z, $position, $whence)
48           binmode($z)
49           fileno($z)
50           eof($z)
51           close($z)
52

DESCRIPTION

54       This module provides a Perl interface that allows the reading of
55       files/buffers that have been compressed in a number of formats that use
56       the zlib compression library.
57
58       The formats supported are
59
60       RFC 1950
61       RFC 1951 (optionally)
62       gzip (RFC 1952)
63       zip
64
65       The module will auto-detect which, if any, of the supported compression
66       formats is being used.
67

Functional Interface

69       A top-level function, "anyinflate", is provided to carry out "one-shot"
70       uncompression between buffers and/or files. For finer control over the
71       uncompression process, see the "OO Interface" section.
72
73           use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
74
75           anyinflate $input => $output [,OPTS]
76               or die "anyinflate failed: $AnyInflateError\n";
77
78       The functional interface needs Perl5.005 or better.
79
80       anyinflate $input => $output [, OPTS]
81
82       "anyinflate" expects at least two parameters, $input and $output.
83
84       The $input parameter
85
86       The parameter, $input, is used to define the source of the compressed
87       data.
88
89       It can take one of the following forms:
90
91       A filename
92            If the $input parameter is a simple scalar, it is assumed to be a
93            filename. This file will be opened for reading and the input data
94            will be read from it.
95
96       A filehandle
97            If the $input parameter is a filehandle, the input data will be
98            read from it.  The string '-' can be used as an alias for standard
99            input.
100
101       A scalar reference
102            If $input is a scalar reference, the input data will be read from
103            $$input.
104
105       An array reference
106            If $input is an array reference, each element in the array must be
107            a filename.
108
109            The input data will be read from each file in turn.
110
111            The complete array will be walked to ensure that it only contains
112            valid filenames before any data is uncompressed.
113
114       An Input FileGlob string
115            If $input is a string that is delimited by the characters "<" and
116            ">" "anyinflate" will assume that it is an input fileglob string.
117            The input is the list of files that match the fileglob.
118
119            If the fileglob does not match any files ...
120
121            See File::GlobMapper for more details.
122
123       If the $input parameter is any other type, "undef" will be returned.
124
125       The $output parameter
126
127       The parameter $output is used to control the destination of the uncom‐
128       pressed data. This parameter can take one of these forms.
129
130       A filename
131            If the $output parameter is a simple scalar, it is assumed to be a
132            filename.  This file will be opened for writing and the uncom‐
133            pressed data will be written to it.
134
135       A filehandle
136            If the $output parameter is a filehandle, the uncompressed data
137            will be written to it.  The string '-' can be used as an alias for
138            standard output.
139
140       A scalar reference
141            If $output is a scalar reference, the uncompressed data will be
142            stored in $$output.
143
144       An Array Reference
145            If $output is an array reference, the uncompressed data will be
146            pushed onto the array.
147
148       An Output FileGlob
149            If $output is a string that is delimited by the characters "<" and
150            ">" "anyinflate" will assume that it is an output fileglob string.
151            The output is the list of files that match the fileglob.
152
153            When $output is an fileglob string, $input must also be a fileglob
154            string. Anything else is an error.
155
156       If the $output parameter is any other type, "undef" will be returned.
157
158       Notes
159
160       When $input maps to multiple compressed files/buffers and $output is a
161       single file/buffer, after uncompression $output will contain a concate‐
162       nation of all the uncompressed data from each of the input files/buf‐
163       fers.
164
165       Optional Parameters
166
167       Unless specified below, the optional parameters for "anyinflate",
168       "OPTS", are the same as those used with the OO interface defined in the
169       "Constructor Options" section below.
170
171       "AutoClose => 0⎪1"
172            This option applies to any input or output data streams to "anyin‐
173            flate" that are filehandles.
174
175            If "AutoClose" is specified, and the value is true, it will result
176            in all input and/or output filehandles being closed once "anyin‐
177            flate" has completed.
178
179            This parameter defaults to 0.
180
181       "BinModeOut => 0⎪1"
182            When writing to a file or filehandle, set "binmode" before writing
183            to the file.
184
185            Defaults to 0.
186
187       "Append => 0⎪1"
188            TODO
189
190       "MultiStream => 0⎪1"
191            If the input file/buffer contains multiple compressed data
192            streams, this option will uncompress the whole lot as a single
193            data stream.
194
195            Defaults to 0.
196
197       "TrailingData => $scalar"
198            Returns the data, if any, that is present immediately after the
199            compressed data stream once uncompression is complete.
200
201            This option can be used when there is useful information immedi‐
202            ately following the compressed data stream, and you don't know the
203            length of the compressed data stream.
204
205            If the input is a buffer, "trailingData" will return everything
206            from the end of the compressed data stream to the end of the buf‐
207            fer.
208
209            If the input is a filehandle, "trailingData" will return the data
210            that is left in the filehandle input buffer once the end of the
211            compressed data stream has been reached. You can then use the
212            filehandle to read the rest of the input file.
213
214            Don't bother using "trailingData" if the input is a filename.
215
216            If you know the length of the compressed data stream before you
217            start uncompressing, you can avoid having to use "trailingData" by
218            setting the "InputLength" option.
219
220       Examples
221
222       To read the contents of the file "file1.txt.Compressed" and write the
223       compressed data to the file "file1.txt".
224
225           use strict ;
226           use warnings ;
227           use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
228
229           my $input = "file1.txt.Compressed";
230           my $output = "file1.txt";
231           anyinflate $input => $output
232               or die "anyinflate failed: $AnyInflateError\n";
233
234       To read from an existing Perl filehandle, $input, and write the uncom‐
235       pressed data to a buffer, $buffer.
236
237           use strict ;
238           use warnings ;
239           use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
240           use IO::File ;
241
242           my $input = new IO::File "<file1.txt.Compressed"
243               or die "Cannot open 'file1.txt.Compressed': $!\n" ;
244           my $buffer ;
245           anyinflate $input => \$buffer
246               or die "anyinflate failed: $AnyInflateError\n";
247
248       To uncompress all files in the directory "/my/home" that match
249       "*.txt.Compressed" and store the compressed data in the same directory
250
251           use strict ;
252           use warnings ;
253           use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
254
255           anyinflate '</my/home/*.txt.Compressed>' => '</my/home/#1.txt>'
256               or die "anyinflate failed: $AnyInflateError\n";
257
258       and if you want to compress each file one at a time, this will do the
259       trick
260
261           use strict ;
262           use warnings ;
263           use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
264
265           for my $input ( glob "/my/home/*.txt.Compressed" )
266           {
267               my $output = $input;
268               $output =~ s/.Compressed// ;
269               anyinflate $input => $output
270                   or die "Error compressing '$input': $AnyInflateError\n";
271           }
272

OO Interface

274       Constructor
275
276       The format of the constructor for IO::Uncompress::AnyInflate is shown
277       below
278
279           my $z = new IO::Uncompress::AnyInflate $input [OPTS]
280               or die "IO::Uncompress::AnyInflate failed: $AnyInflateError\n";
281
282       Returns an "IO::Uncompress::AnyInflate" object on success and undef on
283       failure.  The variable $AnyInflateError will contain an error message
284       on failure.
285
286       If you are running Perl 5.005 or better the object, $z, returned from
287       IO::Uncompress::AnyInflate can be used exactly like an IO::File file‐
288       handle.  This means that all normal input file operations can be car‐
289       ried out with $z.  For example, to read a line from a compressed
290       file/buffer you can use either of these forms
291
292           $line = $z->getline();
293           $line = <$z>;
294
295       The mandatory parameter $input is used to determine the source of the
296       compressed data. This parameter can take one of three forms.
297
298       A filename
299            If the $input parameter is a scalar, it is assumed to be a file‐
300            name. This file will be opened for reading and the compressed data
301            will be read from it.
302
303       A filehandle
304            If the $input parameter is a filehandle, the compressed data will
305            be read from it.  The string '-' can be used as an alias for stan‐
306            dard input.
307
308       A scalar reference
309            If $input is a scalar reference, the compressed data will be read
310            from $$output.
311
312       Constructor Options
313
314       The option names defined below are case insensitive and can be option‐
315       ally prefixed by a '-'.  So all of the following are valid
316
317           -AutoClose
318           -autoclose
319           AUTOCLOSE
320           autoclose
321
322       OPTS is a combination of the following options:
323
324       "AutoClose => 0⎪1"
325            This option is only valid when the $input parameter is a filehan‐
326            dle. If specified, and the value is true, it will result in the
327            file being closed once either the "close" method is called or the
328            IO::Uncompress::AnyInflate object is destroyed.
329
330            This parameter defaults to 0.
331
332       "MultiStream => 0⎪1"
333            Allows multiple concatenated compressed streams to be treated as a
334            single compressed stream. Decompression will stop once either the
335            end of the file/buffer is reached, an error is encountered (prema‐
336            ture eof, corrupt compressed data) or the end of a stream is not
337            immediately followed by the start of another stream.
338
339            This parameter defaults to 0.
340
341       "Prime => $string"
342            This option will uncompress the contents of $string before pro‐
343            cessing the input file/buffer.
344
345            This option can be useful when the compressed data is embedded in
346            another file/data structure and it is not possible to work out
347            where the compressed data begins without having to read the first
348            few bytes. If this is the case, the uncompression can be primed
349            with these bytes using this option.
350
351       "Transparent => 0⎪1"
352            If this option is set and the input file/buffer is not compressed
353            data, the module will allow reading of it anyway.
354
355            In addition, if the input file/buffer does contain compressed data
356            and there is non-compressed data immediately following it, setting
357            this option will make this module treat the whole file/bufffer as
358            a single data stream.
359
360            This option defaults to 1.
361
362       "BlockSize => $num"
363            When reading the compressed input data, IO::Uncompress::AnyInflate
364            will read it in blocks of $num bytes.
365
366            This option defaults to 4096.
367
368       "InputLength => $size"
369            When present this option will limit the number of compressed bytes
370            read from the input file/buffer to $size. This option can be used
371            in the situation where there is useful data directly after the
372            compressed data stream and you know beforehand the exact length of
373            the compressed data stream.
374
375            This option is mostly used when reading from a filehandle, in
376            which case the file pointer will be left pointing to the first
377            byte directly after the compressed data stream.
378
379            This option defaults to off.
380
381       "Append => 0⎪1"
382            This option controls what the "read" method does with uncompressed
383            data.
384
385            If set to 1, all uncompressed data will be appended to the output
386            parameter of the "read" method.
387
388            If set to 0, the contents of the output parameter of the "read"
389            method will be overwritten by the uncompressed data.
390
391            Defaults to 0.
392
393       "Strict => 0⎪1"
394            This option controls whether the extra checks defined below are
395            used when carrying out the decompression. When Strict is on, the
396            extra tests are carried out, when Strict is off they are not.
397
398            The default for this option is off.
399
400            If the input is an RFC 1950 data stream, the following will be
401            checked:
402
403            1    The ADLER32 checksum field must be present.
404
405            2    The value of the ADLER32 field read must match the adler32
406                 value of the uncompressed data actually contained in the
407                 file.
408
409            If the input is a gzip (RFC 1952) data stream, the following will
410            be checked:
411
412            1    If the FHCRC bit is set in the gzip FLG header byte, the
413                 CRC16 bytes in the header must match the crc16 value of the
414                 gzip header actually read.
415
416            2    If the gzip header contains a name field (FNAME) it consists
417                 solely of ISO 8859-1 characters.
418
419            3    If the gzip header contains a comment field (FCOMMENT) it
420                 consists solely of ISO 8859-1 characters plus line-feed.
421
422            4    If the gzip FEXTRA header field is present it must conform to
423                 the sub-field structure as defined in RFC 1952.
424
425            5    The CRC32 and ISIZE trailer fields must be present.
426
427            6    The value of the CRC32 field read must match the crc32 value
428                 of the uncompressed data actually contained in the gzip file.
429
430            7    The value of the ISIZE fields read must match the length of
431                 the uncompressed data actually read from the file.
432
433       "RawInflate => 0⎪1"
434            When auto-detecting the compressed format, try to test for raw-
435            deflate (RFC 1951) content using the "IO::Uncompress::RawInflate"
436            module.
437
438            The reason this is not default behaviour is because RFC 1951 con‐
439            tent can only be detected by attempting to uncompress it. This
440            process is error prone and can result is false positives.
441
442            Defaults to 0.
443
444       "ParseExtra => 0⎪1" If the gzip FEXTRA header field is present and this
445       option is set, it will force the module to check that it conforms to
446       the sub-field structure as defined in RFC 1952.
447            If the "Strict" is on it will automatically enable this option.
448
449            Defaults to 0.
450
451       Examples
452
453       TODO
454

Methods

456       read
457
458       Usage is
459
460           $status = $z->read($buffer)
461
462       Reads a block of compressed data (the size the the compressed block is
463       determined by the "Buffer" option in the constructor), uncompresses it
464       and writes any uncompressed data into $buffer. If the "Append" parame‐
465       ter is set in the constructor, the uncompressed data will be appended
466       to the $buffer parameter. Otherwise $buffer will be overwritten.
467
468       Returns the number of uncompressed bytes written to $buffer, zero if
469       eof or a negative number on error.
470
471       read
472
473       Usage is
474
475           $status = $z->read($buffer, $length)
476           $status = $z->read($buffer, $length, $offset)
477
478           $status = read($z, $buffer, $length)
479           $status = read($z, $buffer, $length, $offset)
480
481       Attempt to read $length bytes of uncompressed data into $buffer.
482
483       The main difference between this form of the "read" method and the pre‐
484       vious one, is that this one will attempt to return exactly $length
485       bytes. The only circumstances that this function will not is if end-of-
486       file or an IO error is encountered.
487
488       Returns the number of uncompressed bytes written to $buffer, zero if
489       eof or a negative number on error.
490
491       getline
492
493       Usage is
494
495           $line = $z->getline()
496           $line = <$z>
497
498       Reads a single line.
499
500       This method fully supports the use of of the variable $/ (or
501       $INPUT_RECORD_SEPARATOR or $RS when "English" is in use) to determine
502       what constitutes an end of line. Paragraph mode, record mode and file
503       slurp mode are all supported.
504
505       getc
506
507       Usage is
508
509           $char = $z->getc()
510
511       Read a single character.
512
513       ungetc
514
515       Usage is
516
517           $char = $z->ungetc($string)
518
519       inflateSync
520
521       Usage is
522
523           $status = $z->inflateSync()
524
525       TODO
526
527       getHeaderInfo
528
529       Usage is
530
531           $hdr  = $z->getHeaderInfo();
532           @hdrs = $z->getHeaderInfo();
533
534       This method returns either a hash reference (in scalar context) or a
535       list or hash references (in array context) that contains information
536       about each of the header fields in the compressed data stream(s).
537
538       tell
539
540       Usage is
541
542           $z->tell()
543           tell $z
544
545       Returns the uncompressed file offset.
546
547       eof
548
549       Usage is
550
551           $z->eof();
552           eof($z);
553
554       Returns true if the end of the compressed input stream has been
555       reached.
556
557       seek
558
559           $z->seek($position, $whence);
560           seek($z, $position, $whence);
561
562       Provides a sub-set of the "seek" functionality, with the restriction
563       that it is only legal to seek forward in the input file/buffer.  It is
564       a fatal error to attempt to seek backward.
565
566       The $whence parameter takes one the usual values, namely SEEK_SET,
567       SEEK_CUR or SEEK_END.
568
569       Returns 1 on success, 0 on failure.
570
571       binmode
572
573       Usage is
574
575           $z->binmode
576           binmode $z ;
577
578       This is a noop provided for completeness.
579
580       opened
581
582           $z->opened()
583
584       Returns true if the object currently refers to a opened file/buffer.
585
586       autoflush
587
588           my $prev = $z->autoflush()
589           my $prev = $z->autoflush(EXPR)
590
591       If the $z object is associated with a file or a filehandle, this method
592       returns the current autoflush setting for the underlying filehandle. If
593       "EXPR" is present, and is non-zero, it will enable flushing after every
594       write/print operation.
595
596       If $z is associated with a buffer, this method has no effect and always
597       returns "undef".
598
599       Note that the special variable $⎪ cannot be used to set or retrieve the
600       autoflush setting.
601
602       input_line_number
603
604           $z->input_line_number()
605           $z->input_line_number(EXPR)
606
607       Returns the current uncompressed line number. If "EXPR" is present it
608       has the effect of setting the line number. Note that setting the line
609       number does not change the current position within the file/buffer
610       being read.
611
612       The contents of $/ are used to to determine what constitutes a line
613       terminator.
614
615       fileno
616
617           $z->fileno()
618           fileno($z)
619
620       If the $z object is associated with a file or a filehandle, this method
621       will return the underlying file descriptor.
622
623       If the $z object is is associated with a buffer, this method will
624       return undef.
625
626       close
627
628           $z->close() ;
629           close $z ;
630
631       Closes the output file/buffer.
632
633       For most versions of Perl this method will be automatically invoked if
634       the IO::Uncompress::AnyInflate object is destroyed (either explicitly
635       or by the variable with the reference to the object going out of
636       scope). The exceptions are Perl versions 5.005 through 5.00504 and
637       5.8.0. In these cases, the "close" method will be called automatically,
638       but not until global destruction of all live objects when the program
639       is terminating.
640
641       Therefore, if you want your scripts to be able to run on all versions
642       of Perl, you should call "close" explicitly and not rely on automatic
643       closing.
644
645       Returns true on success, otherwise 0.
646
647       If the "AutoClose" option has been enabled when the IO::Uncom‐
648       press::AnyInflate object was created, and the object is associated with
649       a file, the underlying file will also be closed.
650
651       nextStream
652
653       Usage is
654
655           my $status = $z->nextStream();
656
657       Skips to the next compressed data stream in the input file/buffer. If a
658       new compressed data stream is found, the eof marker will be cleared and
659       $.  will be reset to 0.
660
661       Returns 1 if a new stream was found, 0 if none was found, and -1 if an
662       error was encountered.
663
664       trailingData
665
666       Usage is
667
668           my $data = $z->trailingData();
669
670       Returns the data, if any, that is present immediately after the com‐
671       pressed data stream once uncompression is complete. It only makes sense
672       to call this method once the end of the compressed data stream has been
673       encountered.
674
675       This option can be used when there is useful information immediately
676       following the compressed data stream, and you don't know the length of
677       the compressed data stream.
678
679       If the input is a buffer, "trailingData" will return everything from
680       the end of the compressed data stream to the end of the buffer.
681
682       If the input is a filehandle, "trailingData" will return the data that
683       is left in the filehandle input buffer once the end of the compressed
684       data stream has been reached. You can then use the filehandle to read
685       the rest of the input file.
686
687       Don't bother using "trailingData" if the input is a filename.
688
689       If you know the length of the compressed data stream before you start
690       uncompressing, you can avoid having to use "trailingData" by setting
691       the "InputLength" option in the constructor.
692

Importing

694       No symbolic constants are required by this IO::Uncompress::AnyInflate
695       at present.
696
697       :all Imports "anyinflate" and $AnyInflateError.  Same as doing this
698
699                use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
700

EXAMPLES

SEE ALSO

703       Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Com‐
704       press::Deflate, IO::Uncompress::Inflate, IO::Compress::RawDeflate,
705       IO::Uncompress::RawInflate, IO::Compress::Bzip2, IO::Uncompress::Bun‐
706       zip2, IO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf,
707       IO::Uncompress::UnLzf, IO::Uncompress::AnyUncompress
708
709       Compress::Zlib::FAQ
710
711       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
712
713       For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html,
714       http://www.faqs.org/rfcs/rfc1951.html and
715       http://www.faqs.org/rfcs/rfc1952.html
716
717       The zlib compression library was written by Jean-loup Gailly
718       gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
719
720       The primary site for the zlib compression library is
721       http://www.zlib.org.
722
723       The primary site for gzip is http://www.gzip.org.
724

AUTHOR

726       This module was written by Paul Marquess, pmqs@cpan.org.
727

MODIFICATION HISTORY

729       See the Changes file.
730
732       Copyright (c) 2005-2007 Paul Marquess. All rights reserved.
733
734       This program is free software; you can redistribute it and/or modify it
735       under the same terms as Perl itself.
736
737
738
739perl v5.8.8                       2007-06-18     IO::Uncompress::AnyInflate(3)
Impressum