1IO::Uncompress::RawInflaPteer(l3pPmr)ogrammers ReferencIeO:G:uUindceompress::RawInflate(3pm)
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 => $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 TODO
177
178 "MultiStream => 0|1"
179 This option is a no-op.
180
181 "TrailingData => $scalar"
182 Returns the data, if any, that is present immediately after the
183 compressed data stream once uncompression is complete.
184
185 This option can be used when there is useful information
186 immediately following the compressed data stream, and you don't
187 know the length of the compressed data stream.
188
189 If the input is a buffer, "trailingData" will return everything
190 from the end of the compressed data stream to the end of the
191 buffer.
192
193 If the input is a filehandle, "trailingData" will return the data
194 that is left in the filehandle input buffer once the end of the
195 compressed data stream has been reached. You can then use the
196 filehandle to read the rest of the input file.
197
198 Don't bother using "trailingData" if the input is a filename.
199
200 If you know the length of the compressed data stream before you
201 start uncompressing, you can avoid having to use "trailingData" by
202 setting the "InputLength" option.
203
204 Examples
205 To read the contents of the file "file1.txt.1951" and write the
206 uncompressed data to the file "file1.txt".
207
208 use strict ;
209 use warnings ;
210 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
211
212 my $input = "file1.txt.1951";
213 my $output = "file1.txt";
214 rawinflate $input => $output
215 or die "rawinflate failed: $RawInflateError\n";
216
217 To read from an existing Perl filehandle, $input, and write the
218 uncompressed data to a buffer, $buffer.
219
220 use strict ;
221 use warnings ;
222 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
223 use IO::File ;
224
225 my $input = new IO::File "<file1.txt.1951"
226 or die "Cannot open 'file1.txt.1951': $!\n" ;
227 my $buffer ;
228 rawinflate $input => \$buffer
229 or die "rawinflate failed: $RawInflateError\n";
230
231 To uncompress all files in the directory "/my/home" that match
232 "*.txt.1951" and store the compressed data in the same directory
233
234 use strict ;
235 use warnings ;
236 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
237
238 rawinflate '</my/home/*.txt.1951>' => '</my/home/#1.txt>'
239 or die "rawinflate failed: $RawInflateError\n";
240
241 and if you want to compress each file one at a time, this will do the
242 trick
243
244 use strict ;
245 use warnings ;
246 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
247
248 for my $input ( glob "/my/home/*.txt.1951" )
249 {
250 my $output = $input;
251 $output =~ s/.1951// ;
252 rawinflate $input => $output
253 or die "Error compressing '$input': $RawInflateError\n";
254 }
255
257 Constructor
258 The format of the constructor for IO::Uncompress::RawInflate is shown
259 below
260
261 my $z = new IO::Uncompress::RawInflate $input [OPTS]
262 or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
263
264 Returns an "IO::Uncompress::RawInflate" object on success and undef on
265 failure. The variable $RawInflateError will contain an error message
266 on failure.
267
268 If you are running Perl 5.005 or better the object, $z, returned from
269 IO::Uncompress::RawInflate can be used exactly like an IO::File
270 filehandle. This means that all normal input file operations can be
271 carried out with $z. For example, to read a line from a compressed
272 file/buffer you can use either of these forms
273
274 $line = $z->getline();
275 $line = <$z>;
276
277 The mandatory parameter $input is used to determine the source of the
278 compressed data. This parameter can take one of three forms.
279
280 A filename
281 If the $input parameter is a scalar, it is assumed to be a
282 filename. This file will be opened for reading and the compressed
283 data will be read from it.
284
285 A filehandle
286 If the $input parameter is a filehandle, the compressed data will
287 be read from it. The string '-' can be used as an alias for
288 standard input.
289
290 A scalar reference
291 If $input is a scalar reference, the compressed data will be read
292 from $$output.
293
294 Constructor Options
295 The option names defined below are case insensitive and can be
296 optionally prefixed by a '-'. So all of the following are valid
297
298 -AutoClose
299 -autoclose
300 AUTOCLOSE
301 autoclose
302
303 OPTS is a combination of the following options:
304
305 "AutoClose => 0|1"
306 This option is only valid when the $input parameter is a
307 filehandle. If specified, and the value is true, it will result in
308 the file being closed once either the "close" method is called or
309 the IO::Uncompress::RawInflate object is destroyed.
310
311 This parameter defaults to 0.
312
313 "MultiStream => 0|1"
314 Allows multiple concatenated compressed streams to be treated as a
315 single compressed stream. Decompression will stop once either the
316 end of the file/buffer is reached, an error is encountered
317 (premature eof, corrupt compressed data) or the end of a stream is
318 not immediately followed by the start of another stream.
319
320 This parameter defaults to 0.
321
322 "Prime => $string"
323 This option will uncompress the contents of $string before
324 processing the input file/buffer.
325
326 This option can be useful when the compressed data is embedded in
327 another file/data structure and it is not possible to work out
328 where the compressed data begins without having to read the first
329 few bytes. If this is the case, the uncompression can be primed
330 with these bytes using this option.
331
332 "Transparent => 0|1"
333 If this option is set and the input file/buffer is not compressed
334 data, the module will allow reading of it anyway.
335
336 In addition, if the input file/buffer does contain compressed data
337 and there is non-compressed data immediately following it, setting
338 this option will make this module treat the whole file/bufffer as
339 a single data stream.
340
341 This option defaults to 1.
342
343 "BlockSize => $num"
344 When reading the compressed input data, IO::Uncompress::RawInflate
345 will read it in blocks of $num bytes.
346
347 This option defaults to 4096.
348
349 "InputLength => $size"
350 When present this option will limit the number of compressed bytes
351 read from the input file/buffer to $size. This option can be used
352 in the situation where there is useful data directly after the
353 compressed data stream and you know beforehand the exact length of
354 the compressed data stream.
355
356 This option is mostly used when reading from a filehandle, in
357 which case the file pointer will be left pointing to the first
358 byte directly after the compressed data stream.
359
360 This option defaults to off.
361
362 "Append => 0|1"
363 This option controls what the "read" method does with uncompressed
364 data.
365
366 If set to 1, all uncompressed data will be appended to the output
367 parameter of the "read" method.
368
369 If set to 0, the contents of the output parameter of the "read"
370 method will be overwritten by the uncompressed data.
371
372 Defaults to 0.
373
374 "Strict => 0|1"
375 This option is a no-op.
376
377 Examples
378 TODO
379
381 read
382 Usage is
383
384 $status = $z->read($buffer)
385
386 Reads a block of compressed data (the size the the compressed block is
387 determined by the "Buffer" option in the constructor), uncompresses it
388 and writes any uncompressed data into $buffer. If the "Append"
389 parameter is set in the constructor, the uncompressed data will be
390 appended to the $buffer parameter. Otherwise $buffer will be
391 overwritten.
392
393 Returns the number of uncompressed bytes written to $buffer, zero if
394 eof or a negative number on error.
395
396 read
397 Usage is
398
399 $status = $z->read($buffer, $length)
400 $status = $z->read($buffer, $length, $offset)
401
402 $status = read($z, $buffer, $length)
403 $status = read($z, $buffer, $length, $offset)
404
405 Attempt to read $length bytes of uncompressed data into $buffer.
406
407 The main difference between this form of the "read" method and the
408 previous one, is that this one will attempt to return exactly $length
409 bytes. The only circumstances that this function will not is if end-of-
410 file or an IO error is encountered.
411
412 Returns the number of uncompressed bytes written to $buffer, zero if
413 eof or a negative number on error.
414
415 getline
416 Usage is
417
418 $line = $z->getline()
419 $line = <$z>
420
421 Reads a single line.
422
423 This method fully supports the use of of the variable $/ (or
424 $INPUT_RECORD_SEPARATOR or $RS when "English" is in use) to determine
425 what constitutes an end of line. Paragraph mode, record mode and file
426 slurp mode are all supported.
427
428 getc
429 Usage is
430
431 $char = $z->getc()
432
433 Read a single character.
434
435 ungetc
436 Usage is
437
438 $char = $z->ungetc($string)
439
440 inflateSync
441 Usage is
442
443 $status = $z->inflateSync()
444
445 TODO
446
447 getHeaderInfo
448 Usage is
449
450 $hdr = $z->getHeaderInfo();
451 @hdrs = $z->getHeaderInfo();
452
453 This method returns either a hash reference (in scalar context) or a
454 list or hash references (in array context) that contains information
455 about each of the header fields in the compressed data stream(s).
456
457 tell
458 Usage is
459
460 $z->tell()
461 tell $z
462
463 Returns the uncompressed file offset.
464
465 eof
466 Usage is
467
468 $z->eof();
469 eof($z);
470
471 Returns true if the end of the compressed input stream has been
472 reached.
473
474 seek
475 $z->seek($position, $whence);
476 seek($z, $position, $whence);
477
478 Provides a sub-set of the "seek" functionality, with the restriction
479 that it is only legal to seek forward in the input file/buffer. It is
480 a fatal error to attempt to seek backward.
481
482 The $whence parameter takes one the usual values, namely SEEK_SET,
483 SEEK_CUR or SEEK_END.
484
485 Returns 1 on success, 0 on failure.
486
487 binmode
488 Usage is
489
490 $z->binmode
491 binmode $z ;
492
493 This is a noop provided for completeness.
494
495 opened
496 $z->opened()
497
498 Returns true if the object currently refers to a opened file/buffer.
499
500 autoflush
501 my $prev = $z->autoflush()
502 my $prev = $z->autoflush(EXPR)
503
504 If the $z object is associated with a file or a filehandle, this method
505 returns the current autoflush setting for the underlying filehandle. If
506 "EXPR" is present, and is non-zero, it will enable flushing after every
507 write/print operation.
508
509 If $z is associated with a buffer, this method has no effect and always
510 returns "undef".
511
512 Note that the special variable $| cannot be used to set or retrieve the
513 autoflush setting.
514
515 input_line_number
516 $z->input_line_number()
517 $z->input_line_number(EXPR)
518
519 Returns the current uncompressed line number. If "EXPR" is present it
520 has the effect of setting the line number. Note that setting the line
521 number does not change the current position within the file/buffer
522 being read.
523
524 The contents of $/ are used to to determine what constitutes a line
525 terminator.
526
527 fileno
528 $z->fileno()
529 fileno($z)
530
531 If the $z object is associated with a file or a filehandle, "fileno"
532 will return the underlying file descriptor. Once the "close" method is
533 called "fileno" will return "undef".
534
535 If the $z object is is associated with a buffer, this method will
536 return "undef".
537
538 close
539 $z->close() ;
540 close $z ;
541
542 Closes the output file/buffer.
543
544 For most versions of Perl this method will be automatically invoked if
545 the IO::Uncompress::RawInflate object is destroyed (either explicitly
546 or by the variable with the reference to the object going out of
547 scope). The exceptions are Perl versions 5.005 through 5.00504 and
548 5.8.0. In these cases, the "close" method will be called automatically,
549 but not until global destruction of all live objects when the program
550 is terminating.
551
552 Therefore, if you want your scripts to be able to run on all versions
553 of Perl, you should call "close" explicitly and not rely on automatic
554 closing.
555
556 Returns true on success, otherwise 0.
557
558 If the "AutoClose" option has been enabled when the
559 IO::Uncompress::RawInflate object was created, and the object is
560 associated with a file, the underlying file will also be closed.
561
562 nextStream
563 Usage is
564
565 my $status = $z->nextStream();
566
567 Skips to the next compressed data stream in the input file/buffer. If a
568 new compressed data stream is found, the eof marker will be cleared and
569 $. will be reset to 0.
570
571 Returns 1 if a new stream was found, 0 if none was found, and -1 if an
572 error was encountered.
573
574 trailingData
575 Usage is
576
577 my $data = $z->trailingData();
578
579 Returns the data, if any, that is present immediately after the
580 compressed data stream once uncompression is complete. It only makes
581 sense to call this method once the end of the compressed data stream
582 has been encountered.
583
584 This option can be used when there is useful information immediately
585 following the compressed data stream, and you don't know the length of
586 the compressed data stream.
587
588 If the input is a buffer, "trailingData" will return everything from
589 the end of the compressed data stream to the end of the buffer.
590
591 If the input is a filehandle, "trailingData" will return the data that
592 is left in the filehandle input buffer once the end of the compressed
593 data stream has been reached. You can then use the filehandle to read
594 the rest of the input file.
595
596 Don't bother using "trailingData" if the input is a filename.
597
598 If you know the length of the compressed data stream before you start
599 uncompressing, you can avoid having to use "trailingData" by setting
600 the "InputLength" option in the constructor.
601
603 No symbolic constants are required by this IO::Uncompress::RawInflate
604 at present.
605
606 :all Imports "rawinflate" and $RawInflateError. Same as doing this
607
608 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
609
611 Working with Net::FTP
612 See IO::Uncompress::RawInflate::FAQ
613
615 Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip,
616 IO::Compress::Deflate, IO::Uncompress::Inflate,
617 IO::Compress::RawDeflate, IO::Compress::Bzip2, IO::Uncompress::Bunzip2,
618 IO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf,
619 IO::Uncompress::UnLzf, IO::Uncompress::AnyInflate,
620 IO::Uncompress::AnyUncompress
621
622 Compress::Zlib::FAQ
623
624 File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
625
626 For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html,
627 http://www.faqs.org/rfcs/rfc1951.html and
628 http://www.faqs.org/rfcs/rfc1952.html
629
630 The zlib compression library was written by Jean-loup Gailly
631 gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
632
633 The primary site for the zlib compression library is
634 http://www.zlib.org.
635
636 The primary site for gzip is http://www.gzip.org.
637
639 This module was written by Paul Marquess, pmqs@cpan.org.
640
642 See the Changes file.
643
645 Copyright (c) 2005-2009 Paul Marquess. All rights reserved.
646
647 This program is free software; you can redistribute it and/or modify it
648 under the same terms as Perl itself.
649
650
651
652perl v5.10.1 2017-03-22 IO::Uncompress::RawInflate(3pm)