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