home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _953b3dc34a35a2865bf4123508ef6901 < prev    next >
Encoding:
Text File  |  2004-06-01  |  1.2 KB  |  69 lines

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