1IO::Uncompress::RawInflaPteer(l3pPmr)ogrammers ReferencIeO:G:uUindceompress::RawInflate(3pm)
2
3
4

NAME

6       IO::Uncompress::RawInflate - Read RFC 1951 files/buffers
7

SYNOPSIS

9           use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
10
11           my $status = rawinflate $input => $output [,OPTS]
12               or die "rawinflate failed: $RawInflateError\n";
13
14           my $z = new IO::Uncompress::RawInflate $input [OPTS]
15               or die "rawinflate failed: $RawInflateError\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           $RawInflateError ;
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

DESCRIPTION

53       This module provides a Perl interface that allows the reading of
54       files/buffers that conform to RFC 1951.
55
56       For writing RFC 1951 files/buffers, see the companion module
57       IO::Compress::RawDeflate.
58

Functional Interface

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

OO Interface

297   Constructor
298       The format of the constructor for IO::Uncompress::RawInflate is shown
299       below
300
301           my $z = new IO::Uncompress::RawInflate $input [OPTS]
302               or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
303
304       Returns an "IO::Uncompress::RawInflate" object on success and undef on
305       failure.  The variable $RawInflateError will contain an error message
306       on failure.
307
308       If you are running Perl 5.005 or better the object, $z, returned from
309       IO::Uncompress::RawInflate can be used exactly like an IO::File
310       filehandle.  This means that all normal input file operations can be
311       carried out with $z.  For example, to read a line from a compressed
312       file/buffer you can use either of these forms
313
314           $line = $z->getline();
315           $line = <$z>;
316
317       The mandatory parameter $input is used to determine the source of the
318       compressed data. This parameter can take one of three forms.
319
320       A filename
321            If the $input parameter is a scalar, it is assumed to be a
322            filename. This file will be opened for reading and the compressed
323            data will be read from it.
324
325       A filehandle
326            If the $input parameter is a filehandle, the compressed data will
327            be read from it.  The string '-' can be used as an alias for
328            standard input.
329
330       A scalar reference
331            If $input is a scalar reference, the compressed data will be read
332            from $$output.
333
334   Constructor Options
335       The option names defined below are case insensitive and can be
336       optionally prefixed by a '-'.  So all of the following are valid
337
338           -AutoClose
339           -autoclose
340           AUTOCLOSE
341           autoclose
342
343       OPTS is a combination of the following options:
344
345       "AutoClose => 0|1"
346            This option is only valid when the $input parameter is a
347            filehandle. If specified, and the value is true, it will result in
348            the file being closed once either the "close" method is called or
349            the IO::Uncompress::RawInflate object is destroyed.
350
351            This parameter defaults to 0.
352
353       "MultiStream => 0|1"
354            Allows multiple concatenated compressed streams to be treated as a
355            single compressed stream. Decompression will stop once either the
356            end of the file/buffer is reached, an error is encountered
357            (premature eof, corrupt compressed data) or the end of a stream is
358            not immediately followed by the start of another stream.
359
360            This parameter defaults to 0.
361
362       "Prime => $string"
363            This option will uncompress the contents of $string before
364            processing the input file/buffer.
365
366            This option can be useful when the compressed data is embedded in
367            another file/data structure and it is not possible to work out
368            where the compressed data begins without having to read the first
369            few bytes. If this is the case, the uncompression can be primed
370            with these bytes using this option.
371
372       "Transparent => 0|1"
373            If this option is set and the input file/buffer is not compressed
374            data, the module will allow reading of it anyway.
375
376            In addition, if the input file/buffer does contain compressed data
377            and there is non-compressed data immediately following it, setting
378            this option will make this module treat the whole file/bufffer as
379            a single data stream.
380
381            This option defaults to 1.
382
383       "BlockSize => $num"
384            When reading the compressed input data, IO::Uncompress::RawInflate
385            will read it in blocks of $num bytes.
386
387            This option defaults to 4096.
388
389       "InputLength => $size"
390            When present this option will limit the number of compressed bytes
391            read from the input file/buffer to $size. This option can be used
392            in the situation where there is useful data directly after the
393            compressed data stream and you know beforehand the exact length of
394            the compressed data stream.
395
396            This option is mostly used when reading from a filehandle, in
397            which case the file pointer will be left pointing to the first
398            byte directly after the compressed data stream.
399
400            This option defaults to off.
401
402       "Append => 0|1"
403            This option controls what the "read" method does with uncompressed
404            data.
405
406            If set to 1, all uncompressed data will be appended to the output
407            parameter of the "read" method.
408
409            If set to 0, the contents of the output parameter of the "read"
410            method will be overwritten by the uncompressed data.
411
412            Defaults to 0.
413
414       "Strict => 0|1"
415            This option is a no-op.
416
417   Examples
418       TODO
419

Methods

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

Importing

643       No symbolic constants are required by this IO::Uncompress::RawInflate
644       at present.
645
646       :all Imports "rawinflate" and $RawInflateError.  Same as doing this
647
648                use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
649

EXAMPLES

651   Working with Net::FTP
652       See IO::Uncompress::RawInflate::FAQ
653

SEE ALSO

655       Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip,
656       IO::Compress::Deflate, IO::Uncompress::Inflate,
657       IO::Compress::RawDeflate, IO::Compress::Bzip2, IO::Uncompress::Bunzip2,
658       IO::Compress::Lzma, IO::Uncompress::UnLzma, IO::Compress::Xz,
659       IO::Uncompress::UnXz, IO::Compress::Lzop, IO::Uncompress::UnLzop,
660       IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Uncompress::AnyInflate,
661       IO::Uncompress::AnyUncompress
662
663       Compress::Zlib::FAQ
664
665       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
666
667       For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html,
668       http://www.faqs.org/rfcs/rfc1951.html and
669       http://www.faqs.org/rfcs/rfc1952.html
670
671       The zlib compression library was written by Jean-loup Gailly
672       gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
673
674       The primary site for the zlib compression library is
675       http://www.zlib.org.
676
677       The primary site for gzip is http://www.gzip.org.
678

AUTHOR

680       This module was written by Paul Marquess, pmqs@cpan.org.
681

MODIFICATION HISTORY

683       See the Changes file.
684
686       Copyright (c) 2005-2010 Paul Marquess. All rights reserved.
687
688       This program is free software; you can redistribute it and/or modify it
689       under the same terms as Perl itself.
690
691
692
693perl v5.12.4                      2011-06-07   IO::Uncompress::RawInflate(3pm)
Impressum