2 package IO::Uncompress::Base ;
8 our (@ISA, $VERSION, @EXPORT_OK, %EXPORT_TAGS);
9 #@ISA = qw(Exporter IO::File);
13 $VERSION = '2.000_14';
15 use constant G_EOF => 0 ;
16 use constant G_ERR => -1 ;
18 use IO::Compress::Base::Common;
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 #'ConsumeInput' => [1, 1, Parse_boolean, 0],
306 $self->getExtraParams(),
308 #'Todo - Revert to ordinary file on end Z_STREAM_END'=> 0,
312 $Valid->{TrailingData} = [1, 1, Parse_writable_scalar, undef]
313 if *$self->{OneShot} ;
315 $got->parse($Valid, @_ )
316 or $self->croakError("${class}: $got->{Error}") ;
318 $self->postCheckParams($got)
319 or $self->croakError("${class}: " . $self->error()) ;
328 my $append_mode = shift ;
330 my $class = ref $obj;
331 $obj->croakError("$class: Missing Input parameter")
334 my $inValue = shift ;
336 *$obj->{OneShot} = 0 ;
340 $got = $obj->checkParams($class, undef, @_)
344 my $inType = whatIsInput($inValue, 1);
346 $obj->ckInputParam($class, $inValue, 1)
352 or $obj->croakError("${class}: " . *$obj->{Error});
354 if ($inType eq 'buffer' || $inType eq 'code') {
355 *$obj->{Buffer} = $inValue ;
356 *$obj->{InputEvent} = $inValue
357 if $inType eq 'code' ;
360 if ($inType eq 'handle') {
361 *$obj->{FH} = $inValue ;
362 *$obj->{Handle} = 1 ;
364 # Need to rewind for Scan
365 *$obj->{FH}->seek(0, SEEK_SET)
366 if $got->value('Scan');
370 $mode = '+<' if $got->value('Scan');
371 *$obj->{StdIO} = ($inValue eq '-');
372 *$obj->{FH} = new IO::File "$mode $inValue"
373 or return $obj->saveErrorString(undef, "cannot open file '$inValue': $!", $!) ;
376 *$obj->{LineNo} = $. = 0;
377 setBinModeInput(*$obj->{FH}) ;
380 *$obj->{Buffer} = \$buff ;
384 *$obj->{InputLength} = $got->parsed('InputLength')
385 ? $got->value('InputLength')
387 *$obj->{InputLengthRemaining} = $got->value('InputLength');
388 *$obj->{BufferOffset} = 0 ;
389 *$obj->{AutoClose} = $got->value('AutoClose');
390 *$obj->{Strict} = $got->value('Strict');
391 *$obj->{BlockSize} = $got->value('BlockSize');
392 *$obj->{Append} = $got->value('Append');
393 *$obj->{AppendOutput} = $append_mode || $got->value('Append');
394 *$obj->{ConsumeInput} = $got->value('ConsumeInput');
395 *$obj->{Transparent} = $got->value('Transparent');
396 *$obj->{MultiStream} = $got->value('MultiStream');
398 # TODO - move these two into RawDeflate
399 *$obj->{Scan} = $got->value('Scan');
400 *$obj->{ParseExtra} = $got->value('ParseExtra')
401 || $got->value('Strict') ;
403 *$obj->{Prime} = $got->value('Prime') || '' ;
404 *$obj->{Pending} = '';
406 *$obj->{PlainBytesRead} = 0;
407 *$obj->{InflatedBytesRead} = 0;
408 *$obj->{UnCompSize} = new U64;
409 *$obj->{CompSize} = new U64;
410 *$obj->{TotalInflatedBytesRead} = 0;
411 *$obj->{NewStream} = 0 ;
412 *$obj->{EventEof} = 0 ;
413 *$obj->{ClassName} = $class ;
414 *$obj->{Params} = $got ;
416 if (*$obj->{ConsumeInput}) {
422 my $status = $obj->mkUncomp($class, $got);
425 unless defined $status;
429 unless *$obj->{Transparent};
432 *$obj->{Type} = 'plain';
434 #$status = $obj->mkIdentityUncomp($class, $got);
435 $obj->pushBack(*$obj->{HeaderPending}) ;
438 push @{ *$obj->{InfoList} }, *$obj->{Info} ;
440 $obj->saveStatus(STATUS_OK) ;
451 my $inType = whatIsInput($_[0], $_[1]);
453 $self->croakError("$from: input parameter not a filename, filehandle, array ref or scalar ref")
456 if ($inType eq 'filename' )
458 $self->croakError("$from: input filename is undef or null string")
459 if ! defined $_[0] || $_[0] eq '' ;
461 if ($_[0] ne '-' && ! -e $_[0] )
463 return $self->saveErrorString(undef,
464 "input file '$_[0]' does not exist", STATUS_ERROR);
476 my $class = (caller)[0] ;
477 my $name = (caller(1))[3] ;
479 $obj->croakError("$name: expected at least 1 parameters\n")
487 my $x = new Validator($class, *$obj->{Error}, $name, $input, $output)
490 push @_, $output if $haveOut && $x->{Hash};
492 *$obj->{OneShot} = 1 ;
494 my $got = $obj->checkParams($name, undef, @_)
497 if ($got->parsed('TrailingData'))
499 *$obj->{TrailingData} = $got->value('TrailingData');
502 *$obj->{MultiStream} = $got->value('MultiStream');
503 $got->value('MultiStream', 0);
509 # while (my($k, $v) = each %$input)
512 # unless defined $v ;
514 # $obj->_singleTarget($x, $k, $v, @_)
518 # return keys %$input ;
524 foreach my $pair (@{ $x->{Pairs} })
526 my ($from, $to) = @$pair ;
527 $obj->_singleTarget($x, $from, $to, @_)
531 return scalar @{ $x->{Pairs} } ;
534 if (! $x->{oneOutput} )
536 my $inFile = ($x->{inType} eq 'filenames'
537 || $x->{inType} eq 'filename');
539 $x->{inType} = $inFile ? 'filename' : 'buffer';
541 foreach my $in ($x->{oneInput} ? $input : @$input)
546 $obj->_singleTarget($x, $in, $output, @_)
553 # finally the 1 to 1 and n to 1
554 return $obj->_singleTarget($x, $input, $output, @_);
556 croak "should not be here" ;
564 ${ $x->{Error} } = $string ;
577 $x->{buff} = \$buff ;
580 if ($x->{outType} eq 'filename') {
583 if $x->{Got}->value('Append') ;
584 $x->{fh} = new IO::File "$mode $output"
585 or return retErr($x, "cannot open file '$output': $!") ;
586 binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut');
590 elsif ($x->{outType} eq 'handle') {
592 binmode $x->{fh} if $x->{Got}->valueOrDefault('BinModeOut');
593 if ($x->{Got}->value('Append')) {
594 seek($x->{fh}, 0, SEEK_END)
595 or return retErr($x, "Cannot seek to end of output filehandle: $!") ;
600 elsif ($x->{outType} eq 'buffer' )
603 unless $x->{Got}->value('Append');
604 $x->{buff} = $output ;
609 defined $self->_rd2($x, $input, $output)
614 for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input)
616 defined $self->_rd2($x, $element, $output)
622 if ( ($x->{outType} eq 'filename' && $output ne '-') ||
623 ($x->{outType} eq 'handle' && $x->{Got}->value('AutoClose'))) {
625 or return retErr($x, $!);
639 my $z = createSelfTiedObject($x->{Class}, *$self->{Error});
641 $z->_create($x->{Got}, 1, $input, @_)
649 while (($status = $z->read($x->{buff})) > 0) {
651 print $fh ${ $x->{buff} }
652 or return $z->saveErrorString(undef, "Error writing to output file: $!", $!);
653 ${ $x->{buff} } = '' ;
657 if (! $x->{oneOutput} ) {
658 my $ot = $x->{outType} ;
661 { push @$output, $x->{buff} }
662 elsif ($ot eq 'hash')
663 { $output->{$input} = $x->{buff} }
670 unless *$self->{MultiStream};
672 $status = $z->nextStream();
675 unless $status == 1 ;
678 return $z->closeError(undef)
681 ${ *$self->{TrailingData} } = $z->trailingData()
682 if defined *$self->{TrailingData} ;
692 return $_[0] if ref($_[0]);
706 wantarray ? @{ *$self->{InfoList} } : *$self->{Info};
715 if (defined *$self->{CompressedInputLength}) {
716 if (*$self->{CompressedInputLengthRemaining} == 0) {
717 delete *$self->{CompressedInputLength};
718 *$self->{CompressedInputLengthDone} = 1;
721 $size = min($size, *$self->{CompressedInputLengthRemaining} );
722 *$self->{CompressedInputLengthRemaining} -= $size ;
725 my $status = $self->smartRead($buff, $size) ;
726 return $self->saveErrorString(STATUS_ERROR, "Error Reading Data")
730 *$self->{Closed} = 1 ;
731 *$self->{EndStream} = 1 ;
732 return $self->saveErrorString(STATUS_ERROR, "unexpected end of file", STATUS_ERROR);
746 # >0 - ok, number of bytes read
752 return G_EOF if *$self->{Closed} ;
753 #return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
754 return G_EOF if *$self->{EndStream} ;
757 my $scan_mode = shift ;
759 if (*$self->{Plain}) {
761 my $len = $self->smartRead(\$tmp_buff, *$self->{BlockSize}) ;
763 return $self->saveErrorString(G_ERR, "Error reading data: $!", $!)
767 *$self->{EndStream} = 1 ;
770 *$self->{PlainBytesRead} += $len ;
771 $$buffer .= $tmp_buff;
777 if (*$self->{NewStream}) {
779 $self->gotoNextStream() > 0
782 # For the headers that actually uncompressed data, put the
783 # uncompressed data into the output buffer.
784 $$buffer .= *$self->{Pending} ;
785 my $len = length *$self->{Pending} ;
786 *$self->{Pending} = '';
792 my $status = $self->readBlock(\$temp_buf, *$self->{BlockSize}, $outSize) ;
794 if $status == STATUS_ERROR ;
797 if ($status == STATUS_OK) {
798 my $beforeC_len = length $temp_buf;
799 my $before_len = defined $$buffer ? length $$buffer : 0 ;
800 $status = *$self->{Uncomp}->uncompr(\$temp_buf, $buffer,
801 defined *$self->{CompressedInputLengthDone} ||
802 $self->smartEof(), $outSize);
804 return $self->saveErrorString(G_ERR, *$self->{Uncomp}{Error}, *$self->{Uncomp}{ErrorNo})
805 if $self->saveStatus($status) == STATUS_ERROR;
807 $self->postBlockChk($buffer, $before_len) == STATUS_OK
810 $self->filterUncompressed($buffer);
812 # TODO uncompress filter goes here
815 $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) ;
825 if ($status == STATUS_ENDSTREAM) {
827 *$self->{EndStream} = 1 ;
828 $self->pushBack($temp_buf) ;
832 my $trailer_size = *$self->{Info}{TrailerLength} ;
834 if (*$self->{Info}{TrailerLength})
836 $got = $self->smartRead(\$trailer, $trailer_size) ;
839 if ($got == $trailer_size) {
840 $self->chkTrailer($trailer) == STATUS_OK
844 return $self->TrailerError("trailer truncated. Expected " .
845 "$trailer_size bytes, got $got")
847 $self->pushBack($trailer) ;
850 # TODO - if want to file file pointer, do it here
852 if (! $self->smartEof()) {
853 *$self->{NewStream} = 1 ;
855 if (*$self->{MultiStream}) {
856 *$self->{EndStream} = 0 ;
864 # return the number of uncompressed bytes read
872 return *$self->{Uncomp}->reset();
875 sub filterUncompressed
882 # return *$self->{NewStream} ||
883 # *$self->{EndStream} ;
890 my $status = $self->gotoNextStream();
894 *$self->{TotalInflatedBytesRead} = 0 ;
895 *$self->{LineNo} = $. = 0;
904 if (! *$self->{NewStream}) {
908 # TODO - make this more efficient if know the offset for the end of
909 # the stream and seekable
910 $status = $self->read($buffer)
917 *$self->{NewStream} = 0 ;
918 *$self->{EndStream} = 0 ;
920 *$self->{UnCompSize}->reset();
921 *$self->{CompSize}->reset();
923 my $magic = $self->ckMagic();
926 *$self->{EndStream} = 1 ;
930 *$self->{Info} = $self->readHeader($magic);
932 if ( ! defined *$self->{Info} ) {
933 *$self->{EndStream} = 1 ;
937 push @{ *$self->{InfoList} }, *$self->{Info} ;
945 return 1 if ! defined *$self->{InfoList};
946 return scalar @{ *$self->{InfoList} } ;
952 # >0 - ok, number of bytes read
958 return G_EOF if *$self->{Closed} ;
959 return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
963 #$self->croakError(*$self->{ClassName} .
964 # "::read: buffer parameter is read-only")
965 # if Compress::Raw::Zlib::_readonly_ref($_[0]);
968 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
969 if readonly(${ $_[0] });
971 $self->croakError(*$self->{ClassName} . "::read: not a scalar reference $_[0]" )
972 unless ref $_[0] eq 'SCALAR' ;
976 $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only")
983 my $offset = $_[2] || 0;
985 # the core read will return 0 if asked for 0 bytes
986 return 0 if defined $length && $length == 0 ;
988 $length = $length || 0;
990 $self->croakError(*$self->{ClassName} . "::read: length parameter is negative")
993 $$buffer = '' unless *$self->{AppendOutput} || $offset ;
995 # Short-circuit if this is a simple read, with no length
996 # or offset specified.
997 unless ( $length || $offset) {
998 if (length *$self->{Pending}) {
999 $$buffer .= *$self->{Pending} ;
1000 my $len = length *$self->{Pending};
1001 *$self->{Pending} = '' ;
1006 $len = $self->_raw_read($buffer)
1007 while ! *$self->{EndStream} && $len == 0 ;
1012 # Need to jump through more hoops - either length or offset
1013 # or both are specified.
1014 my $out_buffer = \*$self->{Pending} ;
1016 while (! *$self->{EndStream} && length($$out_buffer) < $length)
1018 my $buf_len = $self->_raw_read($out_buffer);
1023 $length = length $$out_buffer
1024 if length($$out_buffer) < $length ;
1030 $$buffer .= "\x00" x ($offset - length($$buffer))
1031 if $offset > length($$buffer) ;
1032 #substr($$buffer, $offset) = substr($$out_buffer, 0, $length, '') ;
1033 substr($$buffer, $offset) = substr($$out_buffer, 0, $length) ;
1034 substr($$out_buffer, 0, $length) = '' ;
1037 #$$buffer .= substr($$out_buffer, 0, $length, '') ;
1038 $$buffer .= substr($$out_buffer, 0, $length) ;
1039 substr($$out_buffer, 0, $length) = '' ;
1050 if ( ! defined $/ ) {
1052 1 while $self->read($data) > 0 ;
1057 if ( ref $/ eq 'SCALAR' && ${$/} =~ /^\d+$/ && ${$/} > 0) {
1058 my $reclen = ${$/} ;
1060 $self->read($data, $reclen) ;
1065 if ( ! length $/ ) {
1067 while ($self->read($paragraph) > 0 ) {
1068 if ($paragraph =~ s/^(.*?\n\n+)//s) {
1069 *$self->{Pending} = $paragraph ;
1077 # $/ isn't empty, or a reference, so it's Line Mode.
1081 my $p = \*$self->{Pending} ;
1083 if (length(*$self->{Pending}) &&
1084 ($offset = index(*$self->{Pending}, $/)) >=0) {
1085 my $l = substr(*$self->{Pending}, 0, $offset + length $/ );
1086 substr(*$self->{Pending}, 0, $offset + length $/) = '';
1090 while ($self->read($line) > 0 ) {
1091 my $offset = index($line, $/);
1093 my $l = substr($line, 0, $offset + length $/ );
1094 substr($line, 0, $offset + length $/) = '';
1107 my $current_append = *$self->{AppendOutput} ;
1108 *$self->{AppendOutput} = 1;
1109 my $lineref = $self->_getline();
1110 $. = ++ *$self->{LineNo} if defined $$lineref ;
1111 *$self->{AppendOutput} = $current_append;
1118 $self->croakError(*$self->{ClassName} .
1119 "::getlines: called in scalar context\n") unless wantarray;
1122 while defined($line = $self->getline);
1128 goto &getlines if wantarray;
1136 return $buf if $self->read($buf, 1);
1143 *$self->{Pending} = "" unless defined *$self->{Pending} ;
1144 *$self->{Pending} = $_[0] . *$self->{Pending} ;
1152 if (defined *$self->{FH} || defined *$self->{InputEvent} ) {
1153 return *$self->{Prime} ;
1156 my $buf = *$self->{Buffer} ;
1157 my $offset = *$self->{BufferOffset} ;
1158 return substr($$buf, $offset) ;
1167 return (*$self->{Closed} ||
1168 (!length *$self->{Pending}
1169 && ( $self->smartEof() || *$self->{EndStream}))) ;
1177 if (*$self->{Plain}) {
1178 $in = *$self->{PlainBytesRead} ;
1181 $in = *$self->{TotalInflatedBytesRead} ;
1184 my $pending = length *$self->{Pending} ;
1186 return 0 if $pending > $in ;
1187 return $in - $pending ;
1192 # todo - what to do if close is called before the end of the gzip file
1193 # do we remember any trailing data?
1196 return 1 if *$self->{Closed} ;
1203 if (defined *$self->{FH}) {
1204 if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) {
1205 #if ( *$self->{AutoClose}) {
1208 $status = *$self->{FH}->close();
1209 return $self->saveErrorString(0, $!, $!)
1210 if !*$self->{InNew} && $self->saveStatus($!) != 0 ;
1212 delete *$self->{FH} ;
1215 *$self->{Closed} = 1 ;
1229 my $position = shift;
1230 my $whence = shift ;
1232 my $here = $self->tell() ;
1236 if ($whence == SEEK_SET) {
1237 $target = $position ;
1239 elsif ($whence == SEEK_CUR) {
1240 $target = $here + $position ;
1242 elsif ($whence == SEEK_END) {
1243 $target = $position ;
1244 $self->croakError(*$self->{ClassName} . "::seek: SEEK_END not allowed") ;
1247 $self->croakError(*$self->{ClassName} ."::seek: unknown value, $whence, for whence parameter");
1250 # short circuit if seeking to current offset
1251 return 1 if $target == $here ;
1253 # Outlaw any attempt to seek backwards
1254 $self->croakError( *$self->{ClassName} ."::seek: cannot seek backwards")
1255 if $target < $here ;
1257 # Walk the file to the new offset
1258 my $offset = $target - $here ;
1261 $self->read($buffer, $offset) == $offset
1270 return defined *$self->{FH}
1271 ? fileno *$self->{FH}
1278 # my $self = shift ;
1279 # return defined *$self->{FH}
1280 # ? binmode *$self->{FH}
1287 return ! *$self->{Closed} ;
1293 return defined *$self->{FH}
1294 ? *$self->{FH}->autoflush(@_)
1298 sub input_line_number
1301 my $last = *$self->{LineNo};
1302 $. = *$self->{LineNo} = $_[1] if @_ ;
1307 *BINMODE = \&binmode;
1320 #return sub { croak "$name Not Available" ; } ;
1321 return sub { croak "$name Not Available: File opened only for intput" ; } ;
1325 *print = _notAvailable('print');
1326 *PRINT = _notAvailable('print');
1327 *printf = _notAvailable('printf');
1328 *PRINTF = _notAvailable('printf');
1329 *write = _notAvailable('write');
1330 *WRITE = _notAvailable('write');
1333 #*syswrite = \&_notAvailable;
1337 package IO::Uncompress::Base ;
1346 IO::Uncompress::Base - Base Class for IO::Uncompress modules
1351 use IO::Uncompress::Base ;
1356 This module is not intended for direct use in application code. Its sole
1357 purpose if to to be sub-classed by IO::Unompress modules.
1364 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>
1366 L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1368 L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1369 L<Archive::Tar|Archive::Tar>,
1370 L<IO::Zlib|IO::Zlib>
1378 This module was written by Paul Marquess, F<pmqs@cpan.org>.
1382 =head1 MODIFICATION HISTORY
1384 See the Changes file.
1386 =head1 COPYRIGHT AND LICENSE
1388 Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
1390 This program is free software; you can redistribute it and/or
1391 modify it under the same terms as Perl itself.