Add ARM files
[dh-make-perl] / dev / arm / libarchive-zip-perl / libarchive-zip-perl-1.18 / debian / libarchive-zip-perl / usr / share / perl5 / Archive / Zip / MockFileHandle.pm
1 package 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
8 use strict;
9
10 use vars qw{$VERSION};
11
12 BEGIN {
13     $VERSION = '1.18';
14     $VERSION = eval $VERSION;
15 }
16
17 sub 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
30 sub eof {
31     my $self = shift;
32     return $self->{'position'} >= $self->{'size'};
33 }
34
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;
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).
50 sub writeHook {
51     my $self  = shift;
52     my $bytes = shift;
53     return length($bytes);
54 }
55
56 sub binmode { 1 }
57
58 sub close { 1 }
59
60 sub clearerr { 1 }
61
62 # I'm write-only!
63 sub read { 0 }
64
65 sub tell { return shift->{'position'} }
66
67 sub opened { 1 }
68
69 1;