1IO::Uncompress::RawInflUasteer(3C)ontributed Perl DocumeInOt:a:tUinocnompress::RawInflate(3)
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 IO::Com‐
57       press::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
73       "rawinflate" 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            ">" "rawinflate" will assume that it is an input fileglob string.
108            The 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            ">" "rawinflate" 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 "rawinflate",
159       "OPTS", are the same as those used with the OO interface defined in the
160       "Constructor Options" section below.
161
162       "AutoClose => 0⎪1"
163            This option applies to any input or output data streams to "rawin‐
164            flate" 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 "rawin‐
168            flate" 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            This option is a no-op.
183
184       "TrailingData => $scalar"
185            Returns the data, if any, that is present immediately after the
186            compressed data stream once uncompression is complete.
187
188            This option can be used when there is useful information immedi‐
189            ately following the compressed data stream, and you don't know the
190            length of the compressed data stream.
191
192            If the input is a buffer, "trailingData" will return everything
193            from the end of the compressed data stream to the end of the buf‐
194            fer.
195
196            If the input is a filehandle, "trailingData" will return the data
197            that is left in the filehandle input buffer once the end of the
198            compressed data stream has been reached. You can then use the
199            filehandle to read the rest of the input file.
200
201            Don't bother using "trailingData" if the input is a filename.
202
203            If you know the length of the compressed data stream before you
204            start uncompressing, you can avoid having to use "trailingData" by
205            setting the "InputLength" option.
206
207       Examples
208
209       To read the contents of the file "file1.txt.1951" and write the com‐
210       pressed data to the file "file1.txt".
211
212           use strict ;
213           use warnings ;
214           use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
215
216           my $input = "file1.txt.1951";
217           my $output = "file1.txt";
218           rawinflate $input => $output
219               or die "rawinflate failed: $RawInflateError\n";
220
221       To read from an existing Perl filehandle, $input, and write the uncom‐
222       pressed data to a buffer, $buffer.
223
224           use strict ;
225           use warnings ;
226           use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
227           use IO::File ;
228
229           my $input = new IO::File "<file1.txt.1951"
230               or die "Cannot open 'file1.txt.1951': $!\n" ;
231           my $buffer ;
232           rawinflate $input => \$buffer
233               or die "rawinflate failed: $RawInflateError\n";
234
235       To uncompress all files in the directory "/my/home" that match
236       "*.txt.1951" and store the compressed data in the same directory
237
238           use strict ;
239           use warnings ;
240           use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
241
242           rawinflate '</my/home/*.txt.1951>' => '</my/home/#1.txt>'
243               or die "rawinflate failed: $RawInflateError\n";
244
245       and if you want to compress each file one at a time, this will do the
246       trick
247
248           use strict ;
249           use warnings ;
250           use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
251
252           for my $input ( glob "/my/home/*.txt.1951" )
253           {
254               my $output = $input;
255               $output =~ s/.1951// ;
256               rawinflate $input => $output
257                   or die "Error compressing '$input': $RawInflateError\n";
258           }
259

OO Interface

261       Constructor
262
263       The format of the constructor for IO::Uncompress::RawInflate is shown
264       below
265
266           my $z = new IO::Uncompress::RawInflate $input [OPTS]
267               or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
268
269       Returns an "IO::Uncompress::RawInflate" object on success and undef on
270       failure.  The variable $RawInflateError will contain an error message
271       on failure.
272
273       If you are running Perl 5.005 or better the object, $z, returned from
274       IO::Uncompress::RawInflate can be used exactly like an IO::File file‐
275       handle.  This means that all normal input file operations can be car‐
276       ried out with $z.  For example, to read a line from a compressed
277       file/buffer you can use either of these forms
278
279           $line = $z->getline();
280           $line = <$z>;
281
282       The mandatory parameter $input is used to determine the source of the
283       compressed data. This parameter can take one of three forms.
284
285       A filename
286            If the $input parameter is a scalar, it is assumed to be a file‐
287            name. This file will be opened for reading and the compressed data
288            will be read from it.
289
290       A filehandle
291            If the $input parameter is a filehandle, the compressed data will
292            be read from it.  The string '-' can be used as an alias for stan‐
293            dard input.
294
295       A scalar reference
296            If $input is a scalar reference, the compressed data will be read
297            from $$output.
298
299       Constructor Options
300
301       The option names defined below are case insensitive and can be option‐
302       ally prefixed by a '-'.  So all of the following are valid
303
304           -AutoClose
305           -autoclose
306           AUTOCLOSE
307           autoclose
308
309       OPTS is a combination of the following options:
310
311       "AutoClose => 0⎪1"
312            This option is only valid when the $input parameter is a filehan‐
313            dle. If specified, and the value is true, it will result in the
314            file being closed once either the "close" method is called or the
315            IO::Uncompress::RawInflate object is destroyed.
316
317            This parameter defaults to 0.
318
319       "MultiStream => 0⎪1"
320            Allows multiple concatenated compressed streams to be treated as a
321            single compressed stream. Decompression will stop once either the
322            end of the file/buffer is reached, an error is encountered (prema‐
323            ture eof, corrupt compressed data) or the end of a stream is not
324            immediately followed by the start of another stream.
325
326            This parameter defaults to 0.
327
328       "Prime => $string"
329            This option will uncompress the contents of $string before pro‐
330            cessing the input file/buffer.
331
332            This option can be useful when the compressed data is embedded in
333            another file/data structure and it is not possible to work out
334            where the compressed data begins without having to read the first
335            few bytes. If this is the case, the uncompression can be primed
336            with these bytes using this option.
337
338       "Transparent => 0⎪1"
339            If this option is set and the input file/buffer is not compressed
340            data, the module will allow reading of it anyway.
341
342            In addition, if the input file/buffer does contain compressed data
343            and there is non-compressed data immediately following it, setting
344            this option will make this module treat the whole file/bufffer as
345            a single data stream.
346
347            This option defaults to 1.
348
349       "BlockSize => $num"
350            When reading the compressed input data, IO::Uncompress::RawInflate
351            will read it in blocks of $num bytes.
352
353            This option defaults to 4096.
354
355       "InputLength => $size"
356            When present this option will limit the number of compressed bytes
357            read from the input file/buffer to $size. This option can be used
358            in the situation where there is useful data directly after the
359            compressed data stream and you know beforehand the exact length of
360            the compressed data stream.
361
362            This option is mostly used when reading from a filehandle, in
363            which case the file pointer will be left pointing to the first
364            byte directly after the compressed data stream.
365
366            This option defaults to off.
367
368       "Append => 0⎪1"
369            This option controls what the "read" method does with uncompressed
370            data.
371
372            If set to 1, all uncompressed data will be appended to the output
373            parameter of the "read" method.
374
375            If set to 0, the contents of the output parameter of the "read"
376            method will be overwritten by the uncompressed data.
377
378            Defaults to 0.
379
380       "Strict => 0⎪1"
381            This option is a no-op.
382
383       Examples
384
385       TODO
386

Methods

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

Importing

626       No symbolic constants are required by this IO::Uncompress::RawInflate
627       at present.
628
629       :all Imports "rawinflate" and $RawInflateError.  Same as doing this
630
631                use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
632

EXAMPLES

SEE ALSO

635       Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Com‐
636       press::Deflate, IO::Uncompress::Inflate, IO::Compress::RawDeflate,
637       IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzop,
638       IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf,
639       IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress
640
641       Compress::Zlib::FAQ
642
643       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
644
645       For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html,
646       http://www.faqs.org/rfcs/rfc1951.html and
647       http://www.faqs.org/rfcs/rfc1952.html
648
649       The zlib compression library was written by Jean-loup Gailly
650       gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
651
652       The primary site for the zlib compression library is
653       http://www.zlib.org.
654
655       The primary site for gzip is http://www.gzip.org.
656

AUTHOR

658       This module was written by Paul Marquess, pmqs@cpan.org.
659

MODIFICATION HISTORY

661       See the Changes file.
662
664       Copyright (c) 2005-2007 Paul Marquess. All rights reserved.
665
666       This program is free software; you can redistribute it and/or modify it
667       under the same terms as Perl itself.
668
669
670
671perl v5.8.8                       2007-06-18     IO::Uncompress::RawInflate(3)
Impressum