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

OO Interface

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

Methods

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

Importing

657       No symbolic constants are required by this IO::Uncompress::RawInflate
658       at present.
659
660       :all Imports "rawinflate" and $RawInflateError.  Same as doing this
661
662                use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
663

EXAMPLES

665   Working with Net::FTP
666       See IO::Compress::FAQ
667

SEE ALSO

669       Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip,
670       IO::Compress::Deflate, IO::Uncompress::Inflate,
671       IO::Compress::RawDeflate, IO::Compress::Bzip2, IO::Uncompress::Bunzip2,
672       IO::Compress::Lzma, IO::Uncompress::UnLzma, IO::Compress::Xz,
673       IO::Uncompress::UnXz, IO::Compress::Lzip, IO::Uncompress::UnLzip,
674       IO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf,
675       IO::Uncompress::UnLzf, IO::Compress::Zstd, IO::Uncompress::UnZstd,
676       IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress
677
678       IO::Compress::FAQ
679
680       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
681
682       For RFC 1950, 1951 and 1952 see
683       <http://www.faqs.org/rfcs/rfc1950.html>,
684       <http://www.faqs.org/rfcs/rfc1951.html> and
685       <http://www.faqs.org/rfcs/rfc1952.html>
686
687       The zlib compression library was written by Jean-loup Gailly
688       "gzip@prep.ai.mit.edu" and Mark Adler "madler@alumni.caltech.edu".
689
690       The primary site for the zlib compression library is
691       <http://www.zlib.org>.
692
693       The primary site for gzip is <http://www.gzip.org>.
694

AUTHOR

696       This module was written by Paul Marquess, "pmqs@cpan.org".
697

MODIFICATION HISTORY

699       See the Changes file.
700
702       Copyright (c) 2005-2019 Paul Marquess. All rights reserved.
703
704       This program is free software; you can redistribute it and/or modify it
705       under the same terms as Perl itself.
706
707
708
709perl v5.28.1                      2019-01-05     IO::Uncompress::RawInflate(3)
Impressum