1package Archive::Zip::MockFileHandle; 2 3# Output file handle that calls a custom write routine 4# Ned Konz, March 2000 5# This is provided to help with writing zip files 6# when you have to process them a chunk at a time. 7 8use strict; 9 10use vars qw{$VERSION}; 11 12BEGIN { 13 $VERSION = '1.30'; 14 $VERSION = eval $VERSION; 15} 16 17sub new { 18 my $class = shift || __PACKAGE__; 19 $class = ref($class) || $class; 20 my $self = bless( 21 { 22 'position' => 0, 23 'size' => 0 24 }, 25 $class 26 ); 27 return $self; 28} 29 30sub eof { 31 my $self = shift; 32 return $self->{'position'} >= $self->{'size'}; 33} 34 35# Copy given buffer to me 36sub print { 37 my $self = shift; 38 my $bytes = join( '', @_ ); 39 my $bytesWritten = $self->writeHook($bytes); 40 if ( $self->{'position'} + $bytesWritten > $self->{'size'} ) { 41 $self->{'size'} = $self->{'position'} + $bytesWritten; 42 } 43 $self->{'position'} += $bytesWritten; 44 return $bytesWritten; 45} 46 47# Called on each write. 48# Override in subclasses. 49# Return number of bytes written (0 on error). 50sub writeHook { 51 my $self = shift; 52 my $bytes = shift; 53 return length($bytes); 54} 55 56sub binmode { 1 } 57 58sub close { 1 } 59 60sub clearerr { 1 } 61 62# I'm write-only! 63sub read { 0 } 64 65sub tell { return shift->{'position'} } 66 67sub opened { 1 } 68 691; 70