2 package IO::Uncompress::Base ;
8 our (@ISA, $VERSION, @EXPORT_OK, %EXPORT_TAGS);
9 #@ISA = qw(Exporter IO::File);
15 use constant G_EOF => 0 ;
16 use constant G_ERR => -1 ;
18 use IO::Compress::Base::Common 2.004 ;
19 #use Parse::Parameters ;
23 use Scalar::Util qw(readonly);
24 use List::Util qw(min);
28 push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
29 #Exporter::export_ok_tags('all') ;
42 if (defined *$self->{InputLength}) {
44 if *$self->{InputLengthRemaining} <= 0 ;
45 $size = min($size, *$self->{InputLengthRemaining});
48 if ( length *$self->{Prime} ) {
49 #$$out = substr(*$self->{Prime}, 0, $size, '') ;
50 $$out = substr(*$self->{Prime}, 0, $size) ;
51 substr(*$self->{Prime}, 0, $size) = '' ;
52 if (length $$out == $size) {
53 *$self->{InputLengthRemaining} -= length $$out
54 if defined *$self->{InputLength};
58 $offset = length $$out ;
61 my $get_size = $size - $offset ;
63 #if ( defined *$self->{InputLength} ) {
64 # $get_size = min($get_size, *$self->{InputLengthRemaining});
67 if (defined *$self->{FH})
68 { *$self->{FH}->read($$out, $get_size, $offset) }
69 elsif (defined *$self->{InputEvent}) {
71 while (length $$out < $size) {
73 if ($got = *$self->{InputEvent}->($$out, $get_size)) <= 0;
76 if (length $$out > $size ) {
77 #*$self->{Prime} = substr($$out, $size, length($$out), '');
78 *$self->{Prime} = substr($$out, $size, length($$out));
79 substr($$out, $size, length($$out)) = '';
82 *$self->{EventEof} = 1 if $got <= 0 ;
85 no warnings 'uninitialized';
86 my $buf = *$self->{Buffer} ;
87 $$buf = '' unless defined $$buf ;
88 #$$out = '' unless defined $$out ;
89 substr($$out, $offset) = substr($$buf, *$self->{BufferOffset}, $get_size);
90 if (*$self->{ConsumeInput})
91 { substr($$buf, 0, $get_size) = '' }
93 { *$self->{BufferOffset} += length($$out) - $offset }
96 *$self->{InputLengthRemaining} -= length($$out) #- $offset
97 if defined *$self->{InputLength};
99 $self->saveStatus(length $$out < 0 ? STATUS_ERROR : STATUS_OK) ;
108 return if ! defined $_[0] || length $_[0] == 0 ;
110 if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
111 *$self->{Prime} = $_[0] . *$self->{Prime} ;
112 *$self->{InputLengthRemaining} += length($_[0]);
115 my $len = length $_[0];
117 if($len > *$self->{BufferOffset}) {
118 *$self->{Prime} = substr($_[0], 0, $len - *$self->{BufferOffset}) . *$self->{Prime} ;
119 *$self->{InputLengthRemaining} = *$self->{InputLength};
120 *$self->{BufferOffset} = 0
123 *$self->{InputLengthRemaining} += length($_[0]);
124 *$self->{BufferOffset} -= length($_[0]) ;
133 my $truncate = shift;
134 #print "smartSeek to $offset\n";
136 # TODO -- need to take prime into account
137 if (defined *$self->{FH})
138 { *$self->{FH}->seek($offset, SEEK_SET) }
140 *$self->{BufferOffset} = $offset ;
141 substr(${ *$self->{Buffer} }, *$self->{BufferOffset}) = ''
150 my $out_data = shift ;
152 if (defined *$self->{FH}) {
153 # flush needed for 5.8.0
154 defined *$self->{FH}->write($out_data, length $out_data) &&
155 defined *$self->{FH}->flush() ;
158 my $buf = *$self->{Buffer} ;
159 substr($$buf, *$self->{BufferOffset}, length $out_data) = $out_data ;
160 *$self->{BufferOffset} += length($out_data) ;
167 return $_[0]->smartRead($_[1], $_[2]) == $_[2];
175 return 0 if length *$self->{Prime} || *$self->{PushMode};
177 if (defined *$self->{FH})
178 { *$self->{FH}->eof() }
179 elsif (defined *$self->{InputEvent})
180 { *$self->{EventEof} }
182 { *$self->{BufferOffset} >= length(${ *$self->{Buffer} }) }
189 *$self->{ErrorNo} = 0 ;
190 ${ *$self->{Error} } = '' ;
196 my $errno = shift() + 0 ;
197 #return $errno unless $errno || ! defined *$self->{ErrorNo};
198 #return $errno unless $errno ;
200 *$self->{ErrorNo} = $errno;
201 ${ *$self->{Error} } = '' ;
203 return *$self->{ErrorNo} ;
212 #return $retval if ${ *$self->{Error} };
214 ${ *$self->{Error} } = shift ;
215 *$self->{ErrorNo} = shift() + 0 if @_ ;
217 #warn "saveErrorString: " . ${ *$self->{Error} } . " " . *$self->{Error} . "\n" ;
224 $self->saveErrorString(0, $_[0]);
234 my $errno = *$self->{ErrorNo};
235 my $error = ${ *$self->{Error} };
239 *$self->{ErrorNo} = $errno ;
240 ${ *$self->{Error} } = $error ;
248 return ${ *$self->{Error} } ;
254 return *$self->{ErrorNo};
260 return $self->saveErrorString(undef, "Header Error: $_[0]", STATUS_ERROR);
266 return $self->saveErrorString(G_ERR, "Trailer Error: $_[0]", STATUS_ERROR);
272 return $self->HeaderError("Truncated in $_[0] Section");
278 return $self->TrailerError("Truncated in $_[0] Section");
291 my $got = shift || IO::Compress::Base::Parameters::new();
294 'BlockSize' => [1, 1, Parse_unsigned, 16 * 1024],
295 'AutoClose' => [1, 1, Parse_boolean, 0],
296 'Strict' => [1, 1, Parse_boolean, 0],
297 'Append' => [1, 1, Parse_boolean, 0],
298 'Prime' => [1, 1, Parse_any, undef],
299 'MultiStream' => [1, 1, Parse_boolean, 0],
300 'Transparent' => [1, 1, Parse_any, 1],
301 'Scan' => [1, 1, Parse_boolean, 0],
302 'InputLength' => [1, 1, Parse_unsigned, undef],
303 'BinModeOut' => [1, 1, Parse_boolean, 0],
304 #'Encode' => [1, 1, Parse_any, undef],
306 #'ConsumeInput' => [1, 1, Parse_boolean, 0],
308 $self->getExtraParams(),
310 #'Todo - Revert to ordinary file on end Z_STREAM_END'=> 0,
314 $Valid->{TrailingData} = [1, 1, Parse_writable_scalar, undef]
315 if *$self->{OneShot} ;
317 $got->parse($Valid, @_ )
318 or $self->croakError("${class}: $got->{Error}") ;
320 $self->postCheckParams($got)
321 or $self->croakError("${class}: " . $self->error()) ;
330 my $append_mode = shift ;
332 my $class = ref $obj;
333 $obj->croakError("$class: Missing Input parameter")
336 my $inValue = shift ;
338 *$obj->{OneShot} = 0 ;
342 $got = $obj->checkParams($class, undef, @_)
346 my $inType = whatIsInput($inValue, 1);
348 $obj->ckInputParam($class, $inValue, 1)
354 or $obj->croakError("${class}: " . *$obj->{Error});
356 if ($inType eq 'buffer' || $inType eq 'code') {
357 *$obj->{Buffer} = $inValue ;
358 *$obj->{InputEvent} = $inValue
359 if $inType eq 'code' ;
362 if ($inType eq 'handle') {
363 *$obj->{FH} = $inValue ;
364 *$obj->{Handle} = 1 ;
366 # Need to rewind for Scan
367 *$obj->{FH}->seek(0, SEEK_SET)
368 if $got->value('Scan');
372 $mode = '+<' if $got->value('Scan');
373 *$obj->{StdIO} = ($inValue eq '-');
374 *$obj->{FH} = new IO::File "$mode $inValue"
375 or return $obj->saveErrorString(undef, "cannot open file '$inValue': $!", $!) ;
378 *$obj->{LineNo} = $. = 0;
379 setBinModeInput(*$obj->{FH}) ;
382 *$obj->{Buffer} = \$buff ;
385 if ($got->parsed('Encode')) {
386 my $want_encoding = $got->value('Encode');
387 *$obj->{Encoding} = getEncoding($obj, $class, $want_encoding);
391 *$obj->{InputLength} = $got->parsed('InputLength')
392 ? $got->value('InputLength')
394 *$obj->{InputLengthRemaining} = $got->value('InputLength');
395 *$obj->{BufferOffset} = 0 ;
396 *$obj->{AutoClose} = $got->value('AutoClose');
397 *$obj->{Strict} = $got->value('Strict');
398 *$obj->{BlockSize} = $got->value('BlockSize');
399 *$obj->{Append} = $got->value('Append');
400 *$obj->{AppendOutput} = $append_mode || $got->value('Append');
401 *$obj->{ConsumeInput} = $got->value('ConsumeInput');
402 *$obj->{Transparent} = $got->value('Transparent');
403 *$obj->{MultiStream} = $got->value('MultiStream');
405 # TODO - move these two into RawDeflate
406 *$obj->{Scan} = $got->value('Scan');
407 *$obj->{ParseExtra} = $got->value('ParseExtra')
408 || $got->value('Strict') ;
410 *$obj->{Prime} = $got->value('Prime') || '' ;
411 *$obj->{Pending} = '';
413 *$obj->{PlainBytesRead} = 0;
414 *$obj->{InflatedBytesRead} = 0;
415 *$obj->{UnCompSize} = new U64;
416 *$obj->{CompSize} = new U64;
417 *$obj->{TotalInflatedBytesRead} = 0;
418 *$obj->{NewStream} = 0 ;
419 *$obj->{EventEof} = 0 ;
420 *$obj->{ClassName} = $class ;
421 *$obj->{Params} = $got ;
423 if (*$obj->{ConsumeInput}) {
429 my $status = $obj->mkUncomp($class, $got);
432 unless defined $status;
436 unless *$obj->{Transparent};
439 *$obj->{Type} = 'plain';
441 #$status = $obj->mkIdentityUncomp($class, $got);
442 $obj->pushBack(*$obj->{HeaderPending}) ;
445 push @{ *$obj->{InfoList} }, *$obj->{Info} ;
447 $obj->saveStatus(STATUS_OK) ;
458 my $inType = whatIsInput($_[0], $_[1]);
460 $self->croakError("$from: input parameter not a filename, filehandle, array ref or scalar ref")
463 if ($inType eq 'filename' )
465 $self->croakError("$from: input filename is undef or null string")
466 if ! defined $_[0] || $_[0] eq '' ;
468 if ($_[0] ne '-' && ! -e $_[0] )
470 return $self->saveErrorString(undef,
471 "input file '$_[0]' does not exist", STATUS_ERROR);
483 my $class = (caller)[0] ;
484 my $name = (caller(1))[3] ;
486 $obj->croakError("$name: expected at least 1 parameters\n")
494 my $x = new Validator($class, *$obj->{Error}, $name, $input, $output)
497 push @_, $output if $haveOut && $x->{Hash};
499 *$obj->{OneShot} = 1 ;
501 my $got = $obj->checkParams($name, undef, @_)
504 if ($got->parsed('TrailingData'))
506 *$obj->{TrailingData} = $got->value('TrailingData');
509 *$obj->{MultiStream} = $got->value('MultiStream');
510 $got->value('MultiStream', 0);
516 # while (my($k, $v) = each %$input)
519 # unless defined $v ;
521 # $obj->_singleTarget($x, $k, $v, @_)
525 # return keys %$input ;
531 foreach my $pair (@{ $x->{Pairs} })
533 my ($from, $to) = @$pair ;
534 $obj->_singleTarget($x, $from, $to, @_)
538 return scalar @{ $x->{Pairs} } ;
541 if (! $x->{oneOutput} )
543 my $inFile = ($x->{inType} eq 'filenames'
544 || $x->{inType} eq 'filename');
546 $x->{inType} = $inFile ? 'filename' : 'buffer';
548 foreach my $in ($x->{oneInput} ? $input : @$input)
553 $obj->_singleTarget($x, $in, $output, @_)
560 # finally the 1 to 1 and n to 1
561 return $obj->_singleTarget($x, $input, $output, @_);
563 croak "should not be here" ;
571 ${ $x->{Error} } = $string ;
584 $x->{buff} = \$buff ;
587 if ($x->{outType} eq 'filename') {
590 if $x->{Got}->value('Append') ;
591 $x->{fh} = new IO::File "$mode $output"
592 or return retErr($x, "cannot open file '$output': $!") ;
593 binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut');
597 elsif ($x->{outType} eq 'handle') {
599 binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut');
600 if ($x->{Got}->value('Append')) {
601 seek($x->{fh}, 0, SEEK_END)
602 or return retErr($x, "Cannot seek to end of output filehandle: $!") ;
607 elsif ($x->{outType} eq 'buffer' )
610 unless $x->{Got}->value('Append');
611 $x->{buff} = $output ;
616 defined $self->_rd2($x, $input, $output)
621 for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input)
623 defined $self->_rd2($x, $element, $output)
629 if ( ($x->{outType} eq 'filename' && $output ne '-') ||
630 ($x->{outType} eq 'handle' && $x->{Got}->value('AutoClose'))) {
632 or return retErr($x, $!);
646 my $z = createSelfTiedObject($x->{Class}, *$self->{Error});
648 $z->_create($x->{Got}, 1, $input, @_)
656 while (($status = $z->read($x->{buff})) > 0) {
658 print $fh ${ $x->{buff} }
659 or return $z->saveErrorString(undef, "Error writing to output file: $!", $!);
660 ${ $x->{buff} } = '' ;
664 if (! $x->{oneOutput} ) {
665 my $ot = $x->{outType} ;
668 { push @$output, $x->{buff} }
669 elsif ($ot eq 'hash')
670 { $output->{$input} = $x->{buff} }
677 unless *$self->{MultiStream};
679 $status = $z->nextStream();
682 unless $status == 1 ;
685 return $z->closeError(undef)
688 ${ *$self->{TrailingData} } = $z->trailingData()
689 if defined *$self->{TrailingData} ;
699 return $_[0] if ref($_[0]);
713 wantarray ? @{ *$self->{InfoList} } : *$self->{Info};
722 if (defined *$self->{CompressedInputLength}) {
723 if (*$self->{CompressedInputLengthRemaining} == 0) {
724 delete *$self->{CompressedInputLength};
725 *$self->{CompressedInputLengthDone} = 1;
728 $size = min($size, *$self->{CompressedInputLengthRemaining} );
729 *$self->{CompressedInputLengthRemaining} -= $size ;
732 my $status = $self->smartRead($buff, $size) ;
733 return $self->saveErrorString(STATUS_ERROR, "Error Reading Data")
737 *$self->{Closed} = 1 ;
738 *$self->{EndStream} = 1 ;
739 return $self->saveErrorString(STATUS_ERROR, "unexpected end of file", STATUS_ERROR);
753 # >0 - ok, number of bytes read
759 return G_EOF if *$self->{Closed} ;
760 #return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
761 return G_EOF if *$self->{EndStream} ;
764 my $scan_mode = shift ;
766 if (*$self->{Plain}) {
768 my $len = $self->smartRead(\$tmp_buff, *$self->{BlockSize}) ;
770 return $self->saveErrorString(G_ERR, "Error reading data: $!", $!)
774 *$self->{EndStream} = 1 ;
777 *$self->{PlainBytesRead} += $len ;
778 $$buffer .= $tmp_buff;
784 if (*$self->{NewStream}) {
786 $self->gotoNextStream() > 0
789 # For the headers that actually uncompressed data, put the
790 # uncompressed data into the output buffer.
791 $$buffer .= *$self->{Pending} ;
792 my $len = length *$self->{Pending} ;
793 *$self->{Pending} = '';
799 my $status = $self->readBlock(\$temp_buf, *$self->{BlockSize}, $outSize) ;
801 if $status == STATUS_ERROR ;
804 if ($status == STATUS_OK) {
805 my $beforeC_len = length $temp_buf;
806 my $before_len = defined $$buffer ? length $$buffer : 0 ;
807 $status = *$self->{Uncomp}->uncompr(\$temp_buf, $buffer,
808 defined *$self->{CompressedInputLengthDone} ||
809 $self->smartEof(), $outSize);
811 return $self->saveErrorString(G_ERR, *$self->{Uncomp}{Error}, *$self->{Uncomp}{ErrorNo})
812 if $self->saveStatus($status) == STATUS_ERROR;
814 $self->postBlockChk($buffer, $before_len) == STATUS_OK
817 $buf_len = length($$buffer) - $before_len;
819 *$self->{CompSize}->add($beforeC_len - length $temp_buf) ;
821 *$self->{InflatedBytesRead} += $buf_len ;
822 *$self->{TotalInflatedBytesRead} += $buf_len ;
823 *$self->{UnCompSize}->add($buf_len) ;
825 $self->filterUncompressed($buffer);
827 if (*$self->{Encoding}) {
828 $$buffer = *$self->{Encoding}->decode($$buffer);
832 if ($status == STATUS_ENDSTREAM) {
834 *$self->{EndStream} = 1 ;
835 $self->pushBack($temp_buf) ;
839 my $trailer_size = *$self->{Info}{TrailerLength} ;
841 if (*$self->{Info}{TrailerLength})
843 $got = $self->smartRead(\$trailer, $trailer_size) ;
846 if ($got == $trailer_size) {
847 $self->chkTrailer($trailer) == STATUS_OK
851 return $self->TrailerError("trailer truncated. Expected " .
852 "$trailer_size bytes, got $got")
854 $self->pushBack($trailer) ;
857 # TODO - if want to file file pointer, do it here
859 if (! $self->smartEof()) {
860 *$self->{NewStream} = 1 ;
862 if (*$self->{MultiStream}) {
863 *$self->{EndStream} = 0 ;
871 # return the number of uncompressed bytes read
879 return *$self->{Uncomp}->reset();
882 sub filterUncompressed
889 # return *$self->{NewStream} ||
890 # *$self->{EndStream} ;
897 my $status = $self->gotoNextStream();
901 *$self->{TotalInflatedBytesRead} = 0 ;
902 *$self->{LineNo} = $. = 0;
911 if (! *$self->{NewStream}) {
915 # TODO - make this more efficient if know the offset for the end of
916 # the stream and seekable
917 $status = $self->read($buffer)
924 *$self->{NewStream} = 0 ;
925 *$self->{EndStream} = 0 ;
927 *$self->{UnCompSize}->reset();
928 *$self->{CompSize}->reset();
930 my $magic = $self->ckMagic();
931 #*$self->{EndStream} = 0 ;
934 if (! *$self->{Transparent} )
936 *$self->{EndStream} = 1 ;
941 *$self->{Type} = 'plain';
943 $self->pushBack(*$self->{HeaderPending}) ;
947 *$self->{Info} = $self->readHeader($magic);
949 if ( ! defined *$self->{Info} ) {
950 *$self->{EndStream} = 1 ;
955 push @{ *$self->{InfoList} }, *$self->{Info} ;
963 return 1 if ! defined *$self->{InfoList};
964 return scalar @{ *$self->{InfoList} } ;
970 # >0 - ok, number of bytes read
976 return G_EOF if *$self->{Closed} ;
977 return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
981 #$self->croakError(*$self->{ClassName} .
982 # "::read: buffer parameter is read-only")
983 # if Compress::Raw::Zlib::_readonly_ref($_[0]);
986 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
987 if readonly(${ $_[0] });
989 $self->croakError(*$self->{ClassName} . "::read: not a scalar reference $_[0]" )
990 unless ref $_[0] eq 'SCALAR' ;
994 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
1000 my $length = $_[1] ;
1001 my $offset = $_[2] || 0;
1003 # the core read will return 0 if asked for 0 bytes
1004 return 0 if defined $length && $length == 0 ;
1006 $length = $length || 0;
1008 $self->croakError(*$self->{ClassName} . "::read: length parameter is negative")
1011 $$buffer = '' unless *$self->{AppendOutput} || $offset ;
1013 # Short-circuit if this is a simple read, with no length
1014 # or offset specified.
1015 unless ( $length || $offset) {
1016 if (length *$self->{Pending}) {
1017 $$buffer .= *$self->{Pending} ;
1018 my $len = length *$self->{Pending};
1019 *$self->{Pending} = '' ;
1024 $len = $self->_raw_read($buffer)
1025 while ! *$self->{EndStream} && $len == 0 ;
1030 # Need to jump through more hoops - either length or offset
1031 # or both are specified.
1032 my $out_buffer = *$self->{Pending} ;
1034 while (! *$self->{EndStream} && length($out_buffer) < $length)
1036 my $buf_len = $self->_raw_read(\$out_buffer);
1041 $length = length $out_buffer
1042 if length($out_buffer) < $length ;
1047 *$self->{Pending} = $out_buffer;
1048 $out_buffer = \*$self->{Pending} ;
1051 $$buffer .= "\x00" x ($offset - length($$buffer))
1052 if $offset > length($$buffer) ;
1053 #substr($$buffer, $offset) = substr($$out_buffer, 0, $length, '') ;
1054 substr($$buffer, $offset) = substr($$out_buffer, 0, $length) ;
1055 substr($$out_buffer, 0, $length) = '' ;
1058 #$$buffer .= substr($$out_buffer, 0, $length, '') ;
1059 $$buffer .= substr($$out_buffer, 0, $length) ;
1060 substr($$out_buffer, 0, $length) = '' ;
1071 if ( ! defined $/ ) {
1073 1 while $self->read($data) > 0 ;
1078 if ( ref $/ eq 'SCALAR' && ${$/} =~ /^\d+$/ && ${$/} > 0) {
1079 my $reclen = ${$/} ;
1081 $self->read($data, $reclen) ;
1086 if ( ! length $/ ) {
1088 while ($self->read($paragraph) > 0 ) {
1089 if ($paragraph =~ s/^(.*?\n\n+)//s) {
1090 *$self->{Pending} = $paragraph ;
1098 # $/ isn't empty, or a reference, so it's Line Mode.
1102 my $p = \*$self->{Pending} ;
1104 if (length(*$self->{Pending}) &&
1105 ($offset = index(*$self->{Pending}, $/)) >=0) {
1106 my $l = substr(*$self->{Pending}, 0, $offset + length $/ );
1107 substr(*$self->{Pending}, 0, $offset + length $/) = '';
1111 while ($self->read($line) > 0 ) {
1112 my $offset = index($line, $/);
1114 my $l = substr($line, 0, $offset + length $/ );
1115 substr($line, 0, $offset + length $/) = '';
1128 my $current_append = *$self->{AppendOutput} ;
1129 *$self->{AppendOutput} = 1;
1130 my $lineref = $self->_getline();
1131 $. = ++ *$self->{LineNo} if defined $$lineref ;
1132 *$self->{AppendOutput} = $current_append;
1139 $self->croakError(*$self->{ClassName} .
1140 "::getlines: called in scalar context\n") unless wantarray;
1143 while defined($line = $self->getline);
1149 goto &getlines if wantarray;
1157 return $buf if $self->read($buf, 1);
1164 *$self->{Pending} = "" unless defined *$self->{Pending} ;
1165 *$self->{Pending} = $_[0] . *$self->{Pending} ;
1173 if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
1174 return *$self->{Prime} ;
1177 my $buf = *$self->{Buffer} ;
1178 my $offset = *$self->{BufferOffset} ;
1179 return substr($$buf, $offset) ;
1188 return (*$self->{Closed} ||
1189 (!length *$self->{Pending}
1190 && ( $self->smartEof() || *$self->{EndStream}))) ;
1198 if (*$self->{Plain}) {
1199 $in = *$self->{PlainBytesRead} ;
1202 $in = *$self->{TotalInflatedBytesRead} ;
1205 my $pending = length *$self->{Pending} ;
1207 return 0 if $pending > $in ;
1208 return $in - $pending ;
1213 # todo - what to do if close is called before the end of the gzip file
1214 # do we remember any trailing data?
1217 return 1 if *$self->{Closed} ;
1224 if (defined *$self->{FH}) {
1225 if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) {
1226 #if ( *$self->{AutoClose}) {
1229 $status = *$self->{FH}->close();
1230 return $self->saveErrorString(0, $!, $!)
1231 if !*$self->{InNew} && $self->saveStatus($!) != 0 ;
1233 delete *$self->{FH} ;
1236 *$self->{Closed} = 1 ;
1250 my $position = shift;
1251 my $whence = shift ;
1253 my $here = $self->tell() ;
1257 if ($whence == SEEK_SET) {
1258 $target = $position ;
1260 elsif ($whence == SEEK_CUR) {
1261 $target = $here + $position ;
1263 elsif ($whence == SEEK_END) {
1264 $target = $position ;
1265 $self->croakError(*$self->{ClassName} . "::seek: SEEK_END not allowed") ;
1268 $self->croakError(*$self->{ClassName} ."::seek: unknown value, $whence, for whence parameter");
1271 # short circuit if seeking to current offset
1272 return 1 if $target == $here ;
1274 # Outlaw any attempt to seek backwards
1275 $self->croakError( *$self->{ClassName} ."::seek: cannot seek backwards")
1276 if $target < $here ;
1278 # Walk the file to the new offset
1279 my $offset = $target - $here ;
1282 while (($got = $self->read(my $buffer, min($offset, *$self->{BlockSize})) ) > 0)
1285 last if $offset == 0 ;
1288 return $offset == 0 ? 1 : 0 ;
1294 return defined *$self->{FH}
1295 ? fileno *$self->{FH}
1302 # my $self = shift ;
1303 # return defined *$self->{FH}
1304 # ? binmode *$self->{FH}
1311 return ! *$self->{Closed} ;
1317 return defined *$self->{FH}
1318 ? *$self->{FH}->autoflush(@_)
1322 sub input_line_number
1325 my $last = *$self->{LineNo};
1326 $. = *$self->{LineNo} = $_[1] if @_ ;
1331 *BINMODE = \&binmode;
1344 #return sub { croak "$name Not Available" ; } ;
1345 return sub { croak "$name Not Available: File opened only for intput" ; } ;
1349 *print = _notAvailable('print');
1350 *PRINT = _notAvailable('print');
1351 *printf = _notAvailable('printf');
1352 *PRINTF = _notAvailable('printf');
1353 *write = _notAvailable('write');
1354 *WRITE = _notAvailable('write');
1357 #*syswrite = \&_notAvailable;
1361 package IO::Uncompress::Base ;
1370 IO::Uncompress::Base - Base Class for IO::Uncompress modules
1375 use IO::Uncompress::Base ;
1380 This module is not intended for direct use in application code. Its sole
1381 purpose if to to be sub-classed by IO::Unompress modules.
1388 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>
1390 L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1392 L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1393 L<Archive::Tar|Archive::Tar>,
1394 L<IO::Zlib|IO::Zlib>
1402 This module was written by Paul Marquess, F<pmqs@cpan.org>.
1406 =head1 MODIFICATION HISTORY
1408 See the Changes file.
1410 =head1 COPYRIGHT AND LICENSE
1412 Copyright (c) 2005-2007 Paul Marquess. All rights reserved.
1414 This program is free software; you can redistribute it and/or
1415 modify it under the same terms as Perl itself.