Cleaing up for production release
[archive-zip.git] / lib / Archive / Zip / StringMember.pm
bloba8e6944c5ed412860498b9fb99d35edcdab3c56a
1 package Archive::Zip::StringMember;
3 use strict;
4 use vars qw( $VERSION @ISA );
6 BEGIN {
7 $VERSION = '1.28';
8 @ISA = qw( Archive::Zip::Member );
11 use Archive::Zip qw(
12 :CONSTANTS
13 :ERROR_CODES
16 # Create a new string member. Default is COMPRESSION_STORED.
17 # Can take a ref to a string as well.
18 sub _newFromString {
19 my $class = shift;
20 my $string = shift;
21 my $name = shift;
22 my $self = $class->new(@_);
23 $self->contents($string);
24 $self->fileName($name) if defined($name);
26 # Set the file date to now
27 $self->setLastModFileDateTimeFromUnix( time() );
28 $self->unixFileAttributes( $self->DEFAULT_FILE_PERMISSIONS );
29 return $self;
32 sub _become {
33 my $self = shift;
34 my $newClass = shift;
35 return $self if ref($self) eq $newClass;
36 delete( $self->{'contents'} );
37 return $self->SUPER::_become($newClass);
40 # Get or set my contents. Note that we do not call the superclass
41 # version of this, because it calls us.
42 sub contents {
43 my $self = shift;
44 my $string = shift;
45 if ( defined($string) ) {
46 $self->{'contents'} =
47 pack( 'C0a*', ( ref($string) eq 'SCALAR' ) ? $$string : $string );
48 $self->{'uncompressedSize'} = $self->{'compressedSize'} =
49 length( $self->{'contents'} );
50 $self->{'compressionMethod'} = COMPRESSION_STORED;
52 return $self->{'contents'};
55 # Return bytes read. Note that first parameter is a ref to a buffer.
56 # my $data;
57 # my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
58 sub _readRawChunk {
59 my ( $self, $dataRef, $chunkSize ) = @_;
60 $$dataRef = substr( $self->contents(), $self->_readOffset(), $chunkSize );
61 return ( length($$dataRef), AZ_OK );