Re: [perl #40583] sprintf "%#04X" also uppercases the 0x-prefix
[p5sagit/p5-mst-13.2.git] / ext / Compress / IO / Zlib / lib / IO / Uncompress / RawInflate.pm
CommitLineData
642e522c 1package IO::Uncompress::RawInflate ;
2# for RFC1951
3
4use strict ;
5use warnings;
a02d0f6f 6use bytes;
1a6a8453 7
a02d0f6f 8use Compress::Raw::Zlib ;
9use IO::Compress::Base::Common qw(:Status createSelfTiedObject);
1a6a8453 10
11use IO::Uncompress::Base ;
a02d0f6f 12use IO::Uncompress::Adapter::Inflate ;
1a6a8453 13
14
15
642e522c 16
17require Exporter ;
1a6a8453 18our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $RawInflateError);
642e522c 19
e7d45986 20$VERSION = '2.000_13';
642e522c 21$RawInflateError = '';
22
1a6a8453 23@ISA = qw( Exporter IO::Uncompress::Base );
642e522c 24@EXPORT_OK = qw( $RawInflateError rawinflate ) ;
1a6a8453 25%DEFLATE_CONSTANTS = ();
26%EXPORT_TAGS = %IO::Uncompress::Base::EXPORT_TAGS ;
642e522c 27push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
28Exporter::export_ok_tags('all');
29
30
31
642e522c 32sub new
33{
1a6a8453 34 my $class = shift ;
35 my $obj = createSelfTiedObject($class, \$RawInflateError);
36 $obj->_create(undef, 0, @_);
642e522c 37}
38
39sub rawinflate
40{
1a6a8453 41 my $obj = createSelfTiedObject(undef, \$RawInflateError);
42 return $obj->_inf(@_);
43}
44
45sub getExtraParams
46{
47 return ();
48}
49
50sub ckParams
51{
52 my $self = shift ;
53 my $got = shift ;
54
55 return 1;
56}
57
58sub mkUncomp
59{
60 my $self = shift ;
61 my $class = shift ;
62 my $got = shift ;
63
a02d0f6f 64 my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject(
1a6a8453 65 $got->value('CRC32'),
66 $got->value('ADLER32'),
67 $got->value('Scan'),
68 );
69
70 return $self->saveErrorString(undef, $errstr, $errno)
71 if ! defined $obj;
72
73 *$self->{Uncomp} = $obj;
74
75 my $magic = $self->ckMagic()
76 or return 0;
77
78 *$self->{Info} = $self->readHeader($magic)
79 or return undef ;
80
81 return 1;
82
83}
84
85
86sub ckMagic
87{
88 my $self = shift;
89
90 return $self->_isRaw() ;
91}
92
93sub readHeader
94{
95 my $self = shift;
96 my $magic = shift ;
97
98 return {
99 'Type' => 'rfc1951',
100 'FingerprintLength' => 0,
101 'HeaderLength' => 0,
102 'TrailerLength' => 0,
103 'Header' => ''
104 };
105}
106
107sub chkTrailer
108{
a02d0f6f 109 return STATUS_OK ;
1a6a8453 110}
111
112sub _isRaw
113{
114 my $self = shift ;
115
116 my $got = $self->_isRawx(@_);
117
118 if ($got) {
119 *$self->{Pending} = *$self->{HeaderPending} ;
120 }
121 else {
122 $self->pushBack(*$self->{HeaderPending});
123 *$self->{Uncomp}->reset();
124 }
125 *$self->{HeaderPending} = '';
126
127 return $got ;
642e522c 128}
129
1a6a8453 130sub _isRawx
131{
132 my $self = shift ;
133 my $magic = shift ;
134
135 $magic = '' unless defined $magic ;
136
137 my $buffer = '';
138
139 $self->smartRead(\$buffer, *$self->{BlockSize}) >= 0
140 or return $self->saveErrorString(undef, "No data to read");
141
142 my $temp_buf = $magic . $buffer ;
143 *$self->{HeaderPending} = $temp_buf ;
144 $buffer = '';
145 my $status = *$self->{Uncomp}->uncompr(\$temp_buf, \$buffer, $self->smartEof()) ;
146 return $self->saveErrorString(undef, *$self->{Uncomp}{Error}, STATUS_ERROR)
147 if $status == STATUS_ERROR;
148
e7d45986 149 #my $buf_len = *$self->{Uncomp}->uncompressedBytes();
150 my $buf_len = length $buffer;
1a6a8453 151
152 if ($status == STATUS_ENDSTREAM) {
153 if (*$self->{MultiStream}
154 && (length $temp_buf || ! $self->smartEof())){
155 *$self->{NewStream} = 1 ;
156 *$self->{EndStream} = 0 ;
157 $self->pushBack($temp_buf);
158 }
159 else {
160 *$self->{EndStream} = 1 ;
161 $self->pushBack($temp_buf);
162 }
163 }
164 *$self->{HeaderPending} = $buffer ;
165 *$self->{InflatedBytesRead} = $buf_len ;
166 *$self->{TotalInflatedBytesRead} += $buf_len ;
167 *$self->{Type} = 'rfc1951';
168
169 $self->saveStatus(STATUS_OK);
170
171 return {
172 'Type' => 'rfc1951',
173 'HeaderLength' => 0,
174 'TrailerLength' => 0,
175 'Header' => ''
176 };
177}
178
179
180sub inflateSync
181{
182 my $self = shift ;
183
184 # inflateSync is a no-op in Plain mode
185 return 1
186 if *$self->{Plain} ;
187
188 return 0 if *$self->{Closed} ;
189 #return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
190 return 0 if ! length *$self->{Pending} && *$self->{EndStream} ;
191
192 # Disable CRC check
193 *$self->{Strict} = 0 ;
194
195 my $status ;
196 while (1)
197 {
198 my $temp_buf ;
199
200 if (length *$self->{Pending} )
201 {
202 $temp_buf = *$self->{Pending} ;
203 *$self->{Pending} = '';
204 }
205 else
206 {
207 $status = $self->smartRead(\$temp_buf, *$self->{BlockSize}) ;
208 return $self->saveErrorString(0, "Error Reading Data")
209 if $status < 0 ;
210
211 if ($status == 0 ) {
212 *$self->{EndStream} = 1 ;
213 return $self->saveErrorString(0, "unexpected end of file", STATUS_ERROR);
214 }
215 }
216
217 $status = *$self->{Uncomp}->sync($temp_buf) ;
218
219 if ($status == STATUS_OK)
220 {
221 *$self->{Pending} .= $temp_buf ;
222 return 1 ;
223 }
224
225 last unless $status == STATUS_ERROR ;
226 }
227
228 return 0;
229}
230
231#sub performScan
232#{
233# my $self = shift ;
234#
235# my $status ;
236# my $end_offset = 0;
237#
238# $status = $self->scan()
239# #or return $self->saveErrorString(undef, "Error Scanning: $$error_ref", $self->errorNo) ;
240# or return $self->saveErrorString(G_ERR, "Error Scanning: $status")
241#
242# $status = $self->zap($end_offset)
243# or return $self->saveErrorString(G_ERR, "Error Zapping: $status");
244# #or return $self->saveErrorString(undef, "Error Zapping: $$error_ref", $self->errorNo) ;
245#
246# #(*$obj->{Deflate}, $status) = $inf->createDeflate();
247#
248## *$obj->{Header} = *$inf->{Info}{Header};
249## *$obj->{UnCompSize_32bit} =
250## *$obj->{BytesWritten} = *$inf->{UnCompSize_32bit} ;
251## *$obj->{CompSize_32bit} = *$inf->{CompSize_32bit} ;
252#
253#
254## if ( $outType eq 'buffer')
255## { substr( ${ *$self->{Buffer} }, $end_offset) = '' }
256## elsif ($outType eq 'handle' || $outType eq 'filename') {
257## *$self->{FH} = *$inf->{FH} ;
258## delete *$inf->{FH};
259## *$obj->{FH}->flush() ;
260## *$obj->{Handle} = 1 if $outType eq 'handle';
261##
262## #seek(*$obj->{FH}, $end_offset, SEEK_SET)
263## *$obj->{FH}->seek($end_offset, SEEK_SET)
264## or return $obj->saveErrorString(undef, $!, $!) ;
265## }
266#
267#}
268
269sub scan
270{
271 my $self = shift ;
272
273 return 1 if *$self->{Closed} ;
274 return 1 if !length *$self->{Pending} && *$self->{EndStream} ;
275
276 my $buffer = '' ;
277 my $len = 0;
278
279 $len = $self->_raw_read(\$buffer, 1)
280 while ! *$self->{EndStream} && $len >= 0 ;
281
282 #return $len if $len < 0 ? $len : 0 ;
283 return $len < 0 ? 0 : 1 ;
284}
285
286sub zap
287{
288 my $self = shift ;
289
290 my $headerLength = *$self->{Info}{HeaderLength};
291 my $block_offset = $headerLength + *$self->{Uncomp}->getLastBlockOffset();
292 $_[0] = $headerLength + *$self->{Uncomp}->getEndOffset();
293 #printf "# End $_[0], headerlen $headerLength \n";;
294 #printf "# block_offset $block_offset %x\n", $block_offset;
295 my $byte ;
296 ( $self->smartSeek($block_offset) &&
297 $self->smartRead(\$byte, 1) )
298 or return $self->saveErrorString(0, $!, $!);
299
300 #printf "#byte is %x\n", unpack('C*',$byte);
301 *$self->{Uncomp}->resetLastBlockByte($byte);
302 #printf "#to byte is %x\n", unpack('C*',$byte);
303
304 ( $self->smartSeek($block_offset) &&
305 $self->smartWrite($byte) )
306 or return $self->saveErrorString(0, $!, $!);
307
308 #$self->smartSeek($end_offset, 1);
309
310 return 1 ;
311}
312
313sub createDeflate
314{
315 my $self = shift ;
316 my ($def, $status) = *$self->{Uncomp}->createDeflateStream(
317 -AppendOutput => 1,
318 -WindowBits => - MAX_WBITS,
319 -CRC32 => *$self->{Params}->value('CRC32'),
320 -ADLER32 => *$self->{Params}->value('ADLER32'),
321 );
322
323 return wantarray ? ($status, $def) : $def ;
324}
325
326
642e522c 3271;
328
329__END__
330
331
332=head1 NAME
333
a02d0f6f 334
cb7abd7f 335
336IO::Uncompress::RawInflate - Read RFC 1951 files/buffers
337
642e522c 338
a02d0f6f 339
642e522c 340=head1 SYNOPSIS
341
342 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
343
344 my $status = rawinflate $input => $output [,OPTS]
345 or die "rawinflate failed: $RawInflateError\n";
346
347 my $z = new IO::Uncompress::RawInflate $input [OPTS]
348 or die "rawinflate failed: $RawInflateError\n";
349
350 $status = $z->read($buffer)
351 $status = $z->read($buffer, $length)
352 $status = $z->read($buffer, $length, $offset)
353 $line = $z->getline()
354 $char = $z->getc()
355 $char = $z->ungetc()
a02d0f6f 356 $char = $z->opened()
357
642e522c 358 $status = $z->inflateSync()
a02d0f6f 359
e7d45986 360 $data = $z->trailingData()
361 $status = $z->nextStream()
642e522c 362 $data = $z->getHeaderInfo()
363 $z->tell()
364 $z->seek($position, $whence)
365 $z->binmode()
366 $z->fileno()
367 $z->eof()
368 $z->close()
369
370 $RawInflateError ;
371
372 # IO::File mode
373
374 <$z>
375 read($z, $buffer);
376 read($z, $buffer, $length);
377 read($z, $buffer, $length, $offset);
378 tell($z)
379 seek($z, $position, $whence)
380 binmode($z)
381 fileno($z)
382 eof($z)
383 close($z)
384
385
386=head1 DESCRIPTION
387
388
389
390B<WARNING -- This is a Beta release>.
391
392=over 5
393
394=item * DO NOT use in production code.
395
396=item * The documentation is incomplete in places.
397
398=item * Parts of the interface defined here are tentative.
399
400=item * Please report any problems you find.
401
402=back
403
404
405
406
407
1a6a8453 408This module provides a Perl interface that allows the reading of
642e522c 409files/buffers that conform to RFC 1951.
410
1a6a8453 411For writing RFC 1951 files/buffers, see the companion module IO::Compress::RawDeflate.
642e522c 412
413
414
cb7abd7f 415
416
417
642e522c 418=head1 Functional Interface
419
1a6a8453 420A top-level function, C<rawinflate>, is provided to carry out
421"one-shot" uncompression between buffers and/or files. For finer
422control over the uncompression process, see the L</"OO Interface">
423section.
642e522c 424
425 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
426
427 rawinflate $input => $output [,OPTS]
428 or die "rawinflate failed: $RawInflateError\n";
429
1a6a8453 430
642e522c 431
432The functional interface needs Perl5.005 or better.
433
434
435=head2 rawinflate $input => $output [, OPTS]
436
1a6a8453 437
438C<rawinflate> expects at least two parameters, C<$input> and C<$output>.
642e522c 439
440=head3 The C<$input> parameter
441
442The parameter, C<$input>, is used to define the source of
443the compressed data.
444
445It can take one of the following forms:
446
447=over 5
448
449=item A filename
450
451If the C<$input> parameter is a simple scalar, it is assumed to be a
452filename. This file will be opened for reading and the input data
453will be read from it.
454
455=item A filehandle
456
457If the C<$input> parameter is a filehandle, the input data will be
458read from it.
459The string '-' can be used as an alias for standard input.
460
461=item A scalar reference
462
463If C<$input> is a scalar reference, the input data will be read
464from C<$$input>.
465
466=item An array reference
467
1a6a8453 468If C<$input> is an array reference, each element in the array must be a
469filename.
470
471The input data will be read from each file in turn.
472
642e522c 473The complete array will be walked to ensure that it only
1a6a8453 474contains valid filenames before any data is uncompressed.
475
476
642e522c 477
478=item An Input FileGlob string
479
480If C<$input> is a string that is delimited by the characters "<" and ">"
481C<rawinflate> will assume that it is an I<input fileglob string>. The
482input is the list of files that match the fileglob.
483
484If the fileglob does not match any files ...
485
486See L<File::GlobMapper|File::GlobMapper> for more details.
487
488
489=back
490
491If the C<$input> parameter is any other type, C<undef> will be returned.
492
493
494
495=head3 The C<$output> parameter
496
497The parameter C<$output> is used to control the destination of the
498uncompressed data. This parameter can take one of these forms.
499
500=over 5
501
502=item A filename
503
1a6a8453 504If the C<$output> parameter is a simple scalar, it is assumed to be a
505filename. This file will be opened for writing and the uncompressed
506data will be written to it.
642e522c 507
508=item A filehandle
509
1a6a8453 510If the C<$output> parameter is a filehandle, the uncompressed data
511will be written to it.
642e522c 512The string '-' can be used as an alias for standard output.
513
514
515=item A scalar reference
516
1a6a8453 517If C<$output> is a scalar reference, the uncompressed data will be
518stored in C<$$output>.
642e522c 519
520
642e522c 521
522=item An Array Reference
523
1a6a8453 524If C<$output> is an array reference, the uncompressed data will be
525pushed onto the array.
642e522c 526
527=item An Output FileGlob
528
529If C<$output> is a string that is delimited by the characters "<" and ">"
530C<rawinflate> will assume that it is an I<output fileglob string>. The
531output is the list of files that match the fileglob.
532
533When C<$output> is an fileglob string, C<$input> must also be a fileglob
534string. Anything else is an error.
535
536=back
537
538If the C<$output> parameter is any other type, C<undef> will be returned.
539
642e522c 540
642e522c 541
542=head2 Notes
543
c70c1701 544
545When C<$input> maps to multiple compressed files/buffers and C<$output> is
546a single file/buffer, after uncompression C<$output> will contain a
547concatenation of all the uncompressed data from each of the input
548files/buffers.
549
550
642e522c 551
552
553
554=head2 Optional Parameters
555
556Unless specified below, the optional parameters for C<rawinflate>,
557C<OPTS>, are the same as those used with the OO interface defined in the
558L</"Constructor Options"> section below.
559
560=over 5
561
e7d45986 562=item C<< AutoClose => 0|1 >>
642e522c 563
1a6a8453 564This option applies to any input or output data streams to
565C<rawinflate> that are filehandles.
642e522c 566
567If C<AutoClose> is specified, and the value is true, it will result in all
568input and/or output filehandles being closed once C<rawinflate> has
569completed.
570
571This parameter defaults to 0.
572
573
e7d45986 574=item C<< BinModeOut => 0|1 >>
1a6a8453 575
576When writing to a file or filehandle, set C<binmode> before writing to the
577file.
578
579Defaults to 0.
580
581
582
583
584
e7d45986 585=item C<< Append => 0|1 >>
642e522c 586
587TODO
588
e7d45986 589=item C<< MultiStream => 0|1 >>
1a6a8453 590
e7d45986 591If the input file/buffer contains multiple compressed data streams, this
592option will uncompress the whole lot as a single data stream.
1a6a8453 593
e7d45986 594Defaults to 0.
1a6a8453 595
642e522c 596
597
598=back
599
600
601
602
603=head2 Examples
604
605To read the contents of the file C<file1.txt.1951> and write the
606compressed data to the file C<file1.txt>.
607
608 use strict ;
609 use warnings ;
610 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
611
612 my $input = "file1.txt.1951";
613 my $output = "file1.txt";
614 rawinflate $input => $output
615 or die "rawinflate failed: $RawInflateError\n";
616
617
618To read from an existing Perl filehandle, C<$input>, and write the
619uncompressed data to a buffer, C<$buffer>.
620
621 use strict ;
622 use warnings ;
623 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
624 use IO::File ;
625
626 my $input = new IO::File "<file1.txt.1951"
627 or die "Cannot open 'file1.txt.1951': $!\n" ;
628 my $buffer ;
629 rawinflate $input => \$buffer
630 or die "rawinflate failed: $RawInflateError\n";
631
632To uncompress all files in the directory "/my/home" that match "*.txt.1951" and store the compressed data in the same directory
633
634 use strict ;
635 use warnings ;
636 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
637
638 rawinflate '</my/home/*.txt.1951>' => '</my/home/#1.txt>'
639 or die "rawinflate failed: $RawInflateError\n";
640
641and if you want to compress each file one at a time, this will do the trick
642
643 use strict ;
644 use warnings ;
645 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
646
647 for my $input ( glob "/my/home/*.txt.1951" )
648 {
649 my $output = $input;
650 $output =~ s/.1951// ;
651 rawinflate $input => $output
652 or die "Error compressing '$input': $RawInflateError\n";
653 }
654
655=head1 OO Interface
656
657=head2 Constructor
658
659The format of the constructor for IO::Uncompress::RawInflate is shown below
660
661
662 my $z = new IO::Uncompress::RawInflate $input [OPTS]
663 or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
664
665Returns an C<IO::Uncompress::RawInflate> object on success and undef on failure.
666The variable C<$RawInflateError> will contain an error message on failure.
667
1a6a8453 668If you are running Perl 5.005 or better the object, C<$z>, returned from
669IO::Uncompress::RawInflate can be used exactly like an L<IO::File|IO::File> filehandle.
670This means that all normal input file operations can be carried out with
671C<$z>. For example, to read a line from a compressed file/buffer you can
672use either of these forms
642e522c 673
674 $line = $z->getline();
675 $line = <$z>;
676
677The mandatory parameter C<$input> is used to determine the source of the
678compressed data. This parameter can take one of three forms.
679
680=over 5
681
682=item A filename
683
684If the C<$input> parameter is a scalar, it is assumed to be a filename. This
685file will be opened for reading and the compressed data will be read from it.
686
687=item A filehandle
688
689If the C<$input> parameter is a filehandle, the compressed data will be
690read from it.
691The string '-' can be used as an alias for standard input.
692
693
694=item A scalar reference
695
696If C<$input> is a scalar reference, the compressed data will be read from
697C<$$output>.
698
699=back
700
701=head2 Constructor Options
702
703
704The option names defined below are case insensitive and can be optionally
705prefixed by a '-'. So all of the following are valid
706
707 -AutoClose
708 -autoclose
709 AUTOCLOSE
710 autoclose
711
712OPTS is a combination of the following options:
713
714=over 5
715
e7d45986 716=item C<< AutoClose => 0|1 >>
642e522c 717
718This option is only valid when the C<$input> parameter is a filehandle. If
719specified, and the value is true, it will result in the file being closed once
720either the C<close> method is called or the IO::Uncompress::RawInflate object is
721destroyed.
722
723This parameter defaults to 0.
724
e7d45986 725=item C<< MultiStream => 0|1 >>
642e522c 726
727
728
729This option is a no-op.
730
731
732
e7d45986 733=item C<< Prime => $string >>
642e522c 734
735This option will uncompress the contents of C<$string> before processing the
736input file/buffer.
737
738This option can be useful when the compressed data is embedded in another
739file/data structure and it is not possible to work out where the compressed
1a6a8453 740data begins without having to read the first few bytes. If this is the
741case, the uncompression can be I<primed> with these bytes using this
742option.
642e522c 743
e7d45986 744=item C<< Transparent => 0|1 >>
642e522c 745
746If this option is set and the input file or buffer is not compressed data,
747the module will allow reading of it anyway.
748
749This option defaults to 1.
750
e7d45986 751=item C<< BlockSize => $num >>
642e522c 752
1a6a8453 753When reading the compressed input data, IO::Uncompress::RawInflate will read it in
754blocks of C<$num> bytes.
642e522c 755
756This option defaults to 4096.
757
e7d45986 758=item C<< InputLength => $size >>
642e522c 759
1a6a8453 760When present this option will limit the number of compressed bytes read
761from the input file/buffer to C<$size>. This option can be used in the
762situation where there is useful data directly after the compressed data
763stream and you know beforehand the exact length of the compressed data
764stream.
642e522c 765
1a6a8453 766This option is mostly used when reading from a filehandle, in which case
767the file pointer will be left pointing to the first byte directly after the
642e522c 768compressed data stream.
769
770
771
772This option defaults to off.
773
e7d45986 774=item C<< Append => 0|1 >>
642e522c 775
776This option controls what the C<read> method does with uncompressed data.
777
1a6a8453 778If set to 1, all uncompressed data will be appended to the output parameter
779of the C<read> method.
642e522c 780
1a6a8453 781If set to 0, the contents of the output parameter of the C<read> method
782will be overwritten by the uncompressed data.
642e522c 783
784Defaults to 0.
785
e7d45986 786=item C<< Strict => 0|1 >>
642e522c 787
788
789
790This option is a no-op.
791
792
793
794
795
a02d0f6f 796
642e522c 797=back
798
799=head2 Examples
800
801TODO
802
803=head1 Methods
804
805=head2 read
806
807Usage is
808
809 $status = $z->read($buffer)
810
811Reads a block of compressed data (the size the the compressed block is
812determined by the C<Buffer> option in the constructor), uncompresses it and
1a6a8453 813writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
814set in the constructor, the uncompressed data will be appended to the
815C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
642e522c 816
1a6a8453 817Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
818or a negative number on error.
642e522c 819
820=head2 read
821
822Usage is
823
824 $status = $z->read($buffer, $length)
825 $status = $z->read($buffer, $length, $offset)
826
827 $status = read($z, $buffer, $length)
828 $status = read($z, $buffer, $length, $offset)
829
830Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
831
1a6a8453 832The main difference between this form of the C<read> method and the
833previous one, is that this one will attempt to return I<exactly> C<$length>
834bytes. The only circumstances that this function will not is if end-of-file
835or an IO error is encountered.
642e522c 836
1a6a8453 837Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
838or a negative number on error.
642e522c 839
840
841=head2 getline
842
843Usage is
844
845 $line = $z->getline()
846 $line = <$z>
847
848Reads a single line.
849
850This method fully supports the use of of the variable C<$/>
851(or C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
852determine what constitutes an end of line. Both paragraph mode and file
853slurp mode are supported.
854
855
856=head2 getc
857
858Usage is
859
860 $char = $z->getc()
861
862Read a single character.
863
864=head2 ungetc
865
866Usage is
867
868 $char = $z->ungetc($string)
869
870
a02d0f6f 871
642e522c 872=head2 inflateSync
873
874Usage is
875
876 $status = $z->inflateSync()
877
878TODO
879
a02d0f6f 880
642e522c 881=head2 getHeaderInfo
882
883Usage is
884
1a6a8453 885 $hdr = $z->getHeaderInfo();
886 @hdrs = $z->getHeaderInfo();
642e522c 887
1a6a8453 888This method returns either a hash reference (in scalar context) or a list
889or hash references (in array context) that contains information about each
890of the header fields in the compressed data stream(s).
642e522c 891
892
893
894
895=head2 tell
896
897Usage is
898
899 $z->tell()
900 tell $z
901
902Returns the uncompressed file offset.
903
904=head2 eof
905
906Usage is
907
908 $z->eof();
909 eof($z);
910
911
912
913Returns true if the end of the compressed input stream has been reached.
914
915
916
917=head2 seek
918
919 $z->seek($position, $whence);
920 seek($z, $position, $whence);
921
922
923
924
925Provides a sub-set of the C<seek> functionality, with the restriction
926that it is only legal to seek forward in the input file/buffer.
927It is a fatal error to attempt to seek backward.
928
929
930
931The C<$whence> parameter takes one the usual values, namely SEEK_SET,
932SEEK_CUR or SEEK_END.
933
934Returns 1 on success, 0 on failure.
935
936=head2 binmode
937
938Usage is
939
940 $z->binmode
941 binmode $z ;
942
943This is a noop provided for completeness.
944
a02d0f6f 945=head2 opened
946
947 $z->opened()
948
949Returns true if the object currently refers to a opened file/buffer.
950
951=head2 autoflush
952
953 my $prev = $z->autoflush()
954 my $prev = $z->autoflush(EXPR)
955
956If the C<$z> object is associated with a file or a filehandle, this method
957returns the current autoflush setting for the underlying filehandle. If
958C<EXPR> is present, and is non-zero, it will enable flushing after every
959write/print operation.
960
961If C<$z> is associated with a buffer, this method has no effect and always
962returns C<undef>.
963
964B<Note> that the special variable C<$|> B<cannot> be used to set or
965retrieve the autoflush setting.
966
967=head2 input_line_number
968
969 $z->input_line_number()
970 $z->input_line_number(EXPR)
971
972
973
974Returns the current uncompressed line number. If C<EXPR> is present it has
975the effect of setting the line number. Note that setting the line number
976does not change the current position within the file/buffer being read.
977
978The contents of C<$/> are used to to determine what constitutes a line
979terminator.
980
981
982
642e522c 983=head2 fileno
984
985 $z->fileno()
986 fileno($z)
987
a02d0f6f 988If the C<$z> object is associated with a file or a filehandle, this method
989will return the underlying file descriptor.
642e522c 990
991If the C<$z> object is is associated with a buffer, this method will
992return undef.
993
994=head2 close
995
996 $z->close() ;
997 close $z ;
998
999
1000
1001Closes the output file/buffer.
1002
1003
1004
1005For most versions of Perl this method will be automatically invoked if
1006the IO::Uncompress::RawInflate object is destroyed (either explicitly or by the
1007variable with the reference to the object going out of scope). The
1008exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1009these cases, the C<close> method will be called automatically, but
1010not until global destruction of all live objects when the program is
1011terminating.
1012
1013Therefore, if you want your scripts to be able to run on all versions
1014of Perl, you should call C<close> explicitly and not rely on automatic
1015closing.
1016
1017Returns true on success, otherwise 0.
1018
1019If the C<AutoClose> option has been enabled when the IO::Uncompress::RawInflate
1020object was created, and the object is associated with a file, the
1021underlying file will also be closed.
1022
1023
1024
1025
e7d45986 1026=head2 nextStream
1027
1028Usage is
1029
1030 my $status = $z->nextStream();
1031
1032Skips to the next compressed data stream in the input file/buffer. If a new
1033compressed data stream is found, the eof marker will be cleared, C<$.> will
1034be reset to 0.
1035
1036Returns 1 if a new stream was found, 0 if none was found, and -1 if an
1037error was encountered.
1038
1039=head2 trailingData
1040
1041Usage is
1042
1043 my $data = $z->trailingData();
1044
1045Returns any data that
1046
642e522c 1047=head1 Importing
1048
1049No symbolic constants are required by this IO::Uncompress::RawInflate at present.
1050
1051=over 5
1052
1053=item :all
1054
1055Imports C<rawinflate> and C<$RawInflateError>.
1056Same as doing this
1057
1058 use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
1059
1060=back
1061
1062=head1 EXAMPLES
1063
1064
1065
1066
1067=head1 SEE ALSO
1068
a02d0f6f 1069L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
642e522c 1070
1071L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1072
a02d0f6f 1073L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1074L<Archive::Tar|Archive::Tar>,
642e522c 1075L<IO::Zlib|IO::Zlib>
1076
a02d0f6f 1077
642e522c 1078For RFC 1950, 1951 and 1952 see
1079F<http://www.faqs.org/rfcs/rfc1950.html>,
1080F<http://www.faqs.org/rfcs/rfc1951.html> and
1081F<http://www.faqs.org/rfcs/rfc1952.html>
1082
a02d0f6f 1083The I<zlib> compression library was written by Jean-loup Gailly
1084F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>.
1085
1086The primary site for the I<zlib> compression library is
1087F<http://www.zlib.org>.
1088
1089The primary site for gzip is F<http://www.gzip.org>.
1090
1091
1092
1093
642e522c 1094=head1 AUTHOR
1095
cb7abd7f 1096This module was written by Paul Marquess, F<pmqs@cpan.org>.
642e522c 1097
642e522c 1098
642e522c 1099
1100=head1 MODIFICATION HISTORY
1101
1102See the Changes file.
1103
1104=head1 COPYRIGHT AND LICENSE
642e522c 1105
1a6a8453 1106Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
a02d0f6f 1107
642e522c 1108This program is free software; you can redistribute it and/or
1109modify it under the same terms as Perl itself.
1110