2 package IO::Uncompress::Base ;
8 our (@ISA, $VERSION, @EXPORT_OK, %EXPORT_TAGS);
9 @ISA = qw(Exporter IO::File);
14 use constant G_EOF => 0 ;
15 use constant G_ERR => -1 ;
17 use IO::Compress::Base::Common 2.006 ;
18 #use Parse::Parameters ;
22 use Scalar::Util qw(readonly);
23 use List::Util qw(min);
27 push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
28 #Exporter::export_ok_tags('all') ;
41 if (defined *$self->{InputLength}) {
43 if *$self->{InputLengthRemaining} <= 0 ;
44 $size = min($size, *$self->{InputLengthRemaining});
47 if ( length *$self->{Prime} ) {
48 #$$out = substr(*$self->{Prime}, 0, $size, '') ;
49 $$out = substr(*$self->{Prime}, 0, $size) ;
50 substr(*$self->{Prime}, 0, $size) = '' ;
51 if (length $$out == $size) {
52 *$self->{InputLengthRemaining} -= length $$out
53 if defined *$self->{InputLength};
57 $offset = length $$out ;
60 my $get_size = $size - $offset ;
62 #if ( defined *$self->{InputLength} ) {
63 # $get_size = min($get_size, *$self->{InputLengthRemaining});
66 if (defined *$self->{FH})
67 { *$self->{FH}->read($$out, $get_size, $offset) }
68 elsif (defined *$self->{InputEvent}) {
70 while (length $$out < $size) {
72 if ($got = *$self->{InputEvent}->($$out, $get_size)) <= 0;
75 if (length $$out > $size ) {
76 #*$self->{Prime} = substr($$out, $size, length($$out), '');
77 *$self->{Prime} = substr($$out, $size, length($$out));
78 substr($$out, $size, length($$out)) = '';
81 *$self->{EventEof} = 1 if $got <= 0 ;
84 no warnings 'uninitialized';
85 my $buf = *$self->{Buffer} ;
86 $$buf = '' unless defined $$buf ;
87 #$$out = '' unless defined $$out ;
88 substr($$out, $offset) = substr($$buf, *$self->{BufferOffset}, $get_size);
89 if (*$self->{ConsumeInput})
90 { substr($$buf, 0, $get_size) = '' }
92 { *$self->{BufferOffset} += length($$out) - $offset }
95 *$self->{InputLengthRemaining} -= length($$out) #- $offset
96 if defined *$self->{InputLength};
98 $self->saveStatus(length $$out < 0 ? STATUS_ERROR : STATUS_OK) ;
107 return if ! defined $_[0] || length $_[0] == 0 ;
109 if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
110 *$self->{Prime} = $_[0] . *$self->{Prime} ;
111 *$self->{InputLengthRemaining} += length($_[0]);
114 my $len = length $_[0];
116 if($len > *$self->{BufferOffset}) {
117 *$self->{Prime} = substr($_[0], 0, $len - *$self->{BufferOffset}) . *$self->{Prime} ;
118 *$self->{InputLengthRemaining} = *$self->{InputLength};
119 *$self->{BufferOffset} = 0
122 *$self->{InputLengthRemaining} += length($_[0]);
123 *$self->{BufferOffset} -= length($_[0]) ;
132 my $truncate = shift;
133 #print "smartSeek to $offset\n";
135 # TODO -- need to take prime into account
136 if (defined *$self->{FH})
137 { *$self->{FH}->seek($offset, SEEK_SET) }
139 *$self->{BufferOffset} = $offset ;
140 substr(${ *$self->{Buffer} }, *$self->{BufferOffset}) = ''
149 my $out_data = shift ;
151 if (defined *$self->{FH}) {
152 # flush needed for 5.8.0
153 defined *$self->{FH}->write($out_data, length $out_data) &&
154 defined *$self->{FH}->flush() ;
157 my $buf = *$self->{Buffer} ;
158 substr($$buf, *$self->{BufferOffset}, length $out_data) = $out_data ;
159 *$self->{BufferOffset} += length($out_data) ;
166 return $_[0]->smartRead($_[1], $_[2]) == $_[2];
174 return 0 if length *$self->{Prime} || *$self->{PushMode};
176 if (defined *$self->{FH})
177 { *$self->{FH}->eof() }
178 elsif (defined *$self->{InputEvent})
179 { *$self->{EventEof} }
181 { *$self->{BufferOffset} >= length(${ *$self->{Buffer} }) }
188 *$self->{ErrorNo} = 0 ;
189 ${ *$self->{Error} } = '' ;
195 my $errno = shift() + 0 ;
196 #return $errno unless $errno || ! defined *$self->{ErrorNo};
197 #return $errno unless $errno ;
199 *$self->{ErrorNo} = $errno;
200 ${ *$self->{Error} } = '' ;
202 return *$self->{ErrorNo} ;
211 #return $retval if ${ *$self->{Error} };
213 ${ *$self->{Error} } = shift ;
214 *$self->{ErrorNo} = shift() + 0 if @_ ;
216 #warn "saveErrorString: " . ${ *$self->{Error} } . " " . *$self->{Error} . "\n" ;
223 $self->saveErrorString(0, $_[0]);
233 my $errno = *$self->{ErrorNo};
234 my $error = ${ *$self->{Error} };
238 *$self->{ErrorNo} = $errno ;
239 ${ *$self->{Error} } = $error ;
247 return ${ *$self->{Error} } ;
253 return *$self->{ErrorNo};
259 return $self->saveErrorString(undef, "Header Error: $_[0]", STATUS_ERROR);
265 return $self->saveErrorString(G_ERR, "Trailer Error: $_[0]", STATUS_ERROR);
271 return $self->HeaderError("Truncated in $_[0] Section");
277 return $self->TrailerError("Truncated in $_[0] Section");
290 my $got = shift || IO::Compress::Base::Parameters::new();
293 'BlockSize' => [1, 1, Parse_unsigned, 16 * 1024],
294 'AutoClose' => [1, 1, Parse_boolean, 0],
295 'Strict' => [1, 1, Parse_boolean, 0],
296 'Append' => [1, 1, Parse_boolean, 0],
297 'Prime' => [1, 1, Parse_any, undef],
298 'MultiStream' => [1, 1, Parse_boolean, 0],
299 'Transparent' => [1, 1, Parse_any, 1],
300 'Scan' => [1, 1, Parse_boolean, 0],
301 'InputLength' => [1, 1, Parse_unsigned, undef],
302 'BinModeOut' => [1, 1, Parse_boolean, 0],
303 #'Encode' => [1, 1, Parse_any, undef],
305 #'ConsumeInput' => [1, 1, Parse_boolean, 0],
307 $self->getExtraParams(),
309 #'Todo - Revert to ordinary file on end Z_STREAM_END'=> 0,
313 $Valid->{TrailingData} = [1, 1, Parse_writable_scalar, undef]
314 if *$self->{OneShot} ;
316 $got->parse($Valid, @_ )
317 or $self->croakError("${class}: $got->{Error}") ;
319 $self->postCheckParams($got)
320 or $self->croakError("${class}: " . $self->error()) ;
329 my $append_mode = shift ;
331 my $class = ref $obj;
332 $obj->croakError("$class: Missing Input parameter")
335 my $inValue = shift ;
337 *$obj->{OneShot} = 0 ;
341 $got = $obj->checkParams($class, undef, @_)
345 my $inType = whatIsInput($inValue, 1);
347 $obj->ckInputParam($class, $inValue, 1)
353 or $obj->croakError("${class}: " . *$obj->{Error});
355 if ($inType eq 'buffer' || $inType eq 'code') {
356 *$obj->{Buffer} = $inValue ;
357 *$obj->{InputEvent} = $inValue
358 if $inType eq 'code' ;
361 if ($inType eq 'handle') {
362 *$obj->{FH} = $inValue ;
363 *$obj->{Handle} = 1 ;
365 # Need to rewind for Scan
366 *$obj->{FH}->seek(0, SEEK_SET)
367 if $got->value('Scan');
371 $mode = '+<' if $got->value('Scan');
372 *$obj->{StdIO} = ($inValue eq '-');
373 *$obj->{FH} = new IO::File "$mode $inValue"
374 or return $obj->saveErrorString(undef, "cannot open file '$inValue': $!", $!) ;
377 *$obj->{LineNo} = $. = 0;
378 setBinModeInput(*$obj->{FH}) ;
381 *$obj->{Buffer} = \$buff ;
384 if ($got->parsed('Encode')) {
385 my $want_encoding = $got->value('Encode');
386 *$obj->{Encoding} = getEncoding($obj, $class, $want_encoding);
390 *$obj->{InputLength} = $got->parsed('InputLength')
391 ? $got->value('InputLength')
393 *$obj->{InputLengthRemaining} = $got->value('InputLength');
394 *$obj->{BufferOffset} = 0 ;
395 *$obj->{AutoClose} = $got->value('AutoClose');
396 *$obj->{Strict} = $got->value('Strict');
397 *$obj->{BlockSize} = $got->value('BlockSize');
398 *$obj->{Append} = $got->value('Append');
399 *$obj->{AppendOutput} = $append_mode || $got->value('Append');
400 *$obj->{ConsumeInput} = $got->value('ConsumeInput');
401 *$obj->{Transparent} = $got->value('Transparent');
402 *$obj->{MultiStream} = $got->value('MultiStream');
404 # TODO - move these two into RawDeflate
405 *$obj->{Scan} = $got->value('Scan');
406 *$obj->{ParseExtra} = $got->value('ParseExtra')
407 || $got->value('Strict') ;
409 *$obj->{Prime} = $got->value('Prime') || '' ;
410 *$obj->{Pending} = '';
412 *$obj->{PlainBytesRead} = 0;
413 *$obj->{InflatedBytesRead} = 0;
414 *$obj->{UnCompSize} = new U64;
415 *$obj->{CompSize} = new U64;
416 *$obj->{TotalInflatedBytesRead} = 0;
417 *$obj->{NewStream} = 0 ;
418 *$obj->{EventEof} = 0 ;
419 *$obj->{ClassName} = $class ;
420 *$obj->{Params} = $got ;
422 if (*$obj->{ConsumeInput}) {
428 my $status = $obj->mkUncomp($class, $got);
431 unless defined $status;
435 unless *$obj->{Transparent};
438 *$obj->{Type} = 'plain';
440 #$status = $obj->mkIdentityUncomp($class, $got);
441 $obj->pushBack(*$obj->{HeaderPending}) ;
444 push @{ *$obj->{InfoList} }, *$obj->{Info} ;
446 $obj->saveStatus(STATUS_OK) ;
457 my $inType = whatIsInput($_[0], $_[1]);
459 $self->croakError("$from: input parameter not a filename, filehandle, array ref or scalar ref")
462 if ($inType eq 'filename' )
464 $self->croakError("$from: input filename is undef or null string")
465 if ! defined $_[0] || $_[0] eq '' ;
467 if ($_[0] ne '-' && ! -e $_[0] )
469 return $self->saveErrorString(undef,
470 "input file '$_[0]' does not exist", STATUS_ERROR);
482 my $class = (caller)[0] ;
483 my $name = (caller(1))[3] ;
485 $obj->croakError("$name: expected at least 1 parameters\n")
493 my $x = new Validator($class, *$obj->{Error}, $name, $input, $output)
496 push @_, $output if $haveOut && $x->{Hash};
498 *$obj->{OneShot} = 1 ;
500 my $got = $obj->checkParams($name, undef, @_)
503 if ($got->parsed('TrailingData'))
505 *$obj->{TrailingData} = $got->value('TrailingData');
508 *$obj->{MultiStream} = $got->value('MultiStream');
509 $got->value('MultiStream', 0);
515 # while (my($k, $v) = each %$input)
518 # unless defined $v ;
520 # $obj->_singleTarget($x, $k, $v, @_)
524 # return keys %$input ;
530 foreach my $pair (@{ $x->{Pairs} })
532 my ($from, $to) = @$pair ;
533 $obj->_singleTarget($x, $from, $to, @_)
537 return scalar @{ $x->{Pairs} } ;
540 if (! $x->{oneOutput} )
542 my $inFile = ($x->{inType} eq 'filenames'
543 || $x->{inType} eq 'filename');
545 $x->{inType} = $inFile ? 'filename' : 'buffer';
547 foreach my $in ($x->{oneInput} ? $input : @$input)
552 $obj->_singleTarget($x, $in, $output, @_)
559 # finally the 1 to 1 and n to 1
560 return $obj->_singleTarget($x, $input, $output, @_);
562 croak "should not be here" ;
570 ${ $x->{Error} } = $string ;
583 $x->{buff} = \$buff ;
586 if ($x->{outType} eq 'filename') {
589 if $x->{Got}->value('Append') ;
590 $x->{fh} = new IO::File "$mode $output"
591 or return retErr($x, "cannot open file '$output': $!") ;
592 binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut');
596 elsif ($x->{outType} eq 'handle') {
598 binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut');
599 if ($x->{Got}->value('Append')) {
600 seek($x->{fh}, 0, SEEK_END)
601 or return retErr($x, "Cannot seek to end of output filehandle: $!") ;
606 elsif ($x->{outType} eq 'buffer' )
609 unless $x->{Got}->value('Append');
610 $x->{buff} = $output ;
615 defined $self->_rd2($x, $input, $output)
620 for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input)
622 defined $self->_rd2($x, $element, $output)
628 if ( ($x->{outType} eq 'filename' && $output ne '-') ||
629 ($x->{outType} eq 'handle' && $x->{Got}->value('AutoClose'))) {
631 or return retErr($x, $!);
645 my $z = createSelfTiedObject($x->{Class}, *$self->{Error});
647 $z->_create($x->{Got}, 1, $input, @_)
655 while (($status = $z->read($x->{buff})) > 0) {
657 print $fh ${ $x->{buff} }
658 or return $z->saveErrorString(undef, "Error writing to output file: $!", $!);
659 ${ $x->{buff} } = '' ;
663 if (! $x->{oneOutput} ) {
664 my $ot = $x->{outType} ;
667 { push @$output, $x->{buff} }
668 elsif ($ot eq 'hash')
669 { $output->{$input} = $x->{buff} }
676 unless *$self->{MultiStream};
678 $status = $z->nextStream();
681 unless $status == 1 ;
684 return $z->closeError(undef)
687 ${ *$self->{TrailingData} } = $z->trailingData()
688 if defined *$self->{TrailingData} ;
698 return $_[0] if ref($_[0]);
712 wantarray ? @{ *$self->{InfoList} } : *$self->{Info};
721 if (defined *$self->{CompressedInputLength}) {
722 if (*$self->{CompressedInputLengthRemaining} == 0) {
723 delete *$self->{CompressedInputLength};
724 *$self->{CompressedInputLengthDone} = 1;
727 $size = min($size, *$self->{CompressedInputLengthRemaining} );
728 *$self->{CompressedInputLengthRemaining} -= $size ;
731 my $status = $self->smartRead($buff, $size) ;
732 return $self->saveErrorString(STATUS_ERROR, "Error Reading Data")
736 *$self->{Closed} = 1 ;
737 *$self->{EndStream} = 1 ;
738 return $self->saveErrorString(STATUS_ERROR, "unexpected end of file", STATUS_ERROR);
752 # >0 - ok, number of bytes read
758 return G_EOF if *$self->{Closed} ;
759 #return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
760 return G_EOF if *$self->{EndStream} ;
763 my $scan_mode = shift ;
765 if (*$self->{Plain}) {
767 my $len = $self->smartRead(\$tmp_buff, *$self->{BlockSize}) ;
769 return $self->saveErrorString(G_ERR, "Error reading data: $!", $!)
773 *$self->{EndStream} = 1 ;
776 *$self->{PlainBytesRead} += $len ;
777 $$buffer .= $tmp_buff;
783 if (*$self->{NewStream}) {
785 $self->gotoNextStream() > 0
788 # For the headers that actually uncompressed data, put the
789 # uncompressed data into the output buffer.
790 $$buffer .= *$self->{Pending} ;
791 my $len = length *$self->{Pending} ;
792 *$self->{Pending} = '';
798 my $status = $self->readBlock(\$temp_buf, *$self->{BlockSize}, $outSize) ;
800 if $status == STATUS_ERROR ;
803 if ($status == STATUS_OK) {
804 my $beforeC_len = length $temp_buf;
805 my $before_len = defined $$buffer ? length $$buffer : 0 ;
806 $status = *$self->{Uncomp}->uncompr(\$temp_buf, $buffer,
807 defined *$self->{CompressedInputLengthDone} ||
808 $self->smartEof(), $outSize);
810 return $self->saveErrorString(G_ERR, *$self->{Uncomp}{Error}, *$self->{Uncomp}{ErrorNo})
811 if $self->saveStatus($status) == STATUS_ERROR;
813 $self->postBlockChk($buffer, $before_len) == STATUS_OK
816 $buf_len = length($$buffer) - $before_len;
818 *$self->{CompSize}->add($beforeC_len - length $temp_buf) ;
820 *$self->{InflatedBytesRead} += $buf_len ;
821 *$self->{TotalInflatedBytesRead} += $buf_len ;
822 *$self->{UnCompSize}->add($buf_len) ;
824 $self->filterUncompressed($buffer);
826 if (*$self->{Encoding}) {
827 $$buffer = *$self->{Encoding}->decode($$buffer);
831 if ($status == STATUS_ENDSTREAM) {
833 *$self->{EndStream} = 1 ;
834 $self->pushBack($temp_buf) ;
838 my $trailer_size = *$self->{Info}{TrailerLength} ;
840 if (*$self->{Info}{TrailerLength})
842 $got = $self->smartRead(\$trailer, $trailer_size) ;
845 if ($got == $trailer_size) {
846 $self->chkTrailer($trailer) == STATUS_OK
850 return $self->TrailerError("trailer truncated. Expected " .
851 "$trailer_size bytes, got $got")
853 $self->pushBack($trailer) ;
856 # TODO - if want to file file pointer, do it here
858 if (! $self->smartEof()) {
859 *$self->{NewStream} = 1 ;
861 if (*$self->{MultiStream}) {
862 *$self->{EndStream} = 0 ;
870 # return the number of uncompressed bytes read
878 return *$self->{Uncomp}->reset();
881 sub filterUncompressed
888 # return *$self->{NewStream} ||
889 # *$self->{EndStream} ;
896 my $status = $self->gotoNextStream();
900 *$self->{TotalInflatedBytesRead} = 0 ;
901 *$self->{LineNo} = $. = 0;
910 if (! *$self->{NewStream}) {
914 # TODO - make this more efficient if know the offset for the end of
915 # the stream and seekable
916 $status = $self->read($buffer)
923 *$self->{NewStream} = 0 ;
924 *$self->{EndStream} = 0 ;
926 *$self->{UnCompSize}->reset();
927 *$self->{CompSize}->reset();
929 my $magic = $self->ckMagic();
930 #*$self->{EndStream} = 0 ;
933 if (! *$self->{Transparent} )
935 *$self->{EndStream} = 1 ;
940 *$self->{Type} = 'plain';
942 $self->pushBack(*$self->{HeaderPending}) ;
946 *$self->{Info} = $self->readHeader($magic);
948 if ( ! defined *$self->{Info} ) {
949 *$self->{EndStream} = 1 ;
954 push @{ *$self->{InfoList} }, *$self->{Info} ;
962 return 1 if ! defined *$self->{InfoList};
963 return scalar @{ *$self->{InfoList} } ;
969 # >0 - ok, number of bytes read
975 return G_EOF if *$self->{Closed} ;
980 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
981 if readonly(${ $_[0] });
983 $self->croakError(*$self->{ClassName} . "::read: not a scalar reference $_[0]" )
984 unless ref $_[0] eq 'SCALAR' ;
988 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
995 my $offset = $_[2] || 0;
997 if (! *$self->{AppendOutput}) {
1002 if ($offset > length($$buffer)) {
1003 $$buffer .= "\x00" x ($offset - length($$buffer));
1006 substr($$buffer, $offset) = '';
1011 return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
1013 # the core read will return 0 if asked for 0 bytes
1014 return 0 if defined $length && $length == 0 ;
1016 $length = $length || 0;
1018 $self->croakError(*$self->{ClassName} . "::read: length parameter is negative")
1021 # Short-circuit if this is a simple read, with no length
1022 # or offset specified.
1023 unless ( $length || $offset) {
1024 if (length *$self->{Pending}) {
1025 $$buffer .= *$self->{Pending} ;
1026 my $len = length *$self->{Pending};
1027 *$self->{Pending} = '' ;
1032 $len = $self->_raw_read($buffer)
1033 while ! *$self->{EndStream} && $len == 0 ;
1038 # Need to jump through more hoops - either length or offset
1039 # or both are specified.
1040 my $out_buffer = *$self->{Pending} ;
1043 while (! *$self->{EndStream} && length($out_buffer) < $length)
1045 my $buf_len = $self->_raw_read(\$out_buffer);
1050 $length = length $out_buffer
1051 if length($out_buffer) < $length ;
1057 if ! defined $$buffer;
1059 $offset = length $$buffer
1060 if *$self->{AppendOutput} ;
1062 *$self->{Pending} = $out_buffer;
1063 $out_buffer = \*$self->{Pending} ;
1065 #substr($$buffer, $offset) = substr($$out_buffer, 0, $length, '') ;
1066 substr($$buffer, $offset) = substr($$out_buffer, 0, $length) ;
1067 substr($$out_buffer, 0, $length) = '' ;
1077 if ( ! defined $/ ) {
1079 1 while $self->read($data) > 0 ;
1084 if ( ref $/ eq 'SCALAR' && ${$/} =~ /^\d+$/ && ${$/} > 0) {
1085 my $reclen = ${$/} ;
1087 $self->read($data, $reclen) ;
1092 if ( ! length $/ ) {
1094 while ($self->read($paragraph) > 0 ) {
1095 if ($paragraph =~ s/^(.*?\n\n+)//s) {
1096 *$self->{Pending} = $paragraph ;
1104 # $/ isn't empty, or a reference, so it's Line Mode.
1108 my $p = \*$self->{Pending} ;
1110 if (length(*$self->{Pending}) &&
1111 ($offset = index(*$self->{Pending}, $/)) >=0) {
1112 my $l = substr(*$self->{Pending}, 0, $offset + length $/ );
1113 substr(*$self->{Pending}, 0, $offset + length $/) = '';
1117 while ($self->read($line) > 0 ) {
1118 my $offset = index($line, $/);
1120 my $l = substr($line, 0, $offset + length $/ );
1121 substr($line, 0, $offset + length $/) = '';
1134 my $current_append = *$self->{AppendOutput} ;
1135 *$self->{AppendOutput} = 1;
1136 my $lineref = $self->_getline();
1137 $. = ++ *$self->{LineNo} if defined $$lineref ;
1138 *$self->{AppendOutput} = $current_append;
1145 $self->croakError(*$self->{ClassName} .
1146 "::getlines: called in scalar context\n") unless wantarray;
1149 while defined($line = $self->getline);
1155 goto &getlines if wantarray;
1163 return $buf if $self->read($buf, 1);
1170 *$self->{Pending} = "" unless defined *$self->{Pending} ;
1171 *$self->{Pending} = $_[0] . *$self->{Pending} ;
1179 if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
1180 return *$self->{Prime} ;
1183 my $buf = *$self->{Buffer} ;
1184 my $offset = *$self->{BufferOffset} ;
1185 return substr($$buf, $offset) ;
1194 return (*$self->{Closed} ||
1195 (!length *$self->{Pending}
1196 && ( $self->smartEof() || *$self->{EndStream}))) ;
1204 if (*$self->{Plain}) {
1205 $in = *$self->{PlainBytesRead} ;
1208 $in = *$self->{TotalInflatedBytesRead} ;
1211 my $pending = length *$self->{Pending} ;
1213 return 0 if $pending > $in ;
1214 return $in - $pending ;
1219 # todo - what to do if close is called before the end of the gzip file
1220 # do we remember any trailing data?
1223 return 1 if *$self->{Closed} ;
1230 if (defined *$self->{FH}) {
1231 if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) {
1232 #if ( *$self->{AutoClose}) {
1235 $status = *$self->{FH}->close();
1236 return $self->saveErrorString(0, $!, $!)
1237 if !*$self->{InNew} && $self->saveStatus($!) != 0 ;
1239 delete *$self->{FH} ;
1242 *$self->{Closed} = 1 ;
1256 my $position = shift;
1257 my $whence = shift ;
1259 my $here = $self->tell() ;
1263 if ($whence == SEEK_SET) {
1264 $target = $position ;
1266 elsif ($whence == SEEK_CUR) {
1267 $target = $here + $position ;
1269 elsif ($whence == SEEK_END) {
1270 $target = $position ;
1271 $self->croakError(*$self->{ClassName} . "::seek: SEEK_END not allowed") ;
1274 $self->croakError(*$self->{ClassName} ."::seek: unknown value, $whence, for whence parameter");
1277 # short circuit if seeking to current offset
1278 return 1 if $target == $here ;
1280 # Outlaw any attempt to seek backwards
1281 $self->croakError( *$self->{ClassName} ."::seek: cannot seek backwards")
1282 if $target < $here ;
1284 # Walk the file to the new offset
1285 my $offset = $target - $here ;
1288 while (($got = $self->read(my $buffer, min($offset, *$self->{BlockSize})) ) > 0)
1291 last if $offset == 0 ;
1294 return $offset == 0 ? 1 : 0 ;
1300 return defined *$self->{FH}
1301 ? fileno *$self->{FH}
1308 # my $self = shift ;
1309 # return defined *$self->{FH}
1310 # ? binmode *$self->{FH}
1317 return ! *$self->{Closed} ;
1323 return defined *$self->{FH}
1324 ? *$self->{FH}->autoflush(@_)
1328 sub input_line_number
1331 my $last = *$self->{LineNo};
1332 $. = *$self->{LineNo} = $_[1] if @_ ;
1337 *BINMODE = \&binmode;
1350 #return sub { croak "$name Not Available" ; } ;
1351 return sub { croak "$name Not Available: File opened only for intput" ; } ;
1355 *print = _notAvailable('print');
1356 *PRINT = _notAvailable('print');
1357 *printf = _notAvailable('printf');
1358 *PRINTF = _notAvailable('printf');
1359 *write = _notAvailable('write');
1360 *WRITE = _notAvailable('write');
1363 #*syswrite = \&_notAvailable;
1367 package IO::Uncompress::Base ;
1376 IO::Uncompress::Base - Base Class for IO::Uncompress modules
1381 use IO::Uncompress::Base ;
1386 This module is not intended for direct use in application code. Its sole
1387 purpose if to to be sub-classed by IO::Unompress modules.
1394 L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1396 L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1398 L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1399 L<Archive::Tar|Archive::Tar>,
1400 L<IO::Zlib|IO::Zlib>
1408 This module was written by Paul Marquess, F<pmqs@cpan.org>.
1412 =head1 MODIFICATION HISTORY
1414 See the Changes file.
1416 =head1 COPYRIGHT AND LICENSE
1418 Copyright (c) 2005-2007 Paul Marquess. All rights reserved.
1420 This program is free software; you can redistribute it and/or
1421 modify it under the same terms as Perl itself.