File Coverage

blib/lib/Archive/Zip/NewFileMember.pm
Criterion Covered Total %
statement 43 43 100.0
branch 12 18 66.6
condition 4 9 44.4
subroutine 8 8 100.0
pod 2 2 100.0
total 69 80 86.2


line stmt bran cond sub pod time code
1             package Archive::Zip::NewFileMember;
2              
3 26     26   178 use strict;
  26         63  
  26         887  
4 26     26   1084 use vars qw( $VERSION @ISA );
  26         813  
  26         1619  
5              
6             BEGIN {
7 26     26   81 $VERSION = '1.66';
8 26         1114 @ISA = qw ( Archive::Zip::FileMember );
9             }
10              
11 26         14551 use Archive::Zip qw(
12             :CONSTANTS
13             :ERROR_CODES
14             :UTILITY_METHODS
15 26     26   192 );
  26         53  
16              
17             # Given a file name, set up for eventual writing.
18             sub _newFromFileNamed {
19 314     314   410 my $class = shift;
20 314         407 my $fileName = shift; # local FS format
21 314         388 my $newName = shift;
22 314 100       573 $newName = _asZipDirName($fileName) unless defined($newName);
23 314 50 33     5436 return undef unless (stat($fileName) && -r _ && !-d _ );
      33        
24 314         1561 my $self = $class->new(@_);
25 314         643 $self->{'fileName'} = $newName;
26 314         561 $self->{'externalFileName'} = $fileName;
27 314         423 $self->{'compressionMethod'} = COMPRESSION_STORED;
28 314         724 my @stat = stat(_);
29 314         545 $self->{'compressedSize'} = $self->{'uncompressedSize'} = $stat[7];
30 314 100       634 $self->desiredCompressionMethod(
31             ($self->compressedSize() > 0)
32             ? COMPRESSION_DEFLATED
33             : COMPRESSION_STORED
34             );
35 314         708 $self->unixFileAttributes($stat[2]);
36 314         706 $self->setLastModFileDateTimeFromUnix($stat[9]);
37 314         12391 $self->isTextFile(-T _ );
38 314         866 return $self;
39             }
40              
41             sub rewindData {
42 69     69 1 128 my $self = shift;
43              
44 69         200 my $status = $self->SUPER::rewindData(@_);
45 69 50       241 return $status unless $status == AZ_OK;
46              
47 69 50       276 return AZ_IO_ERROR unless $self->fh();
48 69         161 $self->fh()->clearerr();
49 69 50       138 $self->fh()->seek(0, IO::Seekable::SEEK_SET)
50             or return _ioError("rewinding", $self->externalFileName());
51 69         1223 return AZ_OK;
52             }
53              
54             # Return bytes read. Note that first parameter is a ref to a buffer.
55             # my $data;
56             # my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
57             sub _readRawChunk {
58 73     73   189 my ($self, $dataRef, $chunkSize) = @_;
59 73 50       178 return (0, AZ_OK) unless $chunkSize;
60 73 50       178 my $bytesRead = $self->fh()->read($$dataRef, $chunkSize)
61             or return (0, _ioError("reading data"));
62 73         1897 return ($bytesRead, AZ_OK);
63             }
64              
65             # If I already exist, extraction is a no-op.
66             sub extractToFileNamed {
67 14     14 1 37 my $self = shift;
68 14         24 my $name = shift; # local FS name
69 14 100 66     347 if (File::Spec->rel2abs($name) eq
70             File::Spec->rel2abs($self->externalFileName()) and -r $name) {
71 3         18 return AZ_OK;
72             } else {
73 11         62 return $self->SUPER::extractToFileNamed($name, @_);
74             }
75             }
76              
77             1;