Fixed: #15026: AddTree does not include files with german umlauts in the filename
[archive-zip.git] / lib / Archive / Zip / StringMember.pm
blobdca1e311e6fababd785acba38edb3374f5907a73
1 package Archive::Zip::StringMember;
3 use strict;
4 use vars qw( $VERSION @ISA );
6 BEGIN {
7 $VERSION = '1.27_01';
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 require Encode;
23 $name = Encode::encode( 'cp437', $name );
24 my $self = $class->new(@_);
25 $self->contents($string);
26 $self->fileName($name) if defined($name);
28 # Set the file date to now
29 $self->setLastModFileDateTimeFromUnix( time() );
30 $self->unixFileAttributes( $self->DEFAULT_FILE_PERMISSIONS );
31 return $self;
34 sub _become {
35 my $self = shift;
36 my $newClass = shift;
37 return $self if ref($self) eq $newClass;
38 delete( $self->{'contents'} );
39 return $self->SUPER::_become($newClass);
42 # Get or set my contents. Note that we do not call the superclass
43 # version of this, because it calls us.
44 sub contents {
45 my $self = shift;
46 my $string = shift;
47 if ( defined($string) ) {
48 $self->{'contents'} =
49 pack( 'C0a*', ( ref($string) eq 'SCALAR' ) ? $$string : $string );
50 $self->{'uncompressedSize'} = $self->{'compressedSize'} =
51 length( $self->{'contents'} );
52 $self->{'compressionMethod'} = COMPRESSION_STORED;
54 return $self->{'contents'};
57 # Return bytes read. Note that first parameter is a ref to a buffer.
58 # my $data;
59 # my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
60 sub _readRawChunk {
61 my ( $self, $dataRef, $chunkSize ) = @_;
62 $$dataRef = substr( $self->contents(), $self->_readOffset(), $chunkSize );
63 return ( length($$dataRef), AZ_OK );