Cleaing up for production release
[archive-zip.git] / lib / Archive / Zip / MockFileHandle.pm
blobf7c66f8bbb1b86cee4c3641c0f968dafba3dc618
1 package Archive::Zip::MockFileHandle;
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.
8 use strict;
10 use vars qw{$VERSION};
12 BEGIN {
13 $VERSION = '1.28';
14 $VERSION = eval $VERSION;
17 sub new {
18 my $class = shift || __PACKAGE__;
19 $class = ref($class) || $class;
20 my $self = bless(
22 'position' => 0,
23 'size' => 0
25 $class
27 return $self;
30 sub eof {
31 my $self = shift;
32 return $self->{'position'} >= $self->{'size'};
35 # Copy given buffer to me
36 sub 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;
43 $self->{'position'} += $bytesWritten;
44 return $bytesWritten;
47 # Called on each write.
48 # Override in subclasses.
49 # Return number of bytes written (0 on error).
50 sub writeHook {
51 my $self = shift;
52 my $bytes = shift;
53 return length($bytes);
56 sub binmode { 1 }
58 sub close { 1 }
60 sub clearerr { 1 }
62 # I'm write-only!
63 sub read { 0 }
65 sub tell { return shift->{'position'} }
67 sub opened { 1 }