Create IO-Compress
[p5sagit/p5-mst-13.2.git] / ext / IO-Compress / lib / IO / Compress / Zip.pm
CommitLineData
25f0751f 1package IO::Compress::Zip ;
2
3use strict ;
4use warnings;
5use bytes;
6
319fab50 7use IO::Compress::Base::Common 2.017 qw(:Status createSelfTiedObject);
8use IO::Compress::RawDeflate 2.017 ;
9use IO::Compress::Adapter::Deflate 2.017 ;
10use IO::Compress::Adapter::Identity 2.017 ;
11use IO::Compress::Zlib::Extra 2.017 ;
12use IO::Compress::Zip::Constants 2.017 ;
c70c1701 13
25f0751f 14
319fab50 15use Compress::Raw::Zlib 2.017 qw(crc32) ;
2b4e0969 16BEGIN
17{
b0cda13f 18 eval { require IO::Compress::Adapter::Bzip2 ;
319fab50 19 import IO::Compress::Adapter::Bzip2 2.017 ;
b0cda13f 20 require IO::Compress::Bzip2 ;
319fab50 21 import IO::Compress::Bzip2 2.017 ;
2b4e0969 22 } ;
319fab50 23# eval { require IO::Compress::Adapter::Lzma ;
24# import IO::Compress::Adapter::Lzma 2.016 ;
25# require IO::Compress::Lzma ;
26# import IO::Compress::Lzma 2.016 ;
27# } ;
2b4e0969 28}
29
30
25f0751f 31require Exporter ;
32
33our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $ZipError);
34
319fab50 35$VERSION = '2.017';
25f0751f 36$ZipError = '';
37
38@ISA = qw(Exporter IO::Compress::RawDeflate);
39@EXPORT_OK = qw( $ZipError zip ) ;
40%EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ;
41push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
2b4e0969 42
43$EXPORT_TAGS{zip_method} = [qw( ZIP_CM_STORE ZIP_CM_DEFLATE ZIP_CM_BZIP2 )];
44push @{ $EXPORT_TAGS{all} }, @{ $EXPORT_TAGS{zip_method} };
45
25f0751f 46Exporter::export_ok_tags('all');
47
25f0751f 48sub new
49{
50 my $class = shift ;
51
52 my $obj = createSelfTiedObject($class, \$ZipError);
53 $obj->_create(undef, @_);
54}
55
56sub zip
57{
58 my $obj = createSelfTiedObject(undef, \$ZipError);
59 return $obj->_def(@_);
60}
61
62sub mkComp
63{
64 my $self = shift ;
25f0751f 65 my $got = shift ;
66
67 my ($obj, $errstr, $errno) ;
68
2b4e0969 69 if (*$self->{ZipData}{Method} == ZIP_CM_STORE) {
25f0751f 70 ($obj, $errstr, $errno) = IO::Compress::Adapter::Identity::mkCompObject(
25f0751f 71 $got->value('Level'),
72 $got->value('Strategy')
73 );
74 }
2b4e0969 75 elsif (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
25f0751f 76 ($obj, $errstr, $errno) = IO::Compress::Adapter::Deflate::mkCompObject(
77 $got->value('CRC32'),
78 $got->value('Adler32'),
79 $got->value('Level'),
80 $got->value('Strategy')
81 );
82 }
2b4e0969 83 elsif (*$self->{ZipData}{Method} == ZIP_CM_BZIP2) {
84 ($obj, $errstr, $errno) = IO::Compress::Adapter::Bzip2::mkCompObject(
85 $got->value('BlockSize100K'),
86 $got->value('WorkFactor'),
87 $got->value('Verbosity')
88 );
89 *$self->{ZipData}{CRC32} = crc32(undef);
90 }
319fab50 91# elsif (*$self->{ZipData}{Method} == ZIP_CM_LZMA) {
92# ($obj, $errstr, $errno) = IO::Compress::Adapter::Lzma::mkCompObject(
93# );
94# *$self->{ZipData}{CRC32} = crc32(undef);
95# }
25f0751f 96
97 return $self->saveErrorString(undef, $errstr, $errno)
98 if ! defined $obj;
99
100 if (! defined *$self->{ZipData}{StartOffset}) {
e7d45986 101 *$self->{ZipData}{StartOffset} = 0;
102 *$self->{ZipData}{Offset} = new U64 ;
25f0751f 103 }
104
105 return $obj;
106}
107
2b4e0969 108sub reset
109{
110 my $self = shift ;
111
112 *$self->{Compress}->reset();
113 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32('');
114
115 return STATUS_OK;
116}
117
118sub filterUncompressed
119{
120 my $self = shift ;
25f0751f 121
2b4e0969 122 if (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
123 *$self->{ZipData}{CRC32} = *$self->{Compress}->crc32();
124 }
125 else {
126 *$self->{ZipData}{CRC32} = crc32(${$_[0]}, *$self->{ZipData}{CRC32});
127
128 }
129}
25f0751f 130
131sub mkHeader
132{
133 my $self = shift;
134 my $param = shift ;
135
e7d45986 136 *$self->{ZipData}{StartOffset} = *$self->{ZipData}{Offset}->get32bit() ;
c70c1701 137
25f0751f 138 my $filename = '';
139 $filename = $param->value('Name') || '';
140
141 my $comment = '';
142 $comment = $param->value('Comment') || '';
143
25f0751f 144 my $hdr = '';
145
146 my $time = _unixToDosTime($param->value('Time'));
25f0751f 147
c70c1701 148 my $extra = '';
149 my $ctlExtra = '';
e7d45986 150 my $empty = 0;
4e7676c7 151 my $osCode = $param->value('OS_Code') ;
152 my $extFileAttr = 0 ;
d54256af 153
154 # This code assumes Unix.
155 $extFileAttr = 0666 << 16
156 if $osCode == ZIP_OS_CODE_UNIX ;
e7d45986 157
158 if (*$self->{ZipData}{Zip64}) {
319fab50 159 $empty = 0xFFFFFFFF;
e7d45986 160
161 my $x = '';
162 $x .= pack "V V", 0, 0 ; # uncompressedLength
163 $x .= pack "V V", 0, 0 ; # compressedLength
164 $x .= *$self->{ZipData}{Offset}->getPacked_V64() ; # offset to local hdr
319fab50 165 $x .= pack "V", 0 ; # disk no
e7d45986 166
167 $x = IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_ZIP64, $x);
168 $extra .= $x;
169 $ctlExtra .= $x;
170 }
c70c1701 171
172 if (! $param->value('Minimal')) {
173 if (defined $param->value('exTime'))
174 {
175 $extra .= mkExtendedTime($param->value('MTime'),
176 $param->value('ATime'),
177 $param->value('CTime'));
178
179 $ctlExtra .= mkExtendedTime($param->value('MTime'));
180 }
181
4e7676c7 182 if ( $param->value('UID') && $osCode == ZIP_OS_CODE_UNIX)
183 {
184 $extra .= mkUnix2Extra( $param->value('UID'), $param->value('GID'));
185 $ctlExtra .= mkUnix2Extra();
186 }
187
4e7676c7 188 $extFileAttr = $param->value('ExtAttr')
189 if defined $param->value('ExtAttr') ;
c70c1701 190
191 $extra .= $param->value('ExtraFieldLocal')
192 if defined $param->value('ExtraFieldLocal');
193
194 $ctlExtra .= $param->value('ExtraFieldCentral')
195 if defined $param->value('ExtraFieldCentral');
196 }
197
c70c1701 198 my $gpFlag = 0 ;
199 $gpFlag |= ZIP_GP_FLAG_STREAMING_MASK
200 if *$self->{ZipData}{Stream} ;
201
2b4e0969 202 my $method = *$self->{ZipData}{Method} ;
203
e7d45986 204 my $version = $ZIP_CM_MIN_VERSIONS{$method};
205 $version = ZIP64_MIN_VERSION
206 if ZIP64_MIN_VERSION > $version && *$self->{ZipData}{Zip64};
207 my $madeBy = ($param->value('OS_Code') << 8) + $version;
208 my $extract = $version;
209
210 *$self->{ZipData}{Version} = $version;
211 *$self->{ZipData}{MadeBy} = $madeBy;
c70c1701 212
213 my $ifa = 0;
214 $ifa |= ZIP_IFA_TEXT_MASK
215 if $param->value('TextFlag');
25f0751f 216
2b4e0969 217 $hdr .= pack "V", ZIP_LOCAL_HDR_SIG ; # signature
25f0751f 218 $hdr .= pack 'v', $extract ; # extract Version & OS
c70c1701 219 $hdr .= pack 'v', $gpFlag ; # general purpose flag (set streaming mode)
25f0751f 220 $hdr .= pack 'v', $method ; # compression method (deflate)
221 $hdr .= pack 'V', $time ; # last mod date/time
222 $hdr .= pack 'V', 0 ; # crc32 - 0 when streaming
e7d45986 223 $hdr .= pack 'V', $empty ; # compressed length - 0 when streaming
224 $hdr .= pack 'V', $empty ; # uncompressed length - 0 when streaming
25f0751f 225 $hdr .= pack 'v', length $filename ; # filename length
c70c1701 226 $hdr .= pack 'v', length $extra ; # extra length
25f0751f 227
228 $hdr .= $filename ;
c70c1701 229 $hdr .= $extra ;
25f0751f 230
231
232 my $ctl = '';
233
2b4e0969 234 $ctl .= pack "V", ZIP_CENTRAL_HDR_SIG ; # signature
c70c1701 235 $ctl .= pack 'v', $madeBy ; # version made by
25f0751f 236 $ctl .= pack 'v', $extract ; # extract Version
c70c1701 237 $ctl .= pack 'v', $gpFlag ; # general purpose flag (streaming mode)
25f0751f 238 $ctl .= pack 'v', $method ; # compression method (deflate)
239 $ctl .= pack 'V', $time ; # last mod date/time
240 $ctl .= pack 'V', 0 ; # crc32
e7d45986 241 $ctl .= pack 'V', $empty ; # compressed length
242 $ctl .= pack 'V', $empty ; # uncompressed length
25f0751f 243 $ctl .= pack 'v', length $filename ; # filename length
c70c1701 244 $ctl .= pack 'v', length $ctlExtra ; # extra length
25f0751f 245 $ctl .= pack 'v', length $comment ; # file comment length
246 $ctl .= pack 'v', 0 ; # disk number start
c70c1701 247 $ctl .= pack 'v', $ifa ; # internal file attributes
4e7676c7 248 $ctl .= pack 'V', $extFileAttr ; # external file attributes
e7d45986 249 if (! *$self->{ZipData}{Zip64}) {
250 $ctl .= pack 'V', *$self->{ZipData}{Offset}->get32bit() ; # offset to local header
251 }
252 else {
253 $ctl .= pack 'V', $empty ; # offset to local header
254 }
25f0751f 255
256 $ctl .= $filename ;
e7d45986 257 *$self->{ZipData}{StartOffset64} = 4 + length $ctl;
c70c1701 258 $ctl .= $ctlExtra ;
25f0751f 259 $ctl .= $comment ;
260
e7d45986 261 *$self->{ZipData}{Offset}->add(length $hdr) ;
25f0751f 262
263 *$self->{ZipData}{CentralHeader} = $ctl;
264
265 return $hdr;
266}
267
268sub mkTrailer
269{
270 my $self = shift ;
271
2b4e0969 272 my $crc32 ;
273 if (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
e7d45986 274 $crc32 = pack "V", *$self->{Compress}->crc32();
2b4e0969 275 }
276 else {
e7d45986 277 $crc32 = pack "V", *$self->{ZipData}{CRC32};
2b4e0969 278 }
279
e7d45986 280 my $ctl = *$self->{ZipData}{CentralHeader} ;
281
282 my $sizes ;
283 if (! *$self->{ZipData}{Zip64}) {
284 $sizes .= *$self->{CompSize}->getPacked_V32() ; # Compressed size
285 $sizes .= *$self->{UnCompSize}->getPacked_V32() ; # Uncompressed size
286 }
287 else {
288 $sizes .= *$self->{CompSize}->getPacked_V64() ; # Compressed size
289 $sizes .= *$self->{UnCompSize}->getPacked_V64() ; # Uncompressed size
290 }
291
292 my $data = $crc32 . $sizes ;
25f0751f 293
25f0751f 294
295 my $hdr = '';
296
297 if (*$self->{ZipData}{Stream}) {
2b4e0969 298 $hdr = pack "V", ZIP_DATA_HDR_SIG ; # signature
25f0751f 299 $hdr .= $data ;
300 }
301 else {
302 $self->writeAt(*$self->{ZipData}{StartOffset} + 14, $data)
303 or return undef;
304 }
305
e7d45986 306 if (! *$self->{ZipData}{Zip64})
307 { substr($ctl, 16, length $data) = $data }
308 else {
309 substr($ctl, 16, length $crc32) = $crc32 ;
310 my $s = *$self->{UnCompSize}->getPacked_V64() ; # Uncompressed size
311 $s .= *$self->{CompSize}->getPacked_V64() ; # Compressed size
312 substr($ctl, *$self->{ZipData}{StartOffset64}, length $s) = $s ;
313 }
25f0751f 314
e7d45986 315 *$self->{ZipData}{Offset}->add(length($hdr));
316 *$self->{ZipData}{Offset}->add( *$self->{CompSize} );
25f0751f 317 push @{ *$self->{ZipData}{CentralDir} }, $ctl ;
318
319 return $hdr;
320}
321
322sub mkFinalTrailer
323{
324 my $self = shift ;
325
326 my $comment = '';
327 $comment = *$self->{ZipData}{ZipComment} ;
328
e7d45986 329 my $cd_offset = *$self->{ZipData}{Offset}->get32bit() ; # offset to start central dir
330
25f0751f 331 my $entries = @{ *$self->{ZipData}{CentralDir} };
332 my $cd = join '', @{ *$self->{ZipData}{CentralDir} };
e7d45986 333 my $cd_len = length $cd ;
334
335 my $z64e = '';
336
337 if ( *$self->{ZipData}{Zip64} ) {
338
339 my $v = *$self->{ZipData}{Version} ;
340 my $mb = *$self->{ZipData}{MadeBy} ;
341 $z64e .= pack 'v', $v ; # Version made by
342 $z64e .= pack 'v', $mb ; # Version to extract
343 $z64e .= pack 'V', 0 ; # number of disk
344 $z64e .= pack 'V', 0 ; # number of disk with central dir
345 $z64e .= U64::pack_V64 $entries ; # entries in central dir on this disk
346 $z64e .= U64::pack_V64 $entries ; # entries in central dir
347 $z64e .= U64::pack_V64 $cd_len ; # size of central dir
348 $z64e .= *$self->{ZipData}{Offset}->getPacked_V64() ; # offset to start central dir
349
350 $z64e = pack("V", ZIP64_END_CENTRAL_REC_HDR_SIG) # signature
351 . U64::pack_V64(length $z64e)
352 . $z64e ;
353
354 *$self->{ZipData}{Offset}->add(length $cd) ;
355
356 $z64e .= pack "V", ZIP64_END_CENTRAL_LOC_HDR_SIG; # signature
357 $z64e .= pack 'V', 0 ; # number of disk with central dir
358 $z64e .= *$self->{ZipData}{Offset}->getPacked_V64() ; # offset to end zip64 central dir
359 $z64e .= pack 'V', 1 ; # Total number of disks
360
361 # TODO - fix these when info-zip 3 is fixed.
362 #$cd_len =
363 #$cd_offset =
364 $entries = 0xFFFF ;
365 }
25f0751f 366
367 my $ecd = '';
2b4e0969 368 $ecd .= pack "V", ZIP_END_CENTRAL_HDR_SIG ; # signature
25f0751f 369 $ecd .= pack 'v', 0 ; # number of disk
e7d45986 370 $ecd .= pack 'v', 0 ; # number of disk with central dir
25f0751f 371 $ecd .= pack 'v', $entries ; # entries in central dir on this disk
372 $ecd .= pack 'v', $entries ; # entries in central dir
e7d45986 373 $ecd .= pack 'V', $cd_len ; # size of central dir
374 $ecd .= pack 'V', $cd_offset ; # offset to start central dir
25f0751f 375 $ecd .= pack 'v', length $comment ; # zipfile comment length
376 $ecd .= $comment;
377
e7d45986 378 return $cd . $z64e . $ecd ;
25f0751f 379}
380
381sub ckParams
382{
383 my $self = shift ;
384 my $got = shift;
385
386 $got->value('CRC32' => 1);
387
388 if (! $got->parsed('Time') ) {
389 # Modification time defaults to now.
390 $got->value('Time' => time) ;
391 }
392
c70c1701 393 if (! $got->parsed('exTime') ) {
394 my $timeRef = $got->value('exTime');
395 if ( defined $timeRef) {
396 return $self->saveErrorString(undef, "exTime not a 3-element array ref")
397 if ref $timeRef ne 'ARRAY' || @$timeRef != 3;
398 }
399
400 $got->value("MTime", $timeRef->[1]);
401 $got->value("ATime", $timeRef->[0]);
402 $got->value("CTime", $timeRef->[2]);
403 }
d54256af 404
405 # Unix2 Extended Attribute
406 if (! $got->parsed('exUnix2') ) {
407 my $timeRef = $got->value('exUnix2');
408 if ( defined $timeRef) {
409 return $self->saveErrorString(undef, "exUnix2 not a 2-element array ref")
410 if ref $timeRef ne 'ARRAY' || @$timeRef != 2;
411 }
412
413 $got->value("UID", $timeRef->[0]);
414 $got->value("GID", $timeRef->[1]);
415 }
c70c1701 416
e7d45986 417 *$self->{ZipData}{Zip64} = $got->value('Zip64');
25f0751f 418 *$self->{ZipData}{Stream} = $got->value('Stream');
2b4e0969 419
e7d45986 420 return $self->saveErrorString(undef, "Zip64 only supported if Stream enabled")
421 if *$self->{ZipData}{Zip64} && ! *$self->{ZipData}{Stream} ;
422
2b4e0969 423 my $method = $got->value('Method');
2b4e0969 424 return $self->saveErrorString(undef, "Unknown Method '$method'")
425 if ! defined $ZIP_CM_MIN_VERSIONS{$method};
426
427 return $self->saveErrorString(undef, "Bzip2 not available")
428 if $method == ZIP_CM_BZIP2 and
429 ! defined $IO::Compress::Adapter::Bzip2::VERSION;
430
319fab50 431# return $self->saveErrorString(undef, "Lzma not available")
432# if $method == ZIP_CM_LZMA and
433# ! defined $IO::Compress::Adapter::Lzma::VERSION;
434
2b4e0969 435 *$self->{ZipData}{Method} = $method;
436
25f0751f 437 *$self->{ZipData}{ZipComment} = $got->value('ZipComment') ;
438
c70c1701 439 for my $name (qw( ExtraFieldLocal ExtraFieldCentral ))
440 {
441 my $data = $got->value($name) ;
442 if (defined $data) {
443 my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, 1, 0) ;
444 return $self->saveErrorString(undef, "Error with $name Parameter: $bad")
445 if $bad ;
446
447 $got->value($name, $data) ;
448 }
449 }
450
2b4e0969 451 return undef
452 if defined $IO::Compress::Bzip2::VERSION
453 and ! IO::Compress::Bzip2::ckParams($self, $got);
25f0751f 454
455 return 1 ;
456}
457
458#sub newHeader
459#{
460# my $self = shift ;
461#
462# return $self->mkHeader(*$self->{Got});
463#}
464
465sub getExtraParams
466{
467 my $self = shift ;
468
319fab50 469 use IO::Compress::Base::Common 2.017 qw(:Parse);
470 use Compress::Raw::Zlib 2.017 qw(Z_DEFLATED Z_DEFAULT_COMPRESSION Z_DEFAULT_STRATEGY);
25f0751f 471
2b4e0969 472 my @Bzip2 = ();
473
474 @Bzip2 = IO::Compress::Bzip2::getExtraParams($self)
475 if defined $IO::Compress::Bzip2::VERSION;
25f0751f 476
477 return (
478 # zlib behaviour
479 $self->getZlibParams(),
480
481 'Stream' => [1, 1, Parse_boolean, 1],
2b4e0969 482 #'Store' => [0, 1, Parse_boolean, 0],
483 'Method' => [0, 1, Parse_unsigned, ZIP_CM_DEFLATE],
25f0751f 484
485# # Zip header fields
c70c1701 486 'Minimal' => [0, 1, Parse_boolean, 0],
e7d45986 487 'Zip64' => [0, 1, Parse_boolean, 0],
25f0751f 488 'Comment' => [0, 1, Parse_any, ''],
489 'ZipComment'=> [0, 1, Parse_any, ''],
490 'Name' => [0, 1, Parse_any, ''],
491 'Time' => [0, 1, Parse_any, undef],
c70c1701 492 'exTime' => [0, 1, Parse_any, undef],
d54256af 493 'exUnix2' => [0, 1, Parse_any, undef],
4e7676c7 494 'ExtAttr' => [0, 1, Parse_any, 0],
25f0751f 495 'OS_Code' => [0, 1, Parse_unsigned, $Compress::Raw::Zlib::gzip_os_code],
496
c70c1701 497 'TextFlag' => [0, 1, Parse_boolean, 0],
498 'ExtraFieldLocal' => [0, 1, Parse_any, undef],
499 'ExtraFieldCentral'=> [0, 1, Parse_any, undef],
2b4e0969 500
501 @Bzip2,
25f0751f 502 );
503}
504
505sub getInverseClass
506{
507 return ('IO::Uncompress::Unzip',
508 \$IO::Uncompress::Unzip::UnzipError);
509}
510
511sub getFileInfo
512{
513 my $self = shift ;
514 my $params = shift;
515 my $filename = shift ;
516
c70c1701 517 my ($mode, $uid, $gid, $atime, $mtime, $ctime)
518 = (stat($filename))[2, 4,5, 8,9,10] ;
25f0751f 519
520 $params->value('Name' => $filename)
521 if ! $params->parsed('Name') ;
522
c70c1701 523 $params->value('Time' => $mtime)
25f0751f 524 if ! $params->parsed('Time') ;
525
c70c1701 526 if ( ! $params->parsed('exTime'))
527 {
528 $params->value('MTime' => $mtime) ;
529 $params->value('ATime' => $atime) ;
4e7676c7 530 $params->value('CTime' => undef) ; # No Creation time
c70c1701 531 }
532
d54256af 533 # NOTE - Unix specific code alert
4e7676c7 534 $params->value('ExtAttr' => $mode << 16)
535 if ! $params->parsed('ExtAttr');
c70c1701 536
537 $params->value('UID' => $uid) ;
538 $params->value('GID' => $gid) ;
25f0751f 539
540}
541
c70c1701 542sub mkExtendedTime
543{
544 # order expected is m, a, c
545
546 my $times = '';
547 my $bit = 1 ;
548 my $flags = 0;
549
550 for my $time (@_)
551 {
552 if (defined $time)
553 {
554 $flags |= $bit;
555 $times .= pack("V", $time);
556 }
557
558 $bit <<= 1 ;
559 }
560
c70c1701 561 return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_EXT_TIMESTAMP,
562 pack("C", $flags) . $times);
563}
564
4e7676c7 565sub mkUnix2Extra
c70c1701 566{
567 my $ids = '';
568 for my $id (@_)
569 {
570 $ids .= pack("v", $id);
571 }
572
4e7676c7 573 return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_INFO_ZIP_UNIX2,
574 $ids);
c70c1701 575}
576
577
25f0751f 578# from Archive::Zip
579sub _unixToDosTime # Archive::Zip::Member
580{
581 my $time_t = shift;
582 # TODO - add something to cope with unix time < 1980
583 my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime($time_t);
584 my $dt = 0;
585 $dt += ( $sec >> 1 );
586 $dt += ( $min << 5 );
587 $dt += ( $hour << 11 );
588 $dt += ( $mday << 16 );
589 $dt += ( ( $mon + 1 ) << 21 );
590 $dt += ( ( $year - 80 ) << 25 );
591 return $dt;
592}
593
5941;
595
596__END__
597
598=head1 NAME
599
cb7abd7f 600IO::Compress::Zip - Write zip files/buffers
601
25f0751f 602
603
604=head1 SYNOPSIS
605
606 use IO::Compress::Zip qw(zip $ZipError) ;
607
25f0751f 608 my $status = zip $input => $output [,OPTS]
609 or die "zip failed: $ZipError\n";
610
611 my $z = new IO::Compress::Zip $output [,OPTS]
612 or die "zip failed: $ZipError\n";
613
614 $z->print($string);
615 $z->printf($format, $string);
616 $z->write($string);
617 $z->syswrite($string [, $length, $offset]);
618 $z->flush();
619 $z->tell();
620 $z->eof();
621 $z->seek($position, $whence);
622 $z->binmode();
623 $z->fileno();
624 $z->opened();
625 $z->autoflush();
626 $z->input_line_number();
627 $z->newStream( [OPTS] );
628
629 $z->deflateParams();
630
631 $z->close() ;
632
633 $ZipError ;
634
635 # IO::File mode
636
637 print $z $string;
638 printf $z $format, $string;
639 tell $z
640 eof $z
641 seek $z, $position, $whence
642 binmode $z
643 fileno $z
644 close $z ;
645
646
647=head1 DESCRIPTION
648
25f0751f 649This module provides a Perl interface that allows writing zip
650compressed data to files or buffer.
651
258133d1 652The primary purpose of this module is to provide streaming write access to
653zip files and buffers. It is not a general-purpose file archiver. If that
654is what you want, check out C<Archive::Zip>.
655
4e7676c7 656At present three compression methods are supported by IO::Compress::Zip,
657namely Store (no compression at all), Deflate and Bzip2.
658
659Note that to create Bzip2 content, the module C<IO::Compress::Bzip2> must
660be installed.
661
25f0751f 662For reading zip files/buffers, see the companion module
663L<IO::Uncompress::Unzip|IO::Uncompress::Unzip>.
664
25f0751f 665=head1 Functional Interface
666
667A top-level function, C<zip>, is provided to carry out
668"one-shot" compression between buffers and/or files. For finer
669control over the compression process, see the L</"OO Interface">
670section.
671
672 use IO::Compress::Zip qw(zip $ZipError) ;
673
674 zip $input => $output [,OPTS]
675 or die "zip failed: $ZipError\n";
676
25f0751f 677The functional interface needs Perl5.005 or better.
678
25f0751f 679=head2 zip $input => $output [, OPTS]
680
25f0751f 681C<zip> expects at least two parameters, C<$input> and C<$output>.
682
683=head3 The C<$input> parameter
684
685The parameter, C<$input>, is used to define the source of
686the uncompressed data.
687
688It can take one of the following forms:
689
690=over 5
691
692=item A filename
693
694If the C<$input> parameter is a simple scalar, it is assumed to be a
695filename. This file will be opened for reading and the input data
696will be read from it.
697
698=item A filehandle
699
700If the C<$input> parameter is a filehandle, the input data will be
701read from it.
702The string '-' can be used as an alias for standard input.
703
704=item A scalar reference
705
706If C<$input> is a scalar reference, the input data will be read
707from C<$$input>.
708
709=item An array reference
710
711If C<$input> is an array reference, each element in the array must be a
712filename.
713
714The input data will be read from each file in turn.
715
716The complete array will be walked to ensure that it only
717contains valid filenames before any data is compressed.
718
25f0751f 719=item An Input FileGlob string
720
721If C<$input> is a string that is delimited by the characters "<" and ">"
722C<zip> will assume that it is an I<input fileglob string>. The
723input is the list of files that match the fileglob.
724
725If the fileglob does not match any files ...
726
727See L<File::GlobMapper|File::GlobMapper> for more details.
728
25f0751f 729=back
730
731If the C<$input> parameter is any other type, C<undef> will be returned.
732
25f0751f 733In addition, if C<$input> is a simple filename, the default values for
4e7676c7 734the C<Name>, C<Time>, C<ExtAttr> and C<exTime> options will be sourced from that file.
25f0751f 735
736If you do not want to use these defaults they can be overridden by
4e7676c7 737explicitly setting the C<Name>, C<Time>, C<ExtAttr> and C<exTime> options or by setting the
25f0751f 738C<Minimal> parameter.
739
25f0751f 740=head3 The C<$output> parameter
741
742The parameter C<$output> is used to control the destination of the
743compressed data. This parameter can take one of these forms.
744
745=over 5
746
747=item A filename
748
749If the C<$output> parameter is a simple scalar, it is assumed to be a
750filename. This file will be opened for writing and the compressed
751data will be written to it.
752
753=item A filehandle
754
755If the C<$output> parameter is a filehandle, the compressed data
756will be written to it.
757The string '-' can be used as an alias for standard output.
758
25f0751f 759=item A scalar reference
760
761If C<$output> is a scalar reference, the compressed data will be
762stored in C<$$output>.
763
25f0751f 764=item An Array Reference
765
766If C<$output> is an array reference, the compressed data will be
767pushed onto the array.
768
769=item An Output FileGlob
770
771If C<$output> is a string that is delimited by the characters "<" and ">"
772C<zip> will assume that it is an I<output fileglob string>. The
773output is the list of files that match the fileglob.
774
775When C<$output> is an fileglob string, C<$input> must also be a fileglob
776string. Anything else is an error.
777
778=back
779
780If the C<$output> parameter is any other type, C<undef> will be returned.
781
25f0751f 782=head2 Notes
783
784When C<$input> maps to multiple files/buffers and C<$output> is a single
c70c1701 785file/buffer the input files/buffers will each be stored
786in C<$output> as a distinct entry.
787
25f0751f 788=head2 Optional Parameters
789
790Unless specified below, the optional parameters for C<zip>,
791C<OPTS>, are the same as those used with the OO interface defined in the
792L</"Constructor Options"> section below.
793
794=over 5
795
e7d45986 796=item C<< AutoClose => 0|1 >>
25f0751f 797
798This option applies to any input or output data streams to
799C<zip> that are filehandles.
800
801If C<AutoClose> is specified, and the value is true, it will result in all
802input and/or output filehandles being closed once C<zip> has
803completed.
804
805This parameter defaults to 0.
806
e7d45986 807=item C<< BinModeIn => 0|1 >>
25f0751f 808
809When reading from a file or filehandle, set C<binmode> before reading.
810
811Defaults to 0.
812
e7d45986 813=item C<< Append => 0|1 >>
25f0751f 814
815TODO
816
25f0751f 817=back
818
25f0751f 819=head2 Examples
820
821To read the contents of the file C<file1.txt> and write the compressed
822data to the file C<file1.txt.zip>.
823
824 use strict ;
825 use warnings ;
826 use IO::Compress::Zip qw(zip $ZipError) ;
827
828 my $input = "file1.txt";
829 zip $input => "$input.zip"
830 or die "zip failed: $ZipError\n";
831
25f0751f 832To read from an existing Perl filehandle, C<$input>, and write the
833compressed data to a buffer, C<$buffer>.
834
835 use strict ;
836 use warnings ;
837 use IO::Compress::Zip qw(zip $ZipError) ;
838 use IO::File ;
839
840 my $input = new IO::File "<file1.txt"
841 or die "Cannot open 'file1.txt': $!\n" ;
842 my $buffer ;
843 zip $input => \$buffer
844 or die "zip failed: $ZipError\n";
845
846To compress all files in the directory "/my/home" that match "*.txt"
847and store the compressed data in the same directory
848
849 use strict ;
850 use warnings ;
851 use IO::Compress::Zip qw(zip $ZipError) ;
852
853 zip '</my/home/*.txt>' => '<*.zip>'
854 or die "zip failed: $ZipError\n";
855
856and if you want to compress each file one at a time, this will do the trick
857
858 use strict ;
859 use warnings ;
860 use IO::Compress::Zip qw(zip $ZipError) ;
861
862 for my $input ( glob "/my/home/*.txt" )
863 {
864 my $output = "$input.zip" ;
865 zip $input => $output
866 or die "Error compressing '$input': $ZipError\n";
867 }
868
25f0751f 869=head1 OO Interface
870
871=head2 Constructor
872
873The format of the constructor for C<IO::Compress::Zip> is shown below
874
875 my $z = new IO::Compress::Zip $output [,OPTS]
876 or die "IO::Compress::Zip failed: $ZipError\n";
877
878It returns an C<IO::Compress::Zip> object on success and undef on failure.
879The variable C<$ZipError> will contain an error message on failure.
880
881If you are running Perl 5.005 or better the object, C<$z>, returned from
882IO::Compress::Zip can be used exactly like an L<IO::File|IO::File> filehandle.
883This means that all normal output file operations can be carried out
884with C<$z>.
885For example, to write to a compressed file/buffer you can use either of
886these forms
887
888 $z->print("hello world\n");
889 print $z "hello world\n";
890
891The mandatory parameter C<$output> is used to control the destination
892of the compressed data. This parameter can take one of these forms.
893
894=over 5
895
896=item A filename
897
898If the C<$output> parameter is a simple scalar, it is assumed to be a
899filename. This file will be opened for writing and the compressed data
900will be written to it.
901
902=item A filehandle
903
904If the C<$output> parameter is a filehandle, the compressed data will be
905written to it.
906The string '-' can be used as an alias for standard output.
907
25f0751f 908=item A scalar reference
909
910If C<$output> is a scalar reference, the compressed data will be stored
911in C<$$output>.
912
913=back
914
915If the C<$output> parameter is any other type, C<IO::Compress::Zip>::new will
916return undef.
917
918=head2 Constructor Options
919
920C<OPTS> is any combination of the following options:
921
922=over 5
923
e7d45986 924=item C<< AutoClose => 0|1 >>
25f0751f 925
926This option is only valid when the C<$output> parameter is a filehandle. If
927specified, and the value is true, it will result in the C<$output> being
928closed once either the C<close> method is called or the C<IO::Compress::Zip>
929object is destroyed.
930
931This parameter defaults to 0.
932
e7d45986 933=item C<< Append => 0|1 >>
25f0751f 934
935Opens C<$output> in append mode.
936
937The behaviour of this option is dependent on the type of C<$output>.
938
939=over 5
940
941=item * A Buffer
942
943If C<$output> is a buffer and C<Append> is enabled, all compressed data
944will be append to the end if C<$output>. Otherwise C<$output> will be
945cleared before any data is written to it.
946
947=item * A Filename
948
949If C<$output> is a filename and C<Append> is enabled, the file will be
950opened in append mode. Otherwise the contents of the file, if any, will be
951truncated before any compressed data is written to it.
952
953=item * A Filehandle
954
955If C<$output> is a filehandle, the file pointer will be positioned to the
956end of the file via a call to C<seek> before any compressed data is written
957to it. Otherwise the file pointer will not be moved.
958
959=back
960
961This parameter defaults to 0.
962
e7d45986 963=item C<< Name => $string >>
2b4e0969 964
965Stores the contents of C<$string> in the zip filename header field. If
966C<Name> is not specified, no zip filename field will be created.
967
e7d45986 968=item C<< Time => $number >>
2b4e0969 969
970Sets the last modified time field in the zip header to $number.
971
972This field defaults to the time the C<IO::Compress::Zip> object was created
973if this option is not specified.
974
4e7676c7 975=item C<< ExtAttr => $attr >>
976
977This option controls the "external file attributes" field in the central
978header of the zip file. This is a 4 byte field.
979
d54256af 980If you are running a Unix derivative this value defaults to
981
982 0666 << 16
983
984This should allow read/write access to any files that are extracted from
985the zip file/buffer.
986
987For all other systems it defaults to 0.
4e7676c7 988
e7d45986 989=item C<< exTime => [$atime, $mtime, $ctime] >>
c70c1701 990
991This option expects an array reference with exactly three elements:
992C<$atime>, C<mtime> and C<$ctime>. These correspond to the last access
993time, last modification time and creation time respectively.
994
d54256af 995It uses these values to set the extended timestamp field (ID is "UT") in
996the local zip header using the three values, $atime, $mtime, $ctime. In
997addition it sets the extended timestamp field in the central zip header
998using C<$mtime>.
c70c1701 999
4e7676c7 1000If any of the three values is C<undef> that time value will not be used.
1001So, for example, to set only the C<$mtime> you would use this
1002
1003 exTime => [undef, $mtime, undef]
1004
c70c1701 1005If the C<Minimal> option is set to true, this option will be ignored.
1006
1007By default no extended time field is created.
1008
d54256af 1009=item C<< exUnix2 => [$uid, $gid] >>
1010
1011This option expects an array reference with exactly two elements: C<$uid>
1012and C<$gid>. These values correspond to the numeric user ID and group ID
1013of the owner of the files respectively.
1014
1015When the C<exUnix2> option is present it will trigger the creation of a
1016Unix2 extra field (ID is "Ux") in the local zip. This will be populated
1017with C<$uid> and C<$gid>. In addition an empty Unix2 extra field will also
1018be created in the central zip header
1019
1020If the C<Minimal> option is set to true, this option will be ignored.
1021
1022By default no Unix2 extra field is created.
1023
e7d45986 1024=item C<< Comment => $comment >>
c70c1701 1025
1026Stores the contents of C<$comment> in the Central File Header of
1027the zip file.
1028
1029By default, no comment field is written to the zip file.
1030
e7d45986 1031=item C<< ZipComment => $comment >>
c70c1701 1032
1033Stores the contents of C<$comment> in the End of Central Directory record
1034of the zip file.
1035
1036By default, no comment field is written to the zip file.
1037
e7d45986 1038=item C<< Method => $method >>
2b4e0969 1039
1040Controls which compression method is used. At present three compression
1041methods are supported, namely Store (no compression at all), Deflate and
1042Bzip2.
1043
1044The symbols, ZIP_CM_STORE, ZIP_CM_DEFLATE and ZIP_CM_BZIP2 are used to
1045select the compression method.
1046
1047These constants are not imported by C<IO::Compress::Zip> by default.
1048
1049 use IO::Compress::Zip qw(:zip_method);
1050 use IO::Compress::Zip qw(:constants);
1051 use IO::Compress::Zip qw(:all);
1052
1053Note that to create Bzip2 content, the module C<IO::Compress::Bzip2> must
1054be installed. A fatal error will be thrown if you attempt to create Bzip2
1055content when C<IO::Compress::Bzip2> is not available.
1056
1057The default method is ZIP_CM_DEFLATE.
1058
e7d45986 1059=item C<< Stream => 0|1 >>
2b4e0969 1060
1061This option controls whether the zip file/buffer output is created in
1062streaming mode.
1063
c70c1701 1064Note that when outputting to a file with streaming mode disabled (C<Stream>
1065is 0), the output file must be seekable.
1066
2b4e0969 1067The default is 1.
1068
4e7676c7 1069=item C<< Zip64 => 0|1 >>
258133d1 1070
4e7676c7 1071Create a Zip64 zip file/buffer. This option should only be used if you want
1072to store files larger than 4 Gig.
1073
1074If you intend to manipulate the Zip64 zip files created with this module
1075using an external zip/unzip make sure that it supports streaming Zip64.
1076
1077In particular, if you are using Info-Zip you need to have zip version 3.x
1078or better to update a Zip64 archive and unzip version 6.x to read a zip64
1079archive. At the time of writing both are beta status.
1080
1081When the C<Zip64> option is enabled, the C<Stream> option I<must> be
1082enabled as well.
1083
1084The default is 0.
258133d1 1085
e7d45986 1086=item C<< TextFlag => 0|1 >>
c70c1701 1087
1088This parameter controls the setting of a bit in the zip central header. It
1089is used to signal that the data stored in the zip file/buffer is probably
1090text.
1091
1092The default is 0.
1093
e7d45986 1094=item C<< ExtraFieldLocal => $data >>
1095=item C<< ExtraFieldCentral => $data >>
c70c1701 1096
d54256af 1097The C<ExtraFieldLocal> option is used to store additional metadata in the
1098local header for the zip file/buffer. The C<ExtraFieldCentral> does the
1099same for the matching central header.
c70c1701 1100
1101An extra field consists of zero or more subfields. Each subfield consists
1102of a two byte header followed by the subfield data.
1103
1104The list of subfields can be supplied in any of the following formats
1105
1106 ExtraFieldLocal => [$id1, $data1,
1107 $id2, $data2,
1108 ...
1109 ]
1110
1111 ExtraFieldLocal => [ [$id1 => $data1],
1112 [$id2 => $data2],
1113 ...
1114 ]
1115
1116 ExtraFieldLocal => { $id1 => $data1,
1117 $id2 => $data2,
1118 ...
1119 }
1120
1121Where C<$id1>, C<$id2> are two byte subfield ID's.
1122
1123If you use the hash syntax, you have no control over the order in which
1124the ExtraSubFields are stored, plus you cannot have SubFields with
1125duplicate ID.
1126
1127Alternatively the list of subfields can by supplied as a scalar, thus
1128
1129 ExtraField => $rawdata
1130
d54256af 1131The Extended Time field (ID "UT"), set using the C<exTime> option, and the
1132Unix2 extra field (ID "Ux), set using the C<exUnix2> option, are examples
1133of extra fields.
c70c1701 1134
1135If the C<Minimal> option is set to true, this option will be ignored.
1136
1137The maximum size of an extra field 65535 bytes.
1138
e7d45986 1139=item C<< Minimal => 1|0 >>
c70c1701 1140
d54256af 1141If specified, this option will disable the creation of all extra fields
1142in the zip local and central headers. So the C<exTime>, C<exUnix2>,
1143C<ExtraFieldLocal> and C<ExtraFieldCentral> options will be ignored.
c70c1701 1144
1145This parameter defaults to 0.
1146
e7d45986 1147=item C<< BlockSize100K => number >>
2b4e0969 1148
1149Specify the number of 100K blocks bzip2 uses during compression.
1150
1151Valid values are from 1 to 9, where 9 is best compression.
1152
1153This option is only valid if the C<Method> is ZIP_CM_BZIP2. It is ignored
1154otherwise.
1155
1156The default is 1.
1157
e7d45986 1158=item C<< WorkFactor => number >>
2b4e0969 1159
1160Specifies how much effort bzip2 should take before resorting to a slower
1161fallback compression algorithm.
1162
1163Valid values range from 0 to 250, where 0 means use the default value 30.
1164
1165This option is only valid if the C<Method> is ZIP_CM_BZIP2. It is ignored
1166otherwise.
1167
1168The default is 0.
1169
25f0751f 1170=item -Level
1171
1172Defines the compression level used by zlib. The value should either be
1173a number between 0 and 9 (0 means no compression and 9 is maximum
1174compression), or one of the symbolic constants defined below.
1175
1176 Z_NO_COMPRESSION
1177 Z_BEST_SPEED
1178 Z_BEST_COMPRESSION
1179 Z_DEFAULT_COMPRESSION
1180
1181The default is Z_DEFAULT_COMPRESSION.
1182
1183Note, these constants are not imported by C<IO::Compress::Zip> by default.
1184
1185 use IO::Compress::Zip qw(:strategy);
1186 use IO::Compress::Zip qw(:constants);
1187 use IO::Compress::Zip qw(:all);
1188
1189=item -Strategy
1190
1191Defines the strategy used to tune the compression. Use one of the symbolic
1192constants defined below.
1193
1194 Z_FILTERED
1195 Z_HUFFMAN_ONLY
1196 Z_RLE
1197 Z_FIXED
1198 Z_DEFAULT_STRATEGY
1199
1200The default is Z_DEFAULT_STRATEGY.
1201
e7d45986 1202=item C<< Strict => 0|1 >>
25f0751f 1203
25f0751f 1204This is a placeholder option.
1205
25f0751f 1206=back
1207
1208=head2 Examples
1209
1210TODO
1211
1212=head1 Methods
1213
1214=head2 print
1215
1216Usage is
1217
1218 $z->print($data)
1219 print $z $data
1220
1221Compresses and outputs the contents of the C<$data> parameter. This
1222has the same behaviour as the C<print> built-in.
1223
1224Returns true if successful.
1225
1226=head2 printf
1227
1228Usage is
1229
1230 $z->printf($format, $data)
1231 printf $z $format, $data
1232
1233Compresses and outputs the contents of the C<$data> parameter.
1234
1235Returns true if successful.
1236
1237=head2 syswrite
1238
1239Usage is
1240
1241 $z->syswrite $data
1242 $z->syswrite $data, $length
1243 $z->syswrite $data, $length, $offset
1244
1245Compresses and outputs the contents of the C<$data> parameter.
1246
1247Returns the number of uncompressed bytes written, or C<undef> if
1248unsuccessful.
1249
1250=head2 write
1251
1252Usage is
1253
1254 $z->write $data
1255 $z->write $data, $length
1256 $z->write $data, $length, $offset
1257
1258Compresses and outputs the contents of the C<$data> parameter.
1259
1260Returns the number of uncompressed bytes written, or C<undef> if
1261unsuccessful.
1262
1263=head2 flush
1264
1265Usage is
1266
25f0751f 1267 $z->flush;
1268 $z->flush($flush_type);
1269
25f0751f 1270Flushes any pending compressed data to the output file/buffer.
1271
25f0751f 1272This method takes an optional parameter, C<$flush_type>, that controls
1273how the flushing will be carried out. By default the C<$flush_type>
1274used is C<Z_FINISH>. Other valid values for C<$flush_type> are
1275C<Z_NO_FLUSH>, C<Z_SYNC_FLUSH>, C<Z_FULL_FLUSH> and C<Z_BLOCK>. It is
1276strongly recommended that you only set the C<flush_type> parameter if
1277you fully understand the implications of what it does - overuse of C<flush>
1278can seriously degrade the level of compression achieved. See the C<zlib>
1279documentation for details.
1280
25f0751f 1281Returns true on success.
1282
25f0751f 1283=head2 tell
1284
1285Usage is
1286
1287 $z->tell()
1288 tell $z
1289
1290Returns the uncompressed file offset.
1291
1292=head2 eof
1293
1294Usage is
1295
1296 $z->eof();
1297 eof($z);
1298
25f0751f 1299Returns true if the C<close> method has been called.
1300
25f0751f 1301=head2 seek
1302
1303 $z->seek($position, $whence);
1304 seek($z, $position, $whence);
1305
25f0751f 1306Provides a sub-set of the C<seek> functionality, with the restriction
1307that it is only legal to seek forward in the output file/buffer.
1308It is a fatal error to attempt to seek backward.
1309
1310Empty parts of the file/buffer will have NULL (0x00) bytes written to them.
1311
25f0751f 1312The C<$whence> parameter takes one the usual values, namely SEEK_SET,
1313SEEK_CUR or SEEK_END.
1314
1315Returns 1 on success, 0 on failure.
1316
1317=head2 binmode
1318
1319Usage is
1320
1321 $z->binmode
1322 binmode $z ;
1323
1324This is a noop provided for completeness.
1325
1326=head2 opened
1327
1328 $z->opened()
1329
1330Returns true if the object currently refers to a opened file/buffer.
1331
1332=head2 autoflush
1333
1334 my $prev = $z->autoflush()
1335 my $prev = $z->autoflush(EXPR)
1336
1337If the C<$z> object is associated with a file or a filehandle, this method
1338returns the current autoflush setting for the underlying filehandle. If
1339C<EXPR> is present, and is non-zero, it will enable flushing after every
1340write/print operation.
1341
1342If C<$z> is associated with a buffer, this method has no effect and always
1343returns C<undef>.
1344
1345B<Note> that the special variable C<$|> B<cannot> be used to set or
1346retrieve the autoflush setting.
1347
1348=head2 input_line_number
1349
1350 $z->input_line_number()
1351 $z->input_line_number(EXPR)
1352
25f0751f 1353This method always returns C<undef> when compressing.
1354
25f0751f 1355=head2 fileno
1356
1357 $z->fileno()
1358 fileno($z)
1359
d54256af 1360If the C<$z> object is associated with a file or a filehandle, C<fileno>
1361will return the underlying file descriptor. Once the C<close> method is
1362called C<fileno> will return C<undef>.
25f0751f 1363
d54256af 1364If the C<$z> object is is associated with a buffer, this method will return
1365C<undef>.
25f0751f 1366
1367=head2 close
1368
1369 $z->close() ;
1370 close $z ;
1371
25f0751f 1372Flushes any pending compressed data and then closes the output file/buffer.
1373
25f0751f 1374For most versions of Perl this method will be automatically invoked if
1375the IO::Compress::Zip object is destroyed (either explicitly or by the
1376variable with the reference to the object going out of scope). The
1377exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1378these cases, the C<close> method will be called automatically, but
1379not until global destruction of all live objects when the program is
1380terminating.
1381
1382Therefore, if you want your scripts to be able to run on all versions
1383of Perl, you should call C<close> explicitly and not rely on automatic
1384closing.
1385
1386Returns true on success, otherwise 0.
1387
1388If the C<AutoClose> option has been enabled when the IO::Compress::Zip
1389object was created, and the object is associated with a file, the
1390underlying file will also be closed.
1391
25f0751f 1392=head2 newStream([OPTS])
1393
1394Usage is
1395
1396 $z->newStream( [OPTS] )
1397
1398Closes the current compressed data stream and starts a new one.
1399
e7d45986 1400OPTS consists of any of the the options that are available when creating
1401the C<$z> object.
25f0751f 1402
e7d45986 1403See the L</"Constructor Options"> section for more details.
25f0751f 1404
25f0751f 1405=head2 deflateParams
1406
1407Usage is
1408
1409 $z->deflateParams
1410
1411TODO
1412
25f0751f 1413=head1 Importing
1414
25f0751f 1415A number of symbolic constants are required by some methods in
1416C<IO::Compress::Zip>. None are imported by default.
1417
25f0751f 1418=over 5
1419
1420=item :all
1421
25f0751f 1422Imports C<zip>, C<$ZipError> and all symbolic
1423constants that can be used by C<IO::Compress::Zip>. Same as doing this
1424
1425 use IO::Compress::Zip qw(zip $ZipError :constants) ;
1426
1427=item :constants
1428
1429Import all symbolic constants. Same as doing this
1430
2b4e0969 1431 use IO::Compress::Zip qw(:flush :level :strategy :zip_method) ;
1432
25f0751f 1433=item :flush
1434
1435These symbolic constants are used by the C<flush> method.
1436
1437 Z_NO_FLUSH
1438 Z_PARTIAL_FLUSH
1439 Z_SYNC_FLUSH
1440 Z_FULL_FLUSH
1441 Z_FINISH
1442 Z_BLOCK
1443
1444=item :level
1445
1446These symbolic constants are used by the C<Level> option in the constructor.
1447
1448 Z_NO_COMPRESSION
1449 Z_BEST_SPEED
1450 Z_BEST_COMPRESSION
1451 Z_DEFAULT_COMPRESSION
1452
25f0751f 1453=item :strategy
1454
1455These symbolic constants are used by the C<Strategy> option in the constructor.
1456
1457 Z_FILTERED
1458 Z_HUFFMAN_ONLY
1459 Z_RLE
1460 Z_FIXED
1461 Z_DEFAULT_STRATEGY
2b4e0969 1462
2b4e0969 1463=item :zip_method
1464
1465These symbolic constants are used by the C<Method> option in the
1466constructor.
1467
1468 ZIP_CM_STORE
1469 ZIP_CM_DEFLATE
1470 ZIP_CM_BZIP2
1471
1472
25f0751f 1473
1474
1475=back
1476
25f0751f 1477=head1 EXAMPLES
1478
d54256af 1479=head2 Apache::GZip Revisited
e7d45986 1480
319fab50 1481See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited">
e7d45986 1482
d54256af 1483
e7d45986 1484
d54256af 1485=head2 Working with Net::FTP
e7d45986 1486
319fab50 1487See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
e7d45986 1488
25f0751f 1489=head1 SEE ALSO
1490
258133d1 1491L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
25f0751f 1492
1493L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1494
1495L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1496L<Archive::Tar|Archive::Tar>,
1497L<IO::Zlib|IO::Zlib>
1498
25f0751f 1499For RFC 1950, 1951 and 1952 see
1500F<http://www.faqs.org/rfcs/rfc1950.html>,
1501F<http://www.faqs.org/rfcs/rfc1951.html> and
1502F<http://www.faqs.org/rfcs/rfc1952.html>
1503
1504The I<zlib> compression library was written by Jean-loup Gailly
1505F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>.
1506
1507The primary site for the I<zlib> compression library is
1508F<http://www.zlib.org>.
1509
1510The primary site for gzip is F<http://www.gzip.org>.
1511
25f0751f 1512=head1 AUTHOR
1513
cb7abd7f 1514This module was written by Paul Marquess, F<pmqs@cpan.org>.
25f0751f 1515
25f0751f 1516=head1 MODIFICATION HISTORY
1517
1518See the Changes file.
1519
1520=head1 COPYRIGHT AND LICENSE
25f0751f 1521
319fab50 1522Copyright (c) 2005-2009 Paul Marquess. All rights reserved.
25f0751f 1523
1524This program is free software; you can redistribute it and/or
1525modify it under the same terms as Perl itself.
1526