| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Archive::Zip::SimpleZip; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 5 |  |  | 5 |  | 444339 | use strict; | 
|  | 5 |  |  |  |  | 19 |  | 
|  | 5 |  |  |  |  | 120 |  | 
| 4 | 5 |  |  | 5 |  | 21 | use warnings; | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 182 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | require 5.006; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 5 |  |  | 5 |  | 1589 | use IO::Compress::Zip 2.201 qw(:all); | 
|  | 5 |  |  |  |  | 95365 |  | 
|  | 5 |  |  |  |  | 980 |  | 
| 9 | 5 |  |  | 5 |  | 51 | use IO::Compress::Base::Common  2.201 (); | 
|  | 5 |  |  |  |  | 60 |  | 
|  | 5 |  |  |  |  | 131 |  | 
| 10 | 5 |  |  | 5 |  | 26 | use IO::Compress::Adapter::Deflate 2.201 ; | 
|  | 5 |  |  |  |  | 57 |  | 
|  | 5 |  |  |  |  | 728 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 5 |  |  | 5 |  | 30 | use Fcntl (); | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 74 |  | 
| 13 | 5 |  |  | 5 |  | 19 | use File::Spec (); | 
|  | 5 |  |  |  |  | 16 |  | 
|  | 5 |  |  |  |  | 73 |  | 
| 14 | 5 |  |  | 5 |  | 26 | use IO::File (); | 
|  | 5 |  |  |  |  | 8 |  | 
|  | 5 |  |  |  |  | 72 |  | 
| 15 | 5 |  |  | 5 |  | 20 | use Scalar::Util (); | 
|  | 5 |  |  |  |  | 7 |  | 
|  | 5 |  |  |  |  | 299 |  | 
| 16 | 5 |  |  | 5 |  | 28 | use Carp; | 
|  | 5 |  |  |  |  | 14 |  | 
|  | 5 |  |  |  |  | 6895 |  | 
| 17 |  |  |  |  |  |  | require Exporter ; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $SimpleZipError); | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | $SimpleZipError= ''; | 
| 22 |  |  |  |  |  |  | $VERSION = "1.000"; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | @ISA = qw(Exporter); | 
| 25 |  |  |  |  |  |  | @EXPORT_OK = qw( $SimpleZipError ) ; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | %EXPORT_TAGS = %IO::Compress::Zip::EXPORT_TAGS ; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | Exporter::export_ok_tags('all'); | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | our %PARAMS = ( | 
| 32 |  |  |  |  |  |  | 'name'          => [IO::Compress::Base::Common::Parse_any,       ''], | 
| 33 |  |  |  |  |  |  | 'comment'       => [IO::Compress::Base::Common::Parse_any,       ''], | 
| 34 |  |  |  |  |  |  | 'zipcomment'    => [IO::Compress::Base::Common::Parse_any,       ''], | 
| 35 |  |  |  |  |  |  | 'stream'        => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 36 |  |  |  |  |  |  | 'method'        => [IO::Compress::Base::Common::Parse_unsigned,  ZIP_CM_DEFLATE], | 
| 37 |  |  |  |  |  |  | 'minimal'       => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 38 |  |  |  |  |  |  | 'zip64'         => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 39 |  |  |  |  |  |  | 'filtername'    => [IO::Compress::Base::Common::Parse_code,      undef], | 
| 40 |  |  |  |  |  |  | 'canonicalname' => [IO::Compress::Base::Common::Parse_boolean,   1], | 
| 41 |  |  |  |  |  |  | 'textflag'      => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 42 |  |  |  |  |  |  | 'storelinks'    => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 43 |  |  |  |  |  |  | 'autoflush'     => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 44 |  |  |  |  |  |  | #'storedirs'    => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 45 |  |  |  |  |  |  | 'encode'       => [IO::Compress::Base::Common::Parse_any,        undef], | 
| 46 |  |  |  |  |  |  | #'extrafieldlocal'  => [IO::Compress::Base::Common::Parse_any,    undef], | 
| 47 |  |  |  |  |  |  | #'extrafieldcentral'=> [IO::Compress::Base::Common::Parse_any,    undef], | 
| 48 |  |  |  |  |  |  | 'filtercontainer' => [IO::Compress::Base::Common::Parse_code,  undef], | 
| 49 |  |  |  |  |  |  | #        'time'          => [IO::Compress::Base::Common::Parse_any,       undef], | 
| 50 |  |  |  |  |  |  | #        'extime'        => [IO::Compress::Base::Common::Parse_any,       undef], | 
| 51 |  |  |  |  |  |  | #        'efs'           => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # Zlib | 
| 54 |  |  |  |  |  |  | 'level'         => [IO::Compress::Base::Common::Parse_signed,    Z_DEFAULT_COMPRESSION], | 
| 55 |  |  |  |  |  |  | 'strategy'      => [IO::Compress::Base::Common::Parse_signed,    Z_DEFAULT_STRATEGY], | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | # Lzma | 
| 58 |  |  |  |  |  |  | 'preset'        => [IO::Compress::Base::Common::Parse_unsigned, 6], | 
| 59 |  |  |  |  |  |  | 'extreme'       => [IO::Compress::Base::Common::Parse_boolean,  0], | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # Bzip2 | 
| 62 |  |  |  |  |  |  | 'blocksize100k' => [IO::Compress::Base::Common::Parse_unsigned,  1], | 
| 63 |  |  |  |  |  |  | 'workfactor'    => [IO::Compress::Base::Common::Parse_unsigned,  0], | 
| 64 |  |  |  |  |  |  | 'verbosity'     => [IO::Compress::Base::Common::Parse_boolean,   0], | 
| 65 |  |  |  |  |  |  | ); | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub _ckParams | 
| 69 |  |  |  |  |  |  | { | 
| 70 | 1199 |  | 66 | 1199 |  | 3190 | my $got = shift || IO::Compress::Base::Parameters::new(); | 
| 71 | 1199 |  |  |  |  | 3982 | my $top = shift; | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 1199 | 100 |  |  |  | 3218 | $got->parse(\%PARAMS, @_) | 
| 74 |  |  |  |  |  |  | or _myDie("Parameter Error: " . $got->getError())  ; | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 1197 | 100 |  |  |  | 204934 | if ($top) | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 233 |  |  |  |  | 547 | for my $opt ( qw(name comment) ) | 
| 79 |  |  |  |  |  |  | { | 
| 80 | 465 | 100 |  |  |  | 1699 | _myDie("$opt option not valid in constructor") | 
| 81 |  |  |  |  |  |  | if $got->parsed($opt); | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 231 |  |  |  |  | 1250 | $got->setValue('crc32'   => 1); | 
| 85 | 231 |  |  |  |  | 1842 | $got->setValue('adler32' => 0); | 
| 86 | 231 |  |  |  |  | 1308 | $got->setValue('os_code' => $Compress::Raw::Zlib::gzip_os_code); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | else | 
| 89 |  |  |  |  |  |  | { | 
| 90 | 964 |  |  |  |  | 1472 | for my $opt ( qw( zipcomment) ) | 
| 91 |  |  |  |  |  |  | { | 
| 92 | 964 | 100 |  |  |  | 1796 | _myDie("$opt option only valid in constructor") | 
| 93 |  |  |  |  |  |  | if $got->parsed($opt); | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 1194 |  |  |  |  | 6191 | my $e = $got->getValue("encode"); | 
| 98 | 1194 | 100 |  |  |  | 4088 | if (defined $e) | 
| 99 |  |  |  |  |  |  | { | 
| 100 | 13 | 50 |  |  |  | 51 | _myDie("Encode::find_encoding not found") if ! defined &Encode::find_encoding; | 
| 101 | 13 | 100 |  |  |  | 115 | _myDie("Unknown Encoding '$e'")           if ! defined Encode::find_encoding($e) ; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 1193 |  |  |  |  | 1973 | return $got; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub _illegalFilename | 
| 108 |  |  |  |  |  |  | { | 
| 109 | 3 |  |  | 3 |  | 97 | return _setError(undef, undef, "Illegal Filename") ; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | #sub simplezip | 
| 114 |  |  |  |  |  |  | #{ | 
| 115 |  |  |  |  |  |  | #    my $from = shift; | 
| 116 |  |  |  |  |  |  | #    my $filename = shift ; | 
| 117 |  |  |  |  |  |  | #    #my %opts | 
| 118 |  |  |  |  |  |  | # | 
| 119 |  |  |  |  |  |  | #    my $z = new Archive::Zip::SimpleZip $filename, @_; | 
| 120 |  |  |  |  |  |  | # | 
| 121 |  |  |  |  |  |  | #    if (ref $from eq 'ARRAY') | 
| 122 |  |  |  |  |  |  | #    { | 
| 123 |  |  |  |  |  |  | #        $z->add($_) for @$from; | 
| 124 |  |  |  |  |  |  | #    } | 
| 125 |  |  |  |  |  |  | #    elsif (ref $from) | 
| 126 |  |  |  |  |  |  | #    { | 
| 127 |  |  |  |  |  |  | #        die "bad"; | 
| 128 |  |  |  |  |  |  | #    } | 
| 129 |  |  |  |  |  |  | #    else | 
| 130 |  |  |  |  |  |  | #    { | 
| 131 |  |  |  |  |  |  | #        $z->add($filename); | 
| 132 |  |  |  |  |  |  | #    } | 
| 133 |  |  |  |  |  |  | # | 
| 134 |  |  |  |  |  |  | #    $z->close(); | 
| 135 |  |  |  |  |  |  | #} | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | sub new | 
| 139 |  |  |  |  |  |  | { | 
| 140 | 238 |  |  | 238 | 0 | 815090 | my $class = shift; | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 238 |  |  |  |  | 589 | $SimpleZipError = ''; | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 238 | 100 |  |  |  | 850 | return _setError(undef, undef, "Missing Filename") | 
| 145 |  |  |  |  |  |  | unless @_ ; | 
| 146 |  |  |  |  |  |  |  | 
| 147 | 237 |  |  |  |  | 519 | my $outValue = shift ; | 
| 148 | 237 |  |  |  |  | 411 | my $fh; | 
| 149 |  |  |  |  |  |  |  | 
| 150 | 237 | 100 |  |  |  | 643 | if (!defined $outValue) | 
| 151 |  |  |  |  |  |  | { | 
| 152 | 1 |  |  |  |  | 4 | return _illegalFilename | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  |  | 
| 155 | 236 |  |  |  |  | 589 | my $isSTDOUT = ($outValue eq '-') ; | 
| 156 | 236 |  |  |  |  | 907 | my $outType = IO::Compress::Base::Common::whatIsOutput($outValue); | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 236 | 100 | 66 |  |  | 7896 | if ($outType eq 'filename') | 
|  |  | 50 |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | { | 
| 160 | 145 | 100 | 66 |  |  | 2154 | if (-e $outValue && ( ! -f _ || ! -w _)) | 
|  |  |  | 100 |  |  |  |  | 
| 161 |  |  |  |  |  |  | { | 
| 162 | 1 |  |  |  |  | 6 | return _illegalFilename | 
| 163 |  |  |  |  |  |  | } | 
| 164 |  |  |  |  |  |  |  | 
| 165 | 144 | 100 |  |  |  | 1125 | $fh = new IO::File ">$outValue" | 
| 166 |  |  |  |  |  |  | or return _illegalFilename; | 
| 167 |  |  |  |  |  |  | } | 
| 168 |  |  |  |  |  |  | elsif( $outType eq 'buffer' || $outType eq 'handle') | 
| 169 |  |  |  |  |  |  | { | 
| 170 | 91 |  |  |  |  | 208 | $fh = $outValue; | 
| 171 |  |  |  |  |  |  | } | 
| 172 |  |  |  |  |  |  | else | 
| 173 |  |  |  |  |  |  | { | 
| 174 | 0 |  |  |  |  | 0 | return _illegalFilename | 
| 175 |  |  |  |  |  |  | } | 
| 176 |  |  |  |  |  |  |  | 
| 177 | 234 |  |  |  |  | 14186 | my $got = _ckParams(undef, 1, @_); | 
| 178 | 230 | 100 |  |  |  | 872 | $got->setValue('autoclose' => 1) unless $outType eq 'handle' ; | 
| 179 | 230 | 100 |  |  |  | 1392 | $got->setValue('stream' => 1) if $isSTDOUT ; | 
| 180 |  |  |  |  |  |  |  | 
| 181 | 230 |  |  |  |  | 1226 | my $obj = { | 
| 182 |  |  |  |  |  |  | ZipFile      => $outValue, | 
| 183 |  |  |  |  |  |  | FH           => $fh, | 
| 184 |  |  |  |  |  |  | Open         => 1, | 
| 185 |  |  |  |  |  |  | FilesWritten => 0, | 
| 186 |  |  |  |  |  |  | Opts         => $got, | 
| 187 |  |  |  |  |  |  | Error        => undef, | 
| 188 |  |  |  |  |  |  | Raw          => undef, | 
| 189 |  |  |  |  |  |  | }; | 
| 190 |  |  |  |  |  |  |  | 
| 191 | 230 |  |  |  |  | 819 | bless $obj, $class; | 
| 192 |  |  |  |  |  |  | } | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | sub DESTROY | 
| 195 |  |  |  |  |  |  | { | 
| 196 | 230 |  |  | 230 |  | 1560766 | my $self = shift; | 
| 197 | 230 |  |  |  |  | 671 | $self->close(); | 
| 198 |  |  |  |  |  |  | } | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | sub close | 
| 201 |  |  |  |  |  |  | { | 
| 202 | 448 |  |  | 448 | 1 | 31753 | my $self = shift; | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | return 0 | 
| 205 | 448 | 100 |  |  |  | 5687 | if ! $self->{Open} ; | 
| 206 |  |  |  |  |  |  |  | 
| 207 | 230 |  |  |  |  | 422 | $self->{Open} = 0; | 
| 208 | 230 | 100 | 66 |  |  | 820 | if ($self->{FilesWritten} || defined $self->{Raw}) | 
| 209 |  |  |  |  |  |  | { | 
| 210 | 224 | 50 |  |  |  | 557 | if(defined $self->{Zip}) | 
| 211 |  |  |  |  |  |  | { | 
| 212 | 224 | 100 |  |  |  | 519 | if (defined $self->{Raw}) | 
| 213 |  |  |  |  |  |  | { | 
| 214 | 2 |  |  |  |  | 6 | $self->{Raw} = undef ; | 
| 215 |  |  |  |  |  |  | } | 
| 216 |  |  |  |  |  |  |  | 
| 217 | 224 | 50 |  |  |  | 800 | $self->{Zip}->_flushCompressed() || return 0; | 
| 218 | 224 | 50 |  |  |  | 14858 | $self->{Zip}->close() || return 0; | 
| 219 | 224 |  |  |  |  | 77166 | delete $self->{Zip} ; | 
| 220 |  |  |  |  |  |  | } | 
| 221 |  |  |  |  |  |  | } | 
| 222 |  |  |  |  |  |  |  | 
| 223 | 230 |  |  |  |  | 14789 | 1; | 
| 224 |  |  |  |  |  |  | } | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | sub _newStream | 
| 227 |  |  |  |  |  |  | { | 
| 228 | 961 |  |  | 961 |  | 1204 | my $self = shift; | 
| 229 | 961 |  |  |  |  | 1105 | my $filename = shift ; | 
| 230 | 961 |  |  |  |  | 918 | my $options =  shift; | 
| 231 |  |  |  |  |  |  |  | 
| 232 | 961 | 100 |  |  |  | 1502 | if (defined $filename) | 
| 233 |  |  |  |  |  |  | { | 
| 234 | 27 |  |  |  |  | 123 | IO::Compress::Zip::getFileInfo(undef, $options, $filename) ; | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | # Force STORE for directories, symbolic links & empty files | 
| 237 | 27 | 100 | 66 |  |  | 4424 | $options->setValue(method => ZIP_CM_STORE) | 
|  |  |  | 100 |  |  |  |  | 
| 238 |  |  |  |  |  |  | if -d $filename || -z _ || -l $filename ; | 
| 239 |  |  |  |  |  |  | } | 
| 240 |  |  |  |  |  |  |  | 
| 241 |  |  |  |  |  |  | # Archive::Zip::SimpleZip handles canonical | 
| 242 | 961 |  |  |  |  | 2029 | $options->setValue(canonicalname => 0); | 
| 243 |  |  |  |  |  |  |  | 
| 244 | 961 |  |  |  |  | 5054 | $! = 0; | 
| 245 | 961 | 100 |  |  |  | 1867 | if (! defined $self->{Zip}) { | 
| 246 | 224 |  |  |  |  | 635 | $self->{Zip} = IO::Compress::Base::Common::createSelfTiedObject('IO::Compress::Zip', \$SimpleZipError); | 
| 247 |  |  |  |  |  |  | $self->{Zip}->_create($options, $self->{FH}) | 
| 248 | 224 | 50 |  |  |  | 10415 | or die "_create $SimpleZipError"; | 
| 249 |  |  |  |  |  |  | $self->{Zip}->autoflush() | 
| 250 | 224 | 100 |  |  |  | 195832 | if  $options->getValue('autoflush'); | 
| 251 |  |  |  |  |  |  |  | 
| 252 |  |  |  |  |  |  | } | 
| 253 |  |  |  |  |  |  | else { | 
| 254 | 737 | 50 |  |  |  | 2113 | $self->{Zip}->_newStream($options) | 
| 255 |  |  |  |  |  |  | or die "_newStream - $SimpleZipError"; | 
| 256 |  |  |  |  |  |  | } | 
| 257 |  |  |  |  |  |  |  | 
| 258 | 961 |  |  |  |  | 564539 | ++ $self->{FilesWritten} ; | 
| 259 |  |  |  |  |  |  |  | 
| 260 | 961 |  |  |  |  | 1469 | return 1; | 
| 261 |  |  |  |  |  |  | } | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  |  | 
| 264 |  |  |  |  |  |  | sub _setError | 
| 265 |  |  |  |  |  |  | { | 
| 266 | 7 |  |  | 7 |  | 18 | $SimpleZipError = $_[2] ; | 
| 267 | 7 | 100 |  |  |  | 35 | $_[0]->{Error} = $_[2] | 
| 268 |  |  |  |  |  |  | if defined  $_[0] ; | 
| 269 |  |  |  |  |  |  |  | 
| 270 | 7 |  |  |  |  | 29 | return $_[1]; | 
| 271 |  |  |  |  |  |  | } | 
| 272 |  |  |  |  |  |  |  | 
| 273 |  |  |  |  |  |  |  | 
| 274 |  |  |  |  |  |  | sub error | 
| 275 |  |  |  |  |  |  | { | 
| 276 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 277 | 0 |  |  |  |  | 0 | return $self->{Error}; | 
| 278 |  |  |  |  |  |  | } | 
| 279 |  |  |  |  |  |  |  | 
| 280 |  |  |  |  |  |  | sub _myDie | 
| 281 |  |  |  |  |  |  | { | 
| 282 | 8 |  |  | 8 |  | 1096 | $SimpleZipError = $_[0]; | 
| 283 | 8 |  |  |  |  | 1267 | Carp::croak $_[0]; | 
| 284 |  |  |  |  |  |  |  | 
| 285 |  |  |  |  |  |  | } | 
| 286 |  |  |  |  |  |  |  | 
| 287 |  |  |  |  |  |  | sub _stdPreq | 
| 288 |  |  |  |  |  |  | { | 
| 289 | 968 |  |  | 968 |  | 1109 | my $self = shift; | 
| 290 |  |  |  |  |  |  |  | 
| 291 |  |  |  |  |  |  | return 0 | 
| 292 | 968 | 50 |  |  |  | 2274 | if $self->{Error} ; | 
| 293 |  |  |  |  |  |  |  | 
| 294 |  |  |  |  |  |  | return $self->_setError(0, "Zip file closed") | 
| 295 | 968 | 50 |  |  |  | 1718 | if ! $self->{Open} ; | 
| 296 |  |  |  |  |  |  |  | 
| 297 |  |  |  |  |  |  | return $self->_setError(0, "openMember filehandle already open") | 
| 298 | 968 | 100 |  |  |  | 1768 | if  defined $self->{Raw}; | 
| 299 |  |  |  |  |  |  |  | 
| 300 | 966 |  |  |  |  | 1870 | return 1; | 
| 301 |  |  |  |  |  |  | } | 
| 302 |  |  |  |  |  |  |  | 
| 303 |  |  |  |  |  |  | sub add | 
| 304 |  |  |  |  |  |  | { | 
| 305 | 29 |  |  | 29 | 1 | 6509 | my $self = shift; | 
| 306 | 29 |  |  |  |  | 74 | my $filename = shift; | 
| 307 |  |  |  |  |  |  |  | 
| 308 | 29 | 50 |  |  |  | 111 | $self->_stdPreq or return 0 ; | 
| 309 |  |  |  |  |  |  |  | 
| 310 | 29 | 100 |  |  |  | 419 | return $self->_setError(0, "File '$filename' does not exist") | 
| 311 |  |  |  |  |  |  | if ! -e $filename  ; | 
| 312 |  |  |  |  |  |  |  | 
| 313 | 28 | 50 |  |  |  | 329 | return $self->_setError(0, "File '$filename' cannot be read") | 
| 314 |  |  |  |  |  |  | if ! -r $filename ; | 
| 315 |  |  |  |  |  |  |  | 
| 316 | 28 |  |  |  |  | 182 | my $options =  $self->{Opts}->clone(); | 
| 317 |  |  |  |  |  |  |  | 
| 318 | 28 |  |  |  |  | 2829 | my $got = _ckParams($options, 0, @_); | 
| 319 |  |  |  |  |  |  |  | 
| 320 |  |  |  |  |  |  | # Force Encode off. | 
| 321 | 27 |  |  |  |  | 92 | $got->setValue('encode', undef); | 
| 322 |  |  |  |  |  |  |  | 
| 323 | 27 |  | 100 |  |  | 186 | my $isLink = $got->getValue('storelinks') && -l $filename ; | 
| 324 | 27 |  |  |  |  | 443 | my $isDir = -d $filename; | 
| 325 |  |  |  |  |  |  |  | 
| 326 | 27 | 50 | 33 |  |  | 214 | return 0 | 
| 327 |  |  |  |  |  |  | if $filename eq '.' || $filename eq '..'; | 
| 328 |  |  |  |  |  |  |  | 
| 329 | 27 | 100 |  |  |  | 100 | if ($options->getValue("canonicalname")) | 
| 330 |  |  |  |  |  |  | { | 
| 331 | 26 | 100 |  |  |  | 151 | if (! $got->parsed("name")) | 
| 332 |  |  |  |  |  |  | { | 
| 333 | 18 |  | 100 |  |  | 180 | $got->setValue(name => IO::Compress::Zip::canonicalName($filename, $isDir && ! $isLink)); | 
| 334 |  |  |  |  |  |  | } | 
| 335 |  |  |  |  |  |  | else | 
| 336 |  |  |  |  |  |  | { | 
| 337 | 8 |  | 33 |  |  | 58 | $got->setValue(name => IO::Compress::Zip::canonicalName($got->getValue("name"), $isDir && ! $isLink)); | 
| 338 |  |  |  |  |  |  | } | 
| 339 |  |  |  |  |  |  | } | 
| 340 |  |  |  |  |  |  |  | 
| 341 | 27 |  |  |  |  | 1568 | my ($mode, $uid, $gid, $size, $atime, $mtime, $ctime) ; | 
| 342 |  |  |  |  |  |  |  | 
| 343 | 27 | 100 |  |  |  | 60 | if ( $got->parsed('storelinks') ) | 
| 344 |  |  |  |  |  |  | { | 
| 345 | 5 |  |  |  |  | 83 | ($mode, $uid, $gid, $size, $atime, $mtime, $ctime) | 
| 346 |  |  |  |  |  |  | = (lstat($filename))[2, 4, 5, 7, 8, 9, 10] ; | 
| 347 |  |  |  |  |  |  | } | 
| 348 |  |  |  |  |  |  | else | 
| 349 |  |  |  |  |  |  | { | 
| 350 | 22 |  |  |  |  | 376 | ($mode, $uid, $gid, $size, $atime, $mtime, $ctime) | 
| 351 |  |  |  |  |  |  | = (stat($filename))[2, 4, 5,7, 8, 9, 10] ; | 
| 352 |  |  |  |  |  |  | } | 
| 353 |  |  |  |  |  |  |  | 
| 354 | 27 |  |  |  |  | 142 | $got->setValue(time => $mtime); | 
| 355 |  |  |  |  |  |  |  | 
| 356 | 27 | 50 |  |  |  | 231 | if (! $got->getValue('minimal')) { | 
| 357 |  |  |  |  |  |  |  | 
| 358 | 27 |  |  |  |  | 192 | $got->setValue(extime => [$atime, $mtime, $ctime]) ; | 
| 359 |  |  |  |  |  |  |  | 
| 360 | 5 |  |  | 5 |  | 2012 | use Perl::OSType; | 
|  | 5 |  |  |  |  | 1747 |  | 
|  | 5 |  |  |  |  | 5993 |  | 
| 361 | 27 |  |  |  |  | 275 | my $type = Perl::OSType::os_type(); | 
| 362 | 27 | 50 |  |  |  | 336 | if ( $type eq 'Unix' ) | 
| 363 |  |  |  |  |  |  | { | 
| 364 | 27 |  |  |  |  | 88 | $got->setValue(exunixn => [$uid, $gid]) ; | 
| 365 |  |  |  |  |  |  | } | 
| 366 |  |  |  |  |  |  | # TODO add Windows | 
| 367 |  |  |  |  |  |  | } | 
| 368 |  |  |  |  |  |  |  | 
| 369 | 27 |  |  |  |  | 248 | $self->_newStream($filename, $got); | 
| 370 |  |  |  |  |  |  |  | 
| 371 | 27 | 100 |  |  |  | 597 | if($isLink) | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 372 |  |  |  |  |  |  | { | 
| 373 | 3 |  |  |  |  | 45 | my $target = readlink($filename); | 
| 374 | 3 |  |  |  |  | 24 | $self->{Zip}->write($target); | 
| 375 |  |  |  |  |  |  | } | 
| 376 |  |  |  |  |  |  | elsif (-d $filename) | 
| 377 |  |  |  |  |  |  | { | 
| 378 |  |  |  |  |  |  | # Do nothing, a directory has no payload | 
| 379 |  |  |  |  |  |  | } | 
| 380 |  |  |  |  |  |  | elsif (-f $filename) | 
| 381 |  |  |  |  |  |  | { | 
| 382 | 19 | 50 |  |  |  | 312 | my $fh = new IO::File "<$filename" | 
| 383 |  |  |  |  |  |  | or die "Cannot open file $filename: $!"; | 
| 384 |  |  |  |  |  |  |  | 
| 385 | 19 |  |  |  |  | 1785 | binmode $fh; | 
| 386 |  |  |  |  |  |  |  | 
| 387 | 19 |  |  |  |  | 63 | my $data; | 
| 388 |  |  |  |  |  |  | my $last ; | 
| 389 | 19 |  |  |  |  | 136 | while ($fh->read($data, 1024 * 16)) | 
| 390 |  |  |  |  |  |  | { | 
| 391 | 19 |  |  |  |  | 744 | $self->{Zip}->write($data); | 
| 392 |  |  |  |  |  |  | } | 
| 393 |  |  |  |  |  |  | } | 
| 394 |  |  |  |  |  |  | else | 
| 395 |  |  |  |  |  |  | { | 
| 396 | 0 |  |  |  |  | 0 | return 0; | 
| 397 |  |  |  |  |  |  | } | 
| 398 |  |  |  |  |  |  |  | 
| 399 | 27 |  |  |  |  | 3208 | return 1; | 
| 400 |  |  |  |  |  |  | } | 
| 401 |  |  |  |  |  |  |  | 
| 402 |  |  |  |  |  |  |  | 
| 403 |  |  |  |  |  |  | sub addString | 
| 404 |  |  |  |  |  |  | { | 
| 405 | 862 |  |  | 862 | 1 | 158281 | my $self    = shift; | 
| 406 | 862 |  |  |  |  | 1167 | my $string  = shift; | 
| 407 |  |  |  |  |  |  |  | 
| 408 | 862 | 100 |  |  |  | 1493 | $self->_stdPreq or return 0 ; | 
| 409 |  |  |  |  |  |  |  | 
| 410 | 861 |  |  |  |  | 2318 | my $options =  $self->{Opts}->clone(); | 
| 411 |  |  |  |  |  |  |  | 
| 412 | 861 |  |  |  |  | 70512 | my $got = _ckParams($options, 0, @_); | 
| 413 |  |  |  |  |  |  |  | 
| 414 | 860 | 100 |  |  |  | 1348 | _myDie("Missing 'Name' parameter in addString") | 
| 415 |  |  |  |  |  |  | if ! $got->parsed("name"); | 
| 416 |  |  |  |  |  |  |  | 
| 417 | 859 | 100 |  |  |  | 2982 | $got->setValue(name => IO::Compress::Zip::canonicalName($got->getValue("name"))) | 
| 418 |  |  |  |  |  |  | if $options->getValue("canonicalname") ; | 
| 419 |  |  |  |  |  |  |  | 
| 420 | 859 |  |  |  |  | 4257 | $self->_newStream(undef, $got); | 
| 421 | 859 |  |  |  |  | 2060 | $self->{Zip}->write($string); | 
| 422 |  |  |  |  |  |  |  | 
| 423 | 859 |  |  |  |  | 47153 | return 1; | 
| 424 |  |  |  |  |  |  | } | 
| 425 |  |  |  |  |  |  |  | 
| 426 |  |  |  |  |  |  | sub addFileHandle | 
| 427 |  |  |  |  |  |  | { | 
| 428 | 2 |  |  | 2 | 1 | 581 | my $self = shift; | 
| 429 | 2 |  |  |  |  | 4 | my $fh   = shift; | 
| 430 |  |  |  |  |  |  |  | 
| 431 | 2 | 50 |  |  |  | 9 | $self->_stdPreq or return 0 ; | 
| 432 |  |  |  |  |  |  |  | 
| 433 | 2 |  |  |  |  | 12 | my $options =  $self->{Opts}->clone() ; | 
| 434 |  |  |  |  |  |  |  | 
| 435 | 2 |  |  |  |  | 177 | my $got = _ckParams($options, 0, @_); | 
| 436 |  |  |  |  |  |  |  | 
| 437 | 2 | 100 |  |  |  | 19 | _myDie("Missing 'Name' parameter in addFileHandle") | 
| 438 |  |  |  |  |  |  | if ! $got->parsed("name"); | 
| 439 |  |  |  |  |  |  |  | 
| 440 | 1 | 50 |  |  |  | 7 | $got->setValue(name => IO::Compress::Zip::canonicalName($got->getValue("name"))) | 
| 441 |  |  |  |  |  |  | if $options->getValue("canonicalname") ; | 
| 442 |  |  |  |  |  |  |  | 
| 443 | 1 |  |  |  |  | 61 | $self->_newStream(undef, $got); | 
| 444 |  |  |  |  |  |  |  | 
| 445 | 1 |  |  |  |  | 3 | my $data; | 
| 446 |  |  |  |  |  |  |  | 
| 447 | 1 |  |  |  |  | 8 | while ($fh->read($data, 1024 * 16)) | 
| 448 |  |  |  |  |  |  | { | 
| 449 | 1 |  |  |  |  | 38 | $self->{Zip}->write($data); | 
| 450 |  |  |  |  |  |  | } | 
| 451 |  |  |  |  |  |  |  | 
| 452 | 1 |  |  |  |  | 120 | return 1; | 
| 453 |  |  |  |  |  |  | } | 
| 454 |  |  |  |  |  |  |  | 
| 455 |  |  |  |  |  |  | # sub createDirectory | 
| 456 |  |  |  |  |  |  | # { | 
| 457 |  |  |  |  |  |  | #     my $self = shift ; | 
| 458 |  |  |  |  |  |  | #     my $directory = shift; | 
| 459 |  |  |  |  |  |  |  | 
| 460 |  |  |  |  |  |  | #     # TODO - file attributes | 
| 461 |  |  |  |  |  |  |  | 
| 462 |  |  |  |  |  |  | #     $self->_stdPreq or return 0 ; | 
| 463 |  |  |  |  |  |  |  | 
| 464 |  |  |  |  |  |  | #     my $got = _ckParams($options, 0, @_); | 
| 465 |  |  |  |  |  |  | #     $got->setValue(name => IO::Compress::Zip::canonicalName($filename, 1)); | 
| 466 |  |  |  |  |  |  |  | 
| 467 |  |  |  |  |  |  | #     $self->_newStream(undef, $got); | 
| 468 |  |  |  |  |  |  |  | 
| 469 |  |  |  |  |  |  | #     return 1; | 
| 470 |  |  |  |  |  |  | # } | 
| 471 |  |  |  |  |  |  |  | 
| 472 |  |  |  |  |  |  | sub openMember | 
| 473 |  |  |  |  |  |  | { | 
| 474 | 75 |  |  | 75 | 1 | 7083 | my $self    = shift; | 
| 475 |  |  |  |  |  |  |  | 
| 476 | 75 | 100 |  |  |  | 294 | $self->_stdPreq or return undef ; | 
| 477 |  |  |  |  |  |  |  | 
| 478 | 74 |  |  |  |  | 349 | my $options =  $self->{Opts}->clone(); | 
| 479 |  |  |  |  |  |  |  | 
| 480 | 74 |  |  |  |  | 7928 | my $got = _ckParams($options, 0, @_); | 
| 481 |  |  |  |  |  |  |  | 
| 482 | 74 | 50 |  |  |  | 302 | _myDie("Missing 'Name' parameter in openMember") | 
| 483 |  |  |  |  |  |  | if ! $got->parsed("name"); | 
| 484 |  |  |  |  |  |  |  | 
| 485 | 74 | 100 |  |  |  | 435 | $got->setValue(name => IO::Compress::Zip::canonicalName($got->getValue("name"))) | 
| 486 |  |  |  |  |  |  | if $options->getValue("canonicalname") ; | 
| 487 |  |  |  |  |  |  |  | 
| 488 | 74 |  |  |  |  | 5059 | $self->_newStream(undef, $got); | 
| 489 |  |  |  |  |  |  |  | 
| 490 |  |  |  |  |  |  | #  if (1) | 
| 491 |  |  |  |  |  |  | #  { | 
| 492 | 74 |  |  |  |  | 296 | my $z = IO::Compress::Base::Common::createSelfTiedObject("Archive::Zip::SimpleZip::Handle", \$SimpleZipError) ; | 
| 493 |  |  |  |  |  |  |  | 
| 494 | 74 |  |  |  |  | 975 | $self->{Raw} = 1; | 
| 495 |  |  |  |  |  |  |  | 
| 496 | 74 |  |  |  |  | 204 | *$z->{Open} = 1 ; | 
| 497 | 74 |  |  |  |  | 180 | *$z->{SZ} = $self; | 
| 498 | 74 |  |  |  |  | 478 | Scalar::Util::weaken *$z->{SZ}; # for 5.8 | 
| 499 |  |  |  |  |  |  |  | 
| 500 | 74 |  |  |  |  | 738 | return $z; | 
| 501 |  |  |  |  |  |  | #  } | 
| 502 |  |  |  |  |  |  | #  else | 
| 503 |  |  |  |  |  |  | #  { | 
| 504 |  |  |  |  |  |  | #    my $handle = Symbol::gensym(); | 
| 505 |  |  |  |  |  |  | #    tie *$handle, "Archive::Zip::SimpleZip::Handle", $self, $self->{Zip}; | 
| 506 |  |  |  |  |  |  | # | 
| 507 |  |  |  |  |  |  | #    $self->{Raw} = 1; | 
| 508 |  |  |  |  |  |  | # | 
| 509 |  |  |  |  |  |  | #    return $handle; | 
| 510 |  |  |  |  |  |  | #  } | 
| 511 |  |  |  |  |  |  | } | 
| 512 |  |  |  |  |  |  |  | 
| 513 |  |  |  |  |  |  | sub STORABLE_freeze | 
| 514 |  |  |  |  |  |  | { | 
| 515 | 0 |  |  | 0 | 0 | 0 | my $type = ref shift; | 
| 516 | 0 |  |  |  |  | 0 | croak "Cannot freeze $type object\n"; | 
| 517 |  |  |  |  |  |  | } | 
| 518 |  |  |  |  |  |  |  | 
| 519 |  |  |  |  |  |  | sub STORABLE_thaw | 
| 520 |  |  |  |  |  |  | { | 
| 521 | 0 |  |  | 0 | 0 | 0 | my $type = ref shift; | 
| 522 | 0 |  |  |  |  | 0 | croak "Cannot thaw $type object\n"; | 
| 523 |  |  |  |  |  |  | } | 
| 524 |  |  |  |  |  |  |  | 
| 525 |  |  |  |  |  |  |  | 
| 526 |  |  |  |  |  |  |  | 
| 527 |  |  |  |  |  |  | { | 
| 528 |  |  |  |  |  |  | package Archive::Zip::SimpleZip::Handle ; | 
| 529 |  |  |  |  |  |  |  | 
| 530 |  |  |  |  |  |  | sub TIEHANDLE | 
| 531 |  |  |  |  |  |  | { | 
| 532 | 74 | 50 |  | 74 |  | 3198 | return $_[0] if ref($_[0]); | 
| 533 | 0 |  |  |  |  | 0 | die "OOPS\n" ; | 
| 534 |  |  |  |  |  |  | } | 
| 535 |  |  |  |  |  |  |  | 
| 536 |  |  |  |  |  |  | sub UNTIE | 
| 537 |  |  |  |  |  |  | { | 
| 538 | 0 |  |  | 0 |  | 0 | my $self = shift ; | 
| 539 |  |  |  |  |  |  | } | 
| 540 |  |  |  |  |  |  |  | 
| 541 |  |  |  |  |  |  | sub DESTROY | 
| 542 |  |  |  |  |  |  | { | 
| 543 | 74 |  |  | 74 |  | 116050 | my $self = shift ; | 
| 544 | 74 |  |  |  |  | 748 | local ($., $@, $!, $^E, $?); | 
| 545 | 74 |  |  |  |  | 287 | $self->close() ; | 
| 546 |  |  |  |  |  |  |  | 
| 547 |  |  |  |  |  |  | # TODO - memory leak with 5.8.0 - this isn't called until | 
| 548 |  |  |  |  |  |  | #        global destruction | 
| 549 |  |  |  |  |  |  | # | 
| 550 | 74 |  |  |  |  | 158 | %{ *$self } = () ; | 
|  | 74 |  |  |  |  | 373 |  | 
| 551 | 74 |  |  |  |  | 671 | undef $self ; | 
| 552 |  |  |  |  |  |  | } | 
| 553 |  |  |  |  |  |  |  | 
| 554 |  |  |  |  |  |  |  | 
| 555 |  |  |  |  |  |  | sub close | 
| 556 |  |  |  |  |  |  | { | 
| 557 | 143 |  |  | 143 |  | 13976 | my $self = shift ; | 
| 558 | 143 | 100 |  |  |  | 531 | return 1 if ! *$self->{Open}; | 
| 559 |  |  |  |  |  |  |  | 
| 560 | 74 |  |  |  |  | 191 | *$self->{Open} = 0 ; | 
| 561 |  |  |  |  |  |  |  | 
| 562 |  |  |  |  |  |  | #        untie *$self | 
| 563 |  |  |  |  |  |  | #            if $] >= 5.008 ; | 
| 564 |  |  |  |  |  |  |  | 
| 565 | 74 | 50 |  |  |  | 254 | if (defined *$self->{SZ}) | 
| 566 |  |  |  |  |  |  | { | 
| 567 | 74 |  |  |  |  | 152 | *$self->{SZ}{Raw} = undef ; | 
| 568 | 74 |  |  |  |  | 200 | *$self->{SZ} = undef ; | 
| 569 |  |  |  |  |  |  | } | 
| 570 |  |  |  |  |  |  |  | 
| 571 | 74 |  |  |  |  | 408 | 1; | 
| 572 |  |  |  |  |  |  | } | 
| 573 |  |  |  |  |  |  |  | 
| 574 |  |  |  |  |  |  | sub print | 
| 575 |  |  |  |  |  |  | { | 
| 576 | 70 |  |  | 70 |  | 14444 | my $self = shift; | 
| 577 | 70 | 100 |  |  |  | 279 | $self->_stdPreq() or return 0 ; | 
| 578 |  |  |  |  |  |  |  | 
| 579 | 68 |  |  |  |  | 470 | *$self->{SZ}{Zip}->print(@_); | 
| 580 |  |  |  |  |  |  | } | 
| 581 |  |  |  |  |  |  |  | 
| 582 |  |  |  |  |  |  | sub printf | 
| 583 |  |  |  |  |  |  | { | 
| 584 | 6 |  |  | 6 |  | 1387 | my $self = shift; | 
| 585 | 6 | 50 |  |  |  | 27 | $self->_stdPreq() or return 0 ; | 
| 586 |  |  |  |  |  |  |  | 
| 587 | 6 |  |  |  |  | 52 | *$self->{SZ}{Zip}->printf(@_); | 
| 588 |  |  |  |  |  |  | } | 
| 589 |  |  |  |  |  |  |  | 
| 590 |  |  |  |  |  |  | sub syswrite | 
| 591 |  |  |  |  |  |  | { | 
| 592 | 6 |  |  | 6 |  | 1632 | my $self = shift; | 
| 593 | 6 | 50 |  |  |  | 18 | $self->_stdPreq() or return 0 ; | 
| 594 |  |  |  |  |  |  |  | 
| 595 | 6 |  |  |  |  | 30 | *$self->{SZ}{Zip}->syswrite(@_); | 
| 596 |  |  |  |  |  |  | } | 
| 597 |  |  |  |  |  |  |  | 
| 598 |  |  |  |  |  |  | sub tell | 
| 599 |  |  |  |  |  |  | { | 
| 600 | 9 |  |  | 9 |  | 1393 | my $self = shift; | 
| 601 | 9 | 50 |  |  |  | 31 | $self->_stdPreq() or return 0 ; | 
| 602 |  |  |  |  |  |  |  | 
| 603 | 9 |  |  |  |  | 62 | *$self->{SZ}{Zip}->tell(@_); | 
| 604 |  |  |  |  |  |  | } | 
| 605 |  |  |  |  |  |  |  | 
| 606 |  |  |  |  |  |  | sub eof | 
| 607 |  |  |  |  |  |  | { | 
| 608 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 609 | 0 | 0 |  |  |  | 0 | $self->_stdPreq() or return 0 ; | 
| 610 |  |  |  |  |  |  |  | 
| 611 | 0 |  |  |  |  | 0 | *$self->{SZ}{Zip}->eof; | 
| 612 |  |  |  |  |  |  | } | 
| 613 |  |  |  |  |  |  |  | 
| 614 |  |  |  |  |  |  | sub _stdPreq | 
| 615 |  |  |  |  |  |  | { | 
| 616 | 91 |  |  | 91 |  | 170 | my $self = shift; | 
| 617 |  |  |  |  |  |  |  | 
| 618 |  |  |  |  |  |  | return _setError("Zip file closed") | 
| 619 | 91 | 100 | 66 |  |  | 786 | if ! defined defined *$self->{SZ} || ! *$self->{SZ}{Open} ; | 
| 620 |  |  |  |  |  |  |  | 
| 621 |  |  |  |  |  |  |  | 
| 622 |  |  |  |  |  |  | return _setError("openMember filehandle closed") | 
| 623 | 89 | 50 | 33 |  |  | 529 | if  ! *$self->{Open} || ! defined *$self->{SZ}{Raw}; | 
| 624 |  |  |  |  |  |  |  | 
| 625 |  |  |  |  |  |  | return 0 | 
| 626 | 89 | 50 |  |  |  | 254 | if *$self->{SZ}{Error} ; | 
| 627 |  |  |  |  |  |  |  | 
| 628 | 89 |  |  |  |  | 318 | return 1; | 
| 629 |  |  |  |  |  |  | } | 
| 630 |  |  |  |  |  |  |  | 
| 631 |  |  |  |  |  |  | sub _setError | 
| 632 |  |  |  |  |  |  | { | 
| 633 | 2 |  |  | 2 |  | 7 | $Archive::Zip::SimpleZip::SimpleZipError = $_[0] ; | 
| 634 | 2 |  |  |  |  | 12 | return 0; | 
| 635 |  |  |  |  |  |  | } | 
| 636 |  |  |  |  |  |  |  | 
| 637 |  |  |  |  |  |  | sub clearerr | 
| 638 |  |  |  |  |  |  | { | 
| 639 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 640 |  |  |  |  |  |  |  | 
| 641 | 0 |  |  |  |  |  | return 0; | 
| 642 |  |  |  |  |  |  | } | 
| 643 |  |  |  |  |  |  |  | 
| 644 | 0 |  |  | 0 |  |  | sub binmode { 1 } | 
| 645 |  |  |  |  |  |  | #    sub clearerr { $Archive::Zip::SimpleZip::SimpleZipError = '' } | 
| 646 |  |  |  |  |  |  |  | 
| 647 |  |  |  |  |  |  | *FILENO   = \&fileno; | 
| 648 |  |  |  |  |  |  | *PRINT    = \&print; | 
| 649 |  |  |  |  |  |  | *PRINTF   = \&printf; | 
| 650 |  |  |  |  |  |  | *WRITE    = \&syswrite; | 
| 651 |  |  |  |  |  |  | *write    = \&syswrite; | 
| 652 |  |  |  |  |  |  | *TELL     = \&tell; | 
| 653 |  |  |  |  |  |  | *EOF      = \&eof; | 
| 654 |  |  |  |  |  |  | *CLOSE    = \&close; | 
| 655 |  |  |  |  |  |  | *BINMODE  = \&binmode; | 
| 656 |  |  |  |  |  |  | } | 
| 657 |  |  |  |  |  |  |  | 
| 658 |  |  |  |  |  |  | #{ | 
| 659 |  |  |  |  |  |  | #    package Archive::Zip::SimpleZip::HandleNEW ; | 
| 660 |  |  |  |  |  |  | # | 
| 661 |  |  |  |  |  |  | ## TODO - fix this | 
| 662 |  |  |  |  |  |  | ##    require Tie::Handle; | 
| 663 |  |  |  |  |  |  | ## | 
| 664 |  |  |  |  |  |  | ##    @ISA = qw(Tie::Handle); | 
| 665 |  |  |  |  |  |  | ##@ISA = qw(IO::Handle) ; | 
| 666 |  |  |  |  |  |  | # | 
| 667 |  |  |  |  |  |  | #    sub TIEHANDLE | 
| 668 |  |  |  |  |  |  | #    { | 
| 669 |  |  |  |  |  |  | #        my $class = shift; | 
| 670 |  |  |  |  |  |  | #        my $parent = shift; | 
| 671 |  |  |  |  |  |  | #        my $zip = shift; | 
| 672 |  |  |  |  |  |  | #        my $errorRef = shift; | 
| 673 |  |  |  |  |  |  | # | 
| 674 |  |  |  |  |  |  | #        my %obj = ( | 
| 675 |  |  |  |  |  |  | #            Zip  => $zip , | 
| 676 |  |  |  |  |  |  | #            SZ   => $parent, | 
| 677 |  |  |  |  |  |  | #            Open => 1, | 
| 678 |  |  |  |  |  |  | #        ) ; | 
| 679 |  |  |  |  |  |  | # | 
| 680 |  |  |  |  |  |  | #        Scalar::Util::weaken $obj{SZ}; # for 5.8 | 
| 681 |  |  |  |  |  |  | #        return bless \%obj, $class; | 
| 682 |  |  |  |  |  |  | #    } | 
| 683 |  |  |  |  |  |  | # | 
| 684 |  |  |  |  |  |  | #    sub UNTIE | 
| 685 |  |  |  |  |  |  | #    { | 
| 686 |  |  |  |  |  |  | #        my $self = shift ; | 
| 687 |  |  |  |  |  |  | #    } | 
| 688 |  |  |  |  |  |  | # | 
| 689 |  |  |  |  |  |  | #    sub DESTROY | 
| 690 |  |  |  |  |  |  | #    { | 
| 691 |  |  |  |  |  |  | #        my $self = shift ; | 
| 692 |  |  |  |  |  |  | #        local ($., $@, $!, $^E, $?); | 
| 693 |  |  |  |  |  |  | #        $self->close() ; | 
| 694 |  |  |  |  |  |  | # | 
| 695 |  |  |  |  |  |  | #        # TODO - memory leak with 5.8.0 - this isn't called until | 
| 696 |  |  |  |  |  |  | #        #        global destruction | 
| 697 |  |  |  |  |  |  | #        # | 
| 698 |  |  |  |  |  |  | #        %{ $self } = () ; | 
| 699 |  |  |  |  |  |  | #        undef $self ; | 
| 700 |  |  |  |  |  |  | #    } | 
| 701 |  |  |  |  |  |  | # | 
| 702 |  |  |  |  |  |  | #    sub close | 
| 703 |  |  |  |  |  |  | #    { | 
| 704 |  |  |  |  |  |  | #        my $self = shift ; | 
| 705 |  |  |  |  |  |  | #        return 1 if ! $self->{Open}; | 
| 706 |  |  |  |  |  |  | # | 
| 707 |  |  |  |  |  |  | #        $self->{Open} = 0 ; | 
| 708 |  |  |  |  |  |  | # | 
| 709 |  |  |  |  |  |  | ##        untie *$self | 
| 710 |  |  |  |  |  |  | ##            if $] >= 5.008 ; | 
| 711 |  |  |  |  |  |  | # | 
| 712 |  |  |  |  |  |  | #        if (defined $self->{SZ}) | 
| 713 |  |  |  |  |  |  | #        { | 
| 714 |  |  |  |  |  |  | #            $self->{SZ}{Raw} = undef ; | 
| 715 |  |  |  |  |  |  | #            $self->{SZ} = undef ; | 
| 716 |  |  |  |  |  |  | #        } | 
| 717 |  |  |  |  |  |  | # | 
| 718 |  |  |  |  |  |  | #        1; | 
| 719 |  |  |  |  |  |  | #    } | 
| 720 |  |  |  |  |  |  | # | 
| 721 |  |  |  |  |  |  | #    sub print | 
| 722 |  |  |  |  |  |  | #    { | 
| 723 |  |  |  |  |  |  | #        my $self = shift; | 
| 724 |  |  |  |  |  |  | #        $self->_stdPreq() or return 0 ; | 
| 725 |  |  |  |  |  |  | # | 
| 726 |  |  |  |  |  |  | #        $self->{Zip}->print(@_); | 
| 727 |  |  |  |  |  |  | #    } | 
| 728 |  |  |  |  |  |  | # | 
| 729 |  |  |  |  |  |  | #    sub printf | 
| 730 |  |  |  |  |  |  | #    { | 
| 731 |  |  |  |  |  |  | #        my $self = shift; | 
| 732 |  |  |  |  |  |  | #        $self->_stdPreq() or return 0 ; | 
| 733 |  |  |  |  |  |  | # | 
| 734 |  |  |  |  |  |  | #        $self->{Zip}->printf(@_); | 
| 735 |  |  |  |  |  |  | #    } | 
| 736 |  |  |  |  |  |  | # | 
| 737 |  |  |  |  |  |  | #    sub syswrite | 
| 738 |  |  |  |  |  |  | #    { | 
| 739 |  |  |  |  |  |  | #        my $self = shift; | 
| 740 |  |  |  |  |  |  | #        $self->_stdPreq() or return 0 ; | 
| 741 |  |  |  |  |  |  | # | 
| 742 |  |  |  |  |  |  | #        $self->{Zip}->syswrite(@_); | 
| 743 |  |  |  |  |  |  | #    } | 
| 744 |  |  |  |  |  |  | # | 
| 745 |  |  |  |  |  |  | #    sub tell | 
| 746 |  |  |  |  |  |  | #    { | 
| 747 |  |  |  |  |  |  | #        my $self = shift; | 
| 748 |  |  |  |  |  |  | #        $self->_stdPreq() or return 0 ; | 
| 749 |  |  |  |  |  |  | # | 
| 750 |  |  |  |  |  |  | #        $self->{Zip}->tell(@_); | 
| 751 |  |  |  |  |  |  | #    } | 
| 752 |  |  |  |  |  |  | # | 
| 753 |  |  |  |  |  |  | #    sub eof | 
| 754 |  |  |  |  |  |  | #    { | 
| 755 |  |  |  |  |  |  | #        my $self = shift; | 
| 756 |  |  |  |  |  |  | #        $self->_stdPreq() or return 0 ; | 
| 757 |  |  |  |  |  |  | # | 
| 758 |  |  |  |  |  |  | #        $self->{Zip}->eof; | 
| 759 |  |  |  |  |  |  | #    } | 
| 760 |  |  |  |  |  |  | # | 
| 761 |  |  |  |  |  |  | #    sub _stdPreq | 
| 762 |  |  |  |  |  |  | #    { | 
| 763 |  |  |  |  |  |  | #        my $self = shift; | 
| 764 |  |  |  |  |  |  | # | 
| 765 |  |  |  |  |  |  | #        return _setError("Zip file closed") | 
| 766 |  |  |  |  |  |  | #            if ! defined defined $self->{SZ} || ! $self->{SZ}{Open} ; | 
| 767 |  |  |  |  |  |  | # | 
| 768 |  |  |  |  |  |  | # | 
| 769 |  |  |  |  |  |  | #        return _setError("openMember filehandle closed") | 
| 770 |  |  |  |  |  |  | #            if  ! $self->{Open} || ! defined $self->{SZ}{Raw}; | 
| 771 |  |  |  |  |  |  | # | 
| 772 |  |  |  |  |  |  | #        return 0 | 
| 773 |  |  |  |  |  |  | #            if $self->{SZ}{Error} ; | 
| 774 |  |  |  |  |  |  | # | 
| 775 |  |  |  |  |  |  | #         return 1; | 
| 776 |  |  |  |  |  |  | #    } | 
| 777 |  |  |  |  |  |  | # | 
| 778 |  |  |  |  |  |  | #    sub _setError | 
| 779 |  |  |  |  |  |  | #    { | 
| 780 |  |  |  |  |  |  | #        $Archive::Zip::SimpleZip::SimpleZipError = $_[0] ; | 
| 781 |  |  |  |  |  |  | #        return 0; | 
| 782 |  |  |  |  |  |  | #    } | 
| 783 |  |  |  |  |  |  | # | 
| 784 |  |  |  |  |  |  | #    sub binmode { 1 } | 
| 785 |  |  |  |  |  |  | ##    sub clearerr { $Archive::Zip::SimpleZip::SimpleZipError = '' } | 
| 786 |  |  |  |  |  |  | # | 
| 787 |  |  |  |  |  |  | #    *FILENO   = \&fileno; | 
| 788 |  |  |  |  |  |  | #    *PRINT    = \&print; | 
| 789 |  |  |  |  |  |  | #    *PRINTF   = \&printf; | 
| 790 |  |  |  |  |  |  | #    *WRITE    = \&syswrite; | 
| 791 |  |  |  |  |  |  | #    *write    = \&syswrite; | 
| 792 |  |  |  |  |  |  | #    *TELL     = \&tell; | 
| 793 |  |  |  |  |  |  | ##    sub IO::Handle::tell { bless $_[0], "Archive::Zip::SimpleZip::Handle" ; Archive::Zip::SimpleZip::Handle::tell @_ }; | 
| 794 |  |  |  |  |  |  | #    *EOF      = \&eof; | 
| 795 |  |  |  |  |  |  | #    *CLOSE    = \&close; | 
| 796 |  |  |  |  |  |  | #    *BINMODE  = \&binmode; | 
| 797 |  |  |  |  |  |  | #} | 
| 798 |  |  |  |  |  |  |  | 
| 799 |  |  |  |  |  |  | 1; | 
| 800 |  |  |  |  |  |  |  | 
| 801 |  |  |  |  |  |  | __END__ |