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