Re: [perl #40583] sprintf "%#04X" also uppercases the 0x-prefix
[p5sagit/p5-mst-13.2.git] / ext / Compress / IO / Base / lib / IO / Compress / Base.pm
CommitLineData
25f0751f 1
2package IO::Compress::Base ;
3
4require 5.004 ;
5
6use strict ;
7use warnings;
8
9use IO::Compress::Base::Common;
10
11use IO::File ;
12use Scalar::Util qw(blessed readonly);
13
14#use File::Glob;
15#require Exporter ;
16use Carp ;
17use Symbol;
18use bytes;
19
20our (@ISA, $VERSION, $got_encode);
21#@ISA = qw(Exporter IO::File);
22
e7d45986 23$VERSION = '2.000_13';
25f0751f 24
25#Can't locate object method "SWASHNEW" via package "utf8" (perhaps you forgot to load "utf8"?) at .../ext/Compress-Zlib/Gzip/blib/lib/Compress/Zlib/Common.pm line 16.
26
27#$got_encode = 0;
28#eval
29#{
30# require Encode;
31# Encode->import('encode', 'find_encoding');
32#};
33#
34#$got_encode = 1 unless $@;
35
36sub saveStatus
37{
38 my $self = shift ;
39 ${ *$self->{ErrorNo} } = shift() + 0 ;
40 ${ *$self->{Error} } = '' ;
41
42 return ${ *$self->{ErrorNo} } ;
43}
44
45
46sub saveErrorString
47{
48 my $self = shift ;
49 my $retval = shift ;
50 ${ *$self->{Error} } = shift ;
51 ${ *$self->{ErrorNo} } = shift() + 0 if @_ ;
52
53 return $retval;
54}
55
56sub croakError
57{
58 my $self = shift ;
59 $self->saveErrorString(0, $_[0]);
60 croak $_[0];
61}
62
63sub closeError
64{
65 my $self = shift ;
66 my $retval = shift ;
67
68 my $errno = *$self->{ErrorNo};
69 my $error = ${ *$self->{Error} };
70
71 $self->close();
72
73 *$self->{ErrorNo} = $errno ;
74 ${ *$self->{Error} } = $error ;
75
76 return $retval;
77}
78
79
80
81sub error
82{
83 my $self = shift ;
84 return ${ *$self->{Error} } ;
85}
86
87sub errorNo
88{
89 my $self = shift ;
90 return ${ *$self->{ErrorNo} } ;
91}
92
93
94sub writeAt
95{
96 my $self = shift ;
97 my $offset = shift;
98 my $data = shift;
99
100 if (defined *$self->{FH}) {
101 my $here = tell(*$self->{FH});
102 return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!)
103 if $here < 0 ;
104 seek(*$self->{FH}, $offset, SEEK_SET)
105 or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
106 defined *$self->{FH}->write($data, length $data)
107 or return $self->saveErrorString(undef, $!, $!) ;
108 seek(*$self->{FH}, $here, SEEK_SET)
109 or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
110 }
111 else {
112 substr(${ *$self->{Buffer} }, $offset, length($data)) = $data ;
113 }
114
115 return 1;
116}
117
e7d45986 118sub output
119{
120 my $self = shift ;
121 my $data = shift ;
122 my $last = shift ;
123
124 return 1
125 if length $data == 0 && ! $last ;
126
127 if ( *$self->{FilterEnvelope} ) {
128 *_ = \$data;
129 &{ *$self->{FilterEnvelope} }();
130 }
131
132 if ( defined *$self->{FH} ) {
133 defined *$self->{FH}->write( $data, length $data )
134 or return $self->saveErrorString(0, $!, $!);
135 }
136 else {
137 ${ *$self->{Buffer} } .= $data ;
138 }
139
140 return 1;
141}
142
25f0751f 143sub getOneShotParams
144{
145 return ( 'MultiStream' => [1, 1, Parse_boolean, 1],
146 );
147}
148
149sub checkParams
150{
151 my $self = shift ;
152 my $class = shift ;
153
154 my $got = shift || IO::Compress::Base::Parameters::new();
155
156 $got->parse(
157 {
158 # Generic Parameters
159 'AutoClose' => [1, 1, Parse_boolean, 0],
160 #'Encoding' => [1, 1, Parse_any, undef],
161 'Strict' => [0, 1, Parse_boolean, 1],
162 'Append' => [1, 1, Parse_boolean, 0],
163 'BinModeIn' => [1, 1, Parse_boolean, 0],
164
e7d45986 165 'FilterEnvelope' => [1, 1, Parse_any, undef],
166
25f0751f 167 $self->getExtraParams(),
168 *$self->{OneShot} ? $self->getOneShotParams()
169 : (),
170 },
171 @_) or $self->croakError("${class}: $got->{Error}") ;
172
173 return $got ;
174}
175
176sub _create
177{
178 my $obj = shift;
179 my $got = shift;
180
181 *$obj->{Closed} = 1 ;
182
183 my $class = ref $obj;
184 $obj->croakError("$class: Missing Output parameter")
185 if ! @_ && ! $got ;
186
187 my $outValue = shift ;
188 my $oneShot = 1 ;
189
190 if (! $got)
191 {
192 $oneShot = 0 ;
193 $got = $obj->checkParams($class, undef, @_)
194 or return undef ;
195 }
196
197 my $lax = ! $got->value('Strict') ;
198
199 my $outType = whatIsOutput($outValue);
200
201 $obj->ckOutputParam($class, $outValue)
202 or return undef ;
203
204 if ($outType eq 'buffer') {
205 *$obj->{Buffer} = $outValue;
206 }
207 else {
208 my $buff = "" ;
209 *$obj->{Buffer} = \$buff ;
210 }
211
212 # Merge implies Append
213 my $merge = $got->value('Merge') ;
214 my $appendOutput = $got->value('Append') || $merge ;
e7d45986 215 *$obj->{Append} = $appendOutput;
216 *$obj->{FilterEnvelope} = $got->value('FilterEnvelope') ;
25f0751f 217
218 if ($merge)
219 {
220 # Switch off Merge mode if output file/buffer is empty/doesn't exist
221 if (($outType eq 'buffer' && length $$outValue == 0 ) ||
222 ($outType ne 'buffer' && (! -e $outValue || (-w _ && -z _))) )
223 { $merge = 0 }
224 }
225
226 # If output is a file, check that it is writable
227 if ($outType eq 'filename' && -e $outValue && ! -w _)
228 { return $obj->saveErrorString(undef, "Output file '$outValue' is not writable" ) }
229
25f0751f 230
231
232# TODO - encoding
233# if ($got->parsed('Encoding')) {
234# $obj->croakError("$class: Encode module needed to use -Encoding")
235# if ! $got_encode;
236#
237# my $want_encoding = $got->value('Encoding');
238# my $encoding = find_encoding($want_encoding);
239#
240# $obj->croakError("$class: Encoding '$want_encoding' is not available")
241# if ! $encoding;
242#
243# *$obj->{Encoding} = $encoding;
244# }
245
246 $obj->ckParams($got)
247 or $obj->croakError("${class}: " . $obj->error());
248
249
250 $obj->saveStatus(STATUS_OK) ;
251
252 my $status ;
253 if (! $merge)
254 {
255 *$obj->{Compress} = $obj->mkComp($class, $got)
256 or return undef;
257
e7d45986 258 *$obj->{UnCompSize} = new U64 ;
259 *$obj->{CompSize} = new U64 ;
25f0751f 260
261 if ( $outType eq 'buffer') {
262 ${ *$obj->{Buffer} } = ''
263 unless $appendOutput ;
25f0751f 264 }
265 else {
266 if ($outType eq 'handle') {
267 *$obj->{FH} = $outValue ;
268 setBinModeOutput(*$obj->{FH}) ;
269 $outValue->flush() ;
270 *$obj->{Handle} = 1 ;
271 if ($appendOutput)
272 {
273 seek(*$obj->{FH}, 0, SEEK_END)
274 or return $obj->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
275
276 }
277 }
278 elsif ($outType eq 'filename') {
279 my $mode = '>' ;
280 $mode = '>>'
281 if $appendOutput;
282 *$obj->{FH} = new IO::File "$mode $outValue"
283 or return $obj->saveErrorString(undef, "cannot open file '$outValue': $!", $!) ;
284 *$obj->{StdIO} = ($outValue eq '-');
285 setBinModeOutput(*$obj->{FH}) ;
286 }
25f0751f 287 }
e7d45986 288
289 *$obj->{Header} = $obj->mkHeader($got) ;
290 $obj->output( *$obj->{Header} )
291 or return undef;
25f0751f 292 }
293 else
294 {
295 *$obj->{Compress} = $obj->createMerge($outValue, $outType)
296 or return undef;
297 }
298
299 *$obj->{Closed} = 0 ;
300 *$obj->{AutoClose} = $got->value('AutoClose') ;
301 *$obj->{Output} = $outValue;
302 *$obj->{ClassName} = $class;
303 *$obj->{Got} = $got;
304 *$obj->{OneShot} = 0 ;
305
306 return $obj ;
307}
308
309sub ckOutputParam
310{
311 my $self = shift ;
312 my $from = shift ;
313 my $outType = whatIsOutput($_[0]);
314
315 $self->croakError("$from: output parameter not a filename, filehandle or scalar ref")
316 if ! $outType ;
317
318 $self->croakError("$from: output filename is undef or null string")
319 if $outType eq 'filename' && (! defined $_[0] || $_[0] eq '') ;
320
321 $self->croakError("$from: output buffer is read-only")
322 if $outType eq 'buffer' && readonly(${ $_[0] });
323
324 return 1;
325}
326
327
328sub _def
329{
330 my $obj = shift ;
331
332 my $class= (caller)[0] ;
333 my $name = (caller(1))[3] ;
334
335 $obj->croakError("$name: expected at least 1 parameters\n")
336 unless @_ >= 1 ;
337
338 my $input = shift ;
339 my $haveOut = @_ ;
340 my $output = shift ;
341
342 my $x = new Validator($class, *$obj->{Error}, $name, $input, $output)
343 or return undef ;
344
345 push @_, $output if $haveOut && $x->{Hash};
346
347 *$obj->{OneShot} = 1 ;
348
349 my $got = $obj->checkParams($name, undef, @_)
350 or return undef ;
351
352 $x->{Got} = $got ;
353
354# if ($x->{Hash})
355# {
356# while (my($k, $v) = each %$input)
357# {
358# $v = \$input->{$k}
359# unless defined $v ;
360#
361# $obj->_singleTarget($x, 1, $k, $v, @_)
362# or return undef ;
363# }
364#
365# return keys %$input ;
366# }
367
368 if ($x->{GlobMap})
369 {
370 $x->{oneInput} = 1 ;
371 foreach my $pair (@{ $x->{Pairs} })
372 {
373 my ($from, $to) = @$pair ;
374 $obj->_singleTarget($x, 1, $from, $to, @_)
375 or return undef ;
376 }
377
378 return scalar @{ $x->{Pairs} } ;
379 }
380
381 if (! $x->{oneOutput} )
382 {
383 my $inFile = ($x->{inType} eq 'filenames'
384 || $x->{inType} eq 'filename');
385
386 $x->{inType} = $inFile ? 'filename' : 'buffer';
387
388 foreach my $in ($x->{oneInput} ? $input : @$input)
389 {
390 my $out ;
391 $x->{oneInput} = 1 ;
392
393 $obj->_singleTarget($x, $inFile, $in, \$out, @_)
394 or return undef ;
395
396 push @$output, \$out ;
397 #if ($x->{outType} eq 'array')
398 # { push @$output, \$out }
399 #else
400 # { $output->{$in} = \$out }
401 }
402
403 return 1 ;
404 }
405
406 # finally the 1 to 1 and n to 1
407 return $obj->_singleTarget($x, 1, $input, $output, @_);
408
409 croak "should not be here" ;
410}
411
412sub _singleTarget
413{
414 my $obj = shift ;
415 my $x = shift ;
416 my $inputIsFilename = shift;
417 my $input = shift;
418
419 if ($x->{oneInput})
420 {
421 $obj->getFileInfo($x->{Got}, $input)
422 if isaFilename($input) and $inputIsFilename ;
423
424 my $z = $obj->_create($x->{Got}, @_)
425 or return undef ;
426
427
428 defined $z->_wr2($input, $inputIsFilename)
429 or return $z->closeError(undef) ;
430
431 return $z->close() ;
432 }
433 else
434 {
435 my $afterFirst = 0 ;
436 my $inputIsFilename = ($x->{inType} ne 'array');
437 my $keep = $x->{Got}->clone();
438
439 #for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input)
440 for my $element ( @$input)
441 {
442 my $isFilename = isaFilename($element);
443
444 if ( $afterFirst ++ )
445 {
446 defined addInterStream($obj, $element, $isFilename)
447 or return $obj->closeError(undef) ;
448 }
449 else
450 {
451 $obj->getFileInfo($x->{Got}, $element)
452 if $isFilename;
453
454 $obj->_create($x->{Got}, @_)
455 or return undef ;
456 }
457
458 defined $obj->_wr2($element, $isFilename)
459 or return $obj->closeError(undef) ;
460
461 *$obj->{Got} = $keep->clone();
462 }
463 return $obj->close() ;
464 }
465
466}
467
468sub _wr2
469{
470 my $self = shift ;
471
472 my $source = shift ;
473 my $inputIsFilename = shift;
474
475 my $input = $source ;
476 if (! $inputIsFilename)
477 {
478 $input = \$source
479 if ! ref $source;
480 }
481
482 if ( ref $input && ref $input eq 'SCALAR' )
483 {
484 return $self->syswrite($input, @_) ;
485 }
486
487 if ( ! ref $input || isaFilehandle($input))
488 {
489 my $isFilehandle = isaFilehandle($input) ;
490
491 my $fh = $input ;
492
493 if ( ! $isFilehandle )
494 {
495 $fh = new IO::File "<$input"
496 or return $self->saveErrorString(undef, "cannot open file '$input': $!", $!) ;
497 }
498 binmode $fh if *$self->{Got}->valueOrDefault('BinModeIn') ;
499
500 my $status ;
501 my $buff ;
502 my $count = 0 ;
e7d45986 503 while (($status = read($fh, $buff, 16 * 1024)) > 0) {
25f0751f 504 $count += length $buff;
505 defined $self->syswrite($buff, @_)
506 or return undef ;
507 }
508
509 return $self->saveErrorString(undef, $!, $!)
510 if $status < 0 ;
511
512 if ( (!$isFilehandle || *$self->{AutoClose}) && $input ne '-')
513 {
514 $fh->close()
515 or return undef ;
516 }
517
518 return $count ;
519 }
520
521 croak "Should not be here";
522 return undef;
523}
524
525sub addInterStream
526{
527 my $self = shift ;
528 my $input = shift ;
529 my $inputIsFilename = shift ;
530
531 if (*$self->{Got}->value('MultiStream'))
532 {
533 $self->getFileInfo(*$self->{Got}, $input)
534 #if isaFilename($input) and $inputIsFilename ;
535 if isaFilename($input) ;
536
537 # TODO -- newStream needs to allow gzip/zip header to be modified
538 return $self->newStream();
539 }
540 elsif (*$self->{Got}->value('AutoFlush'))
541 {
542 #return $self->flush(Z_FULL_FLUSH);
543 }
544
545 return 1 ;
546}
547
548sub TIEHANDLE
549{
550 return $_[0] if ref($_[0]);
551 die "OOPS\n" ;
552}
553
554sub UNTIE
555{
556 my $self = shift ;
557}
558
559sub DESTROY
560{
561 my $self = shift ;
562 $self->close() ;
563
e7d45986 564
25f0751f 565 # TODO - memory leak with 5.8.0 - this isn't called until
566 # global destruction
567 #
568 %{ *$self } = () ;
569 undef $self ;
570}
571
572
573
2b4e0969 574sub filterUncompressed
575{
576}
577
25f0751f 578sub syswrite
579{
580 my $self = shift ;
581
582 my $buffer ;
583 if (ref $_[0] ) {
584 $self->croakError( *$self->{ClassName} . "::write: not a scalar reference" )
585 unless ref $_[0] eq 'SCALAR' ;
586 $buffer = $_[0] ;
587 }
588 else {
589 $buffer = \$_[0] ;
590 }
591
592
593 if (@_ > 1) {
594 my $slen = defined $$buffer ? length($$buffer) : 0;
595 my $len = $slen;
596 my $offset = 0;
597 $len = $_[1] if $_[1] < $len;
598
599 if (@_ > 2) {
600 $offset = $_[2] || 0;
601 $self->croakError(*$self->{ClassName} . "::write: offset outside string")
602 if $offset > $slen;
603 if ($offset < 0) {
604 $offset += $slen;
605 $self->croakError( *$self->{ClassName} . "::write: offset outside string") if $offset < 0;
606 }
607 my $rem = $slen - $offset;
608 $len = $rem if $rem < $len;
609 }
610
611 $buffer = \substr($$buffer, $offset, $len) ;
612 }
613
614 return 0 if ! defined $$buffer || length $$buffer == 0 ;
615
616 my $buffer_length = defined $$buffer ? length($$buffer) : 0 ;
e7d45986 617 *$self->{UnCompSize}->add($buffer_length) ;
25f0751f 618
2b4e0969 619 $self->filterUncompressed($buffer);
620
25f0751f 621# if (*$self->{Encoding}) {
622# $$buffer = *$self->{Encoding}->encode($$buffer);
623# }
624
e7d45986 625 my $outBuffer='';
626 my $status = *$self->{Compress}->compr($buffer, $outBuffer) ;
25f0751f 627
628 return $self->saveErrorString(undef, *$self->{Compress}{Error},
629 *$self->{Compress}{ErrorNo})
630 if $status == STATUS_ERROR;
631
e7d45986 632 *$self->{CompSize}->add(length $outBuffer) ;
25f0751f 633
e7d45986 634 $self->output($outBuffer)
635 or return undef;
25f0751f 636
637 return $buffer_length;
638}
639
640sub print
641{
642 my $self = shift;
643
644 #if (ref $self) {
645 # $self = *$self{GLOB} ;
646 #}
647
648 if (defined $\) {
649 if (defined $,) {
650 defined $self->syswrite(join($,, @_) . $\);
651 } else {
652 defined $self->syswrite(join("", @_) . $\);
653 }
654 } else {
655 if (defined $,) {
656 defined $self->syswrite(join($,, @_));
657 } else {
658 defined $self->syswrite(join("", @_));
659 }
660 }
661}
662
663sub printf
664{
665 my $self = shift;
666 my $fmt = shift;
667 defined $self->syswrite(sprintf($fmt, @_));
668}
669
670
671
672sub flush
673{
674 my $self = shift ;
675
e7d45986 676 my $outBuffer='';
677 my $status = *$self->{Compress}->flush($outBuffer, @_) ;
25f0751f 678 return $self->saveErrorString(0, *$self->{Compress}{Error},
679 *$self->{Compress}{ErrorNo})
680 if $status == STATUS_ERROR;
681
682 if ( defined *$self->{FH} ) {
683 *$self->{FH}->clearerr();
e7d45986 684 }
685
686 *$self->{CompSize}->add(length $outBuffer) ;
687
688 $self->output($outBuffer)
689 or return 0;
690
691 if ( defined *$self->{FH} ) {
25f0751f 692 defined *$self->{FH}->flush()
693 or return $self->saveErrorString(0, $!, $!);
25f0751f 694 }
695
696 return 1;
697}
698
699sub newStream
700{
701 my $self = shift ;
702
703 $self->_writeTrailer()
704 or return 0 ;
705
706 my $got = $self->checkParams('newStream', *$self->{Got}, @_)
707 or return 0 ;
708
709 $self->ckParams($got)
710 or $self->croakError("newStream: $self->{Error}");
711
712 *$self->{Header} = $self->mkHeader($got) ;
e7d45986 713 $self->output(*$self->{Header} )
714 or return 0;
25f0751f 715
2b4e0969 716 my $status = $self->reset() ;
25f0751f 717 return $self->saveErrorString(0, *$self->{Compress}{Error},
718 *$self->{Compress}{ErrorNo})
719 if $status == STATUS_ERROR;
720
e7d45986 721 *$self->{UnCompSize}->reset();
722 *$self->{CompSize}->reset();
25f0751f 723
724 return 1 ;
725}
726
2b4e0969 727sub reset
728{
729 my $self = shift ;
730 return *$self->{Compress}->reset() ;
731}
732
25f0751f 733sub _writeTrailer
734{
735 my $self = shift ;
736
e7d45986 737 my $trailer = '';
738
739 my $status = *$self->{Compress}->close($trailer) ;
25f0751f 740 return $self->saveErrorString(0, *$self->{Compress}{Error}, *$self->{Compress}{ErrorNo})
741 if $status == STATUS_ERROR;
742
e7d45986 743 *$self->{CompSize}->add(length $trailer) ;
744
745 $trailer .= $self->mkTrailer();
25f0751f 746 defined $trailer
747 or return 0;
748
e7d45986 749 return $self->output($trailer);
25f0751f 750}
751
752sub _writeFinalTrailer
753{
754 my $self = shift ;
755
e7d45986 756 return $self->output($self->mkFinalTrailer());
25f0751f 757}
758
759sub close
760{
761 my $self = shift ;
762
763 return 1 if *$self->{Closed} || ! *$self->{Compress} ;
764 *$self->{Closed} = 1 ;
765
766 untie *$self
767 if $] >= 5.008 ;
768
769 $self->_writeTrailer()
770 or return 0 ;
771
772 $self->_writeFinalTrailer()
773 or return 0 ;
774
e7d45986 775 $self->output( "", 1 )
776 or return 0;
777
25f0751f 778 if (defined *$self->{FH}) {
e7d45986 779
25f0751f 780 #if (! *$self->{Handle} || *$self->{AutoClose}) {
781 if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) {
782 $! = 0 ;
783 *$self->{FH}->close()
784 or return $self->saveErrorString(0, $!, $!);
785 }
786 delete *$self->{FH} ;
787 # This delete can set $! in older Perls, so reset the errno
788 $! = 0 ;
789 }
790
791 return 1;
792}
793
794
795#sub total_in
796#sub total_out
797#sub msg
798#
799#sub crc
800#{
801# my $self = shift ;
802# return *$self->{Compress}->crc32() ;
803#}
804#
805#sub msg
806#{
807# my $self = shift ;
808# return *$self->{Compress}->msg() ;
809#}
810#
811#sub dict_adler
812#{
813# my $self = shift ;
814# return *$self->{Compress}->dict_adler() ;
815#}
816#
817#sub get_Level
818#{
819# my $self = shift ;
820# return *$self->{Compress}->get_Level() ;
821#}
822#
823#sub get_Strategy
824#{
825# my $self = shift ;
826# return *$self->{Compress}->get_Strategy() ;
827#}
828
829
830sub tell
831{
832 my $self = shift ;
833
e7d45986 834 return *$self->{UnCompSize}->get32bit() ;
25f0751f 835}
836
837sub eof
838{
839 my $self = shift ;
840
841 return *$self->{Closed} ;
842}
843
844
845sub seek
846{
847 my $self = shift ;
848 my $position = shift;
849 my $whence = shift ;
850
851 my $here = $self->tell() ;
852 my $target = 0 ;
853
854 #use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
855 use IO::Handle ;
856
857 if ($whence == IO::Handle::SEEK_SET) {
858 $target = $position ;
859 }
860 elsif ($whence == IO::Handle::SEEK_CUR || $whence == IO::Handle::SEEK_END) {
861 $target = $here + $position ;
862 }
863 else {
864 $self->croakError(*$self->{ClassName} . "::seek: unknown value, $whence, for whence parameter");
865 }
866
867 # short circuit if seeking to current offset
868 return 1 if $target == $here ;
869
870 # Outlaw any attempt to seek backwards
871 $self->croakError(*$self->{ClassName} . "::seek: cannot seek backwards")
872 if $target < $here ;
873
874 # Walk the file to the new offset
875 my $offset = $target - $here ;
876
877 my $buffer ;
878 defined $self->syswrite("\x00" x $offset)
879 or return 0;
880
881 return 1 ;
882}
883
884sub binmode
885{
886 1;
887# my $self = shift ;
888# return defined *$self->{FH}
889# ? binmode *$self->{FH}
890# : 1 ;
891}
892
893sub fileno
894{
895 my $self = shift ;
896 return defined *$self->{FH}
897 ? *$self->{FH}->fileno()
898 : undef ;
899}
900
901sub opened
902{
903 my $self = shift ;
904 return ! *$self->{Closed} ;
905}
906
907sub autoflush
908{
909 my $self = shift ;
910 return defined *$self->{FH}
911 ? *$self->{FH}->autoflush(@_)
912 : undef ;
913}
914
915sub input_line_number
916{
917 return undef ;
918}
919
920
921sub _notAvailable
922{
923 my $name = shift ;
924 return sub { croak "$name Not Available: File opened only for output" ; } ;
925}
926
927*read = _notAvailable('read');
928*READ = _notAvailable('read');
929*readline = _notAvailable('readline');
930*READLINE = _notAvailable('readline');
931*getc = _notAvailable('getc');
932*GETC = _notAvailable('getc');
933
934*FILENO = \&fileno;
935*PRINT = \&print;
936*PRINTF = \&printf;
937*WRITE = \&syswrite;
938*write = \&syswrite;
939*SEEK = \&seek;
940*TELL = \&tell;
941*EOF = \&eof;
942*CLOSE = \&close;
943*BINMODE = \&binmode;
944
945#*sysread = \&_notAvailable;
946#*syswrite = \&_write;
947
9481;
949
950__END__
951
952=head1 NAME
953
954
955IO::Compress::Base - Base Class for IO::Compress modules
956
957
958=head1 SYNOPSIS
959
960 use IO::Compress::Base ;
961
962=head1 DESCRIPTION
963
964
965This module is not intended for direct use in application code. Its sole
966purpose if to to be sub-classed by IO::Compress modules.
967
968
969
970
971=head1 SEE ALSO
972
973L<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::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
974
975L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
976
977L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
978L<Archive::Tar|Archive::Tar>,
979L<IO::Zlib|IO::Zlib>
980
981
982
983
984
25f0751f 985=head1 AUTHOR
986
cb7abd7f 987This module was written by Paul Marquess, F<pmqs@cpan.org>.
25f0751f 988
989
990
991=head1 MODIFICATION HISTORY
992
993See the Changes file.
994
995=head1 COPYRIGHT AND LICENSE
25f0751f 996
997Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
998
999This program is free software; you can redistribute it and/or
1000modify it under the same terms as Perl itself.
1001
1002