1IO::Compress::Zip(3) User Contributed Perl Documentation IO::Compress::Zip(3)
2
3
4
6 IO::Compress::Zip - Write zip files/buffers
7
9 use IO::Compress::Zip qw(zip $ZipError) ;
10
11 my $status = zip $input => $output [,OPTS]
12 or die "zip failed: $ZipError\n";
13
14 my $z = new IO::Compress::Zip $output [,OPTS]
15 or die "zip failed: $ZipError\n";
16
17 $z->print($string);
18 $z->printf($format, $string);
19 $z->write($string);
20 $z->syswrite($string [, $length, $offset]);
21 $z->flush();
22 $z->tell();
23 $z->eof();
24 $z->seek($position, $whence);
25 $z->binmode();
26 $z->fileno();
27 $z->opened();
28 $z->autoflush();
29 $z->input_line_number();
30 $z->newStream( [OPTS] );
31
32 $z->deflateParams();
33
34 $z->close() ;
35
36 $ZipError ;
37
38 # IO::File mode
39
40 print $z $string;
41 printf $z $format, $string;
42 tell $z
43 eof $z
44 seek $z, $position, $whence
45 binmode $z
46 fileno $z
47 close $z ;
48
50 This module provides a Perl interface that allows writing zip
51 compressed data to files or buffer.
52
53 The primary purpose of this module is to provide streaming write access
54 to zip files and buffers. It is not a general-purpose file archiver. If
55 that is what you want, check out "Archive::Zip" or
56 "Archive::Zip::SimpleZip".
57
58 At present three compression methods are supported by
59 IO::Compress::Zip, namely Store (no compression at all), Deflate, Bzip2
60 and LZMA.
61
62 Note that to create Bzip2 content, the module "IO::Compress::Bzip2"
63 must be installed.
64
65 Note that to create LZMA content, the module "IO::Compress::Lzma" must
66 be installed.
67
68 For reading zip files/buffers, see the companion module
69 IO::Uncompress::Unzip.
70
72 A top-level function, "zip", is provided to carry out "one-shot"
73 compression between buffers and/or files. For finer control over the
74 compression process, see the "OO Interface" section.
75
76 use IO::Compress::Zip qw(zip $ZipError) ;
77
78 zip $input_filename_or_reference => $output_filename_or_reference [,OPTS]
79 or die "zip failed: $ZipError\n";
80
81 The functional interface needs Perl5.005 or better.
82
83 zip $input_filename_or_reference => $output_filename_or_reference [, OPTS]
84 "zip" expects at least two parameters, $input_filename_or_reference and
85 $output_filename_or_reference.
86
87 The $input_filename_or_reference parameter
88
89 The parameter, $input_filename_or_reference, is used to define the
90 source of the uncompressed data.
91
92 It can take one of the following forms:
93
94 A filename
95 If the <$input_filename_or_reference> parameter is a simple
96 scalar, it is assumed to be a filename. This file will be opened
97 for reading and the input data will be read from it.
98
99 A filehandle
100 If the $input_filename_or_reference parameter is a filehandle, the
101 input data will be read from it. The string '-' can be used as an
102 alias for standard input.
103
104 A scalar reference
105 If $input_filename_or_reference is a scalar reference, the input
106 data will be read from $$input_filename_or_reference.
107
108 An array reference
109 If $input_filename_or_reference is an array reference, each
110 element in the array must be a filename.
111
112 The input data will be read from each file in turn.
113
114 The complete array will be walked to ensure that it only contains
115 valid filenames before any data is compressed.
116
117 An Input FileGlob string
118 If $input_filename_or_reference is a string that is delimited by
119 the characters "<" and ">" "zip" will assume that it is an input
120 fileglob string. The input is the list of files that match the
121 fileglob.
122
123 See File::GlobMapper for more details.
124
125 If the $input_filename_or_reference parameter is any other type,
126 "undef" will be returned.
127
128 In addition, if $input_filename_or_reference is a simple filename, the
129 default values for the "Name", "Time", "TextFlag", "ExtAttr", "exUnixN"
130 and "exTime" options will be sourced from that file.
131
132 If you do not want to use these defaults they can be overridden by
133 explicitly setting the "Name", "Time", "TextFlag", "ExtAttr", "exUnixN"
134 and "exTime" options or by setting the "Minimal" parameter.
135
136 The $output_filename_or_reference parameter
137
138 The parameter $output_filename_or_reference is used to control the
139 destination of the compressed data. This parameter can take one of
140 these forms.
141
142 A filename
143 If the $output_filename_or_reference parameter is a simple scalar,
144 it is assumed to be a filename. This file will be opened for
145 writing and the compressed data will be written to it.
146
147 A filehandle
148 If the $output_filename_or_reference parameter is a filehandle,
149 the compressed data will be written to it. The string '-' can be
150 used as an alias for standard output.
151
152 A scalar reference
153 If $output_filename_or_reference is a scalar reference, the
154 compressed data will be stored in $$output_filename_or_reference.
155
156 An Array Reference
157 If $output_filename_or_reference is an array reference, the
158 compressed data will be pushed onto the array.
159
160 An Output FileGlob
161 If $output_filename_or_reference is a string that is delimited by
162 the characters "<" and ">" "zip" will assume that it is an output
163 fileglob string. The output is the list of files that match the
164 fileglob.
165
166 When $output_filename_or_reference is an fileglob string,
167 $input_filename_or_reference must also be a fileglob string.
168 Anything else is an error.
169
170 See File::GlobMapper for more details.
171
172 If the $output_filename_or_reference parameter is any other type,
173 "undef" will be returned.
174
175 Notes
176 When $input_filename_or_reference maps to multiple files/buffers and
177 $output_filename_or_reference is a single file/buffer the input
178 files/buffers will each be stored in $output_filename_or_reference as a
179 distinct entry.
180
181 Optional Parameters
182 Unless specified below, the optional parameters for "zip", "OPTS", are
183 the same as those used with the OO interface defined in the
184 "Constructor Options" section below.
185
186 "AutoClose => 0|1"
187 This option applies to any input or output data streams to "zip"
188 that are filehandles.
189
190 If "AutoClose" is specified, and the value is true, it will result
191 in all input and/or output filehandles being closed once "zip" has
192 completed.
193
194 This parameter defaults to 0.
195
196 "BinModeIn => 0|1"
197 This option is now a no-op. All files will be read in binmode.
198
199 "Append => 0|1"
200 The behaviour of this option is dependent on the type of output
201 data stream.
202
203 · A Buffer
204
205 If "Append" is enabled, all compressed data will be append to
206 the end of the output buffer. Otherwise the output buffer
207 will be cleared before any compressed data is written to it.
208
209 · A Filename
210
211 If "Append" is enabled, the file will be opened in append
212 mode. Otherwise the contents of the file, if any, will be
213 truncated before any compressed data is written to it.
214
215 · A Filehandle
216
217 If "Append" is enabled, the filehandle will be positioned to
218 the end of the file via a call to "seek" before any
219 compressed data is written to it. Otherwise the file pointer
220 will not be moved.
221
222 When "Append" is specified, and set to true, it will append all
223 compressed data to the output data stream.
224
225 So when the output is a filehandle it will carry out a seek to the
226 eof before writing any compressed data. If the output is a
227 filename, it will be opened for appending. If the output is a
228 buffer, all compressed data will be appended to the existing
229 buffer.
230
231 Conversely when "Append" is not specified, or it is present and is
232 set to false, it will operate as follows.
233
234 When the output is a filename, it will truncate the contents of
235 the file before writing any compressed data. If the output is a
236 filehandle its position will not be changed. If the output is a
237 buffer, it will be wiped before any compressed data is output.
238
239 Defaults to 0.
240
241 Examples
242 To read the contents of the file "file1.txt" and write the compressed
243 data to the file "file1.txt.zip".
244
245 use strict ;
246 use warnings ;
247 use IO::Compress::Zip qw(zip $ZipError) ;
248
249 my $input = "file1.txt";
250 zip $input => "$input.zip"
251 or die "zip failed: $ZipError\n";
252
253 To read from an existing Perl filehandle, $input, and write the
254 compressed data to a buffer, $buffer.
255
256 use strict ;
257 use warnings ;
258 use IO::Compress::Zip qw(zip $ZipError) ;
259 use IO::File ;
260
261 my $input = new IO::File "<file1.txt"
262 or die "Cannot open 'file1.txt': $!\n" ;
263 my $buffer ;
264 zip $input => \$buffer
265 or die "zip failed: $ZipError\n";
266
267 To create a zip file, "output.zip", that contains the compressed
268 contents of the files "alpha.txt" and "beta.txt"
269
270 use strict ;
271 use warnings ;
272 use IO::Compress::Zip qw(zip $ZipError) ;
273
274 zip [ 'alpha.txt', 'beta.txt' ] => 'output.zip'
275 or die "zip failed: $ZipError\n";
276
277 Alternatively, rather than having to explicitly name each of the files
278 that you want to compress, you could use a fileglob to select all the
279 "txt" files in the current directory, as follows
280
281 use strict ;
282 use warnings ;
283 use IO::Compress::Zip qw(zip $ZipError) ;
284
285 my @files = <*.txt>;
286 zip \@files => 'output.zip'
287 or die "zip failed: $ZipError\n";
288
289 or more succinctly
290
291 zip [ <*.txt> ] => 'output.zip'
292 or die "zip failed: $ZipError\n";
293
295 Constructor
296 The format of the constructor for "IO::Compress::Zip" is shown below
297
298 my $z = new IO::Compress::Zip $output [,OPTS]
299 or die "IO::Compress::Zip failed: $ZipError\n";
300
301 It returns an "IO::Compress::Zip" object on success and undef on
302 failure. The variable $ZipError will contain an error message on
303 failure.
304
305 If you are running Perl 5.005 or better the object, $z, returned from
306 IO::Compress::Zip can be used exactly like an IO::File filehandle.
307 This means that all normal output file operations can be carried out
308 with $z. For example, to write to a compressed file/buffer you can use
309 either of these forms
310
311 $z->print("hello world\n");
312 print $z "hello world\n";
313
314 The mandatory parameter $output is used to control the destination of
315 the compressed data. This parameter can take one of these forms.
316
317 A filename
318 If the $output parameter is a simple scalar, it is assumed to be a
319 filename. This file will be opened for writing and the compressed
320 data will be written to it.
321
322 A filehandle
323 If the $output parameter is a filehandle, the compressed data will
324 be written to it. The string '-' can be used as an alias for
325 standard output.
326
327 A scalar reference
328 If $output is a scalar reference, the compressed data will be
329 stored in $$output.
330
331 If the $output parameter is any other type, "IO::Compress::Zip"::new
332 will return undef.
333
334 Constructor Options
335 "OPTS" is any combination of the following options:
336
337 "AutoClose => 0|1"
338 This option is only valid when the $output parameter is a
339 filehandle. If specified, and the value is true, it will result in
340 the $output being closed once either the "close" method is called
341 or the "IO::Compress::Zip" object is destroyed.
342
343 This parameter defaults to 0.
344
345 "Append => 0|1"
346 Opens $output in append mode.
347
348 The behaviour of this option is dependent on the type of $output.
349
350 · A Buffer
351
352 If $output is a buffer and "Append" is enabled, all
353 compressed data will be append to the end of $output.
354 Otherwise $output will be cleared before any data is written
355 to it.
356
357 · A Filename
358
359 If $output is a filename and "Append" is enabled, the file
360 will be opened in append mode. Otherwise the contents of the
361 file, if any, will be truncated before any compressed data is
362 written to it.
363
364 · A Filehandle
365
366 If $output is a filehandle, the file pointer will be
367 positioned to the end of the file via a call to "seek" before
368 any compressed data is written to it. Otherwise the file
369 pointer will not be moved.
370
371 This parameter defaults to 0.
372
373 "Name => $string"
374 Stores the contents of $string in the zip filename header field.
375
376 If "Name" is not specified and the $input parameter is a filename,
377 the value of $input will be used for the zip filename header
378 field.
379
380 If "Name" is not specified and the $input parameter is not a
381 filename, no zip filename field will be created.
382
383 Note that both the "CanonicalName" and "FilterName" options can
384 modify the value used for the zip filename header field.
385
386 Also note that you should set the "Efs" option to true if you are
387 working with UTF8 filenames.
388
389 "CanonicalName => 0|1"
390 This option controls whether the filename field in the zip header
391 is normalized into Unix format before being written to the zip
392 file.
393
394 It is recommended that you enable this option unless you really
395 need to create a non-standard Zip file.
396
397 This is what APPNOTE.TXT has to say on what should be stored in
398 the zip filename header field.
399
400 The name of the file, with optional relative path.
401 The path stored should not contain a drive or
402 device letter, or a leading slash. All slashes
403 should be forward slashes '/' as opposed to
404 backwards slashes '\' for compatibility with Amiga
405 and UNIX file systems etc.
406
407 This option defaults to false.
408
409 "FilterName => sub { ... }"
410 This option allow the filename field in the zip header to be
411 modified before it is written to the zip file.
412
413 This option takes a parameter that must be a reference to a sub.
414 On entry to the sub the $_ variable will contain the name to be
415 filtered. If no filename is available $_ will contain an empty
416 string.
417
418 The value of $_ when the sub returns will be stored in the
419 filename header field.
420
421 Note that if "CanonicalName" is enabled, a normalized filename
422 will be passed to the sub.
423
424 If you use "FilterName" to modify the filename, it is your
425 responsibility to keep the filename in Unix format.
426
427 Although this option can be used with the OO interface, it is of
428 most use with the one-shot interface. For example, the code below
429 shows how "FilterName" can be used to remove the path component
430 from a series of filenames before they are stored in $zipfile.
431
432 sub compressTxtFiles
433 {
434 my $zipfile = shift ;
435 my $dir = shift ;
436
437 zip [ <$dir/*.txt> ] => $zipfile,
438 FilterName => sub { s[^$dir/][] } ;
439 }
440
441 "Efs => 0|1"
442 This option controls setting of the "Language Encoding Flag" (EFS)
443 in the zip archive. When set, the filename and comment fields for
444 the zip archive MUST be valid UTF-8.
445
446 If the string used for the filename and/or comment is not valid
447 UTF-8 when this option is true, the script will die with a "wide
448 character" error.
449
450 Note that this option only works with Perl 5.8.4 or better.
451
452 This option defaults to false.
453
454 "Time => $number"
455 Sets the last modified time field in the zip header to $number.
456
457 This field defaults to the time the "IO::Compress::Zip" object was
458 created if this option is not specified and the $input parameter
459 is not a filename.
460
461 "ExtAttr => $attr"
462 This option controls the "external file attributes" field in the
463 central header of the zip file. This is a 4 byte field.
464
465 If you are running a Unix derivative this value defaults to
466
467 0100644 << 16
468
469 This should allow read/write access to any files that are
470 extracted from the zip file/buffer`.
471
472 For all other systems it defaults to 0.
473
474 "exTime => [$atime, $mtime, $ctime]"
475 This option expects an array reference with exactly three
476 elements: $atime, "mtime" and $ctime. These correspond to the last
477 access time, last modification time and creation time
478 respectively.
479
480 It uses these values to set the extended timestamp field (ID is
481 "UT") in the local zip header using the three values, $atime,
482 $mtime, $ctime. In addition it sets the extended timestamp field
483 in the central zip header using $mtime.
484
485 If any of the three values is "undef" that time value will not be
486 used. So, for example, to set only the $mtime you would use this
487
488 exTime => [undef, $mtime, undef]
489
490 If the "Minimal" option is set to true, this option will be
491 ignored.
492
493 By default no extended time field is created.
494
495 "exUnix2 => [$uid, $gid]"
496 This option expects an array reference with exactly two elements:
497 $uid and $gid. These values correspond to the numeric User ID
498 (UID) and Group ID (GID) of the owner of the files respectively.
499
500 When the "exUnix2" option is present it will trigger the creation
501 of a Unix2 extra field (ID is "Ux") in the local zip header. This
502 will be populated with $uid and $gid. An empty Unix2 extra field
503 will also be created in the central zip header.
504
505 Note - The UID & GID are stored as 16-bit integers in the "Ux"
506 field. Use "exUnixN" if your UID or GID are 32-bit.
507
508 If the "Minimal" option is set to true, this option will be
509 ignored.
510
511 By default no Unix2 extra field is created.
512
513 "exUnixN => [$uid, $gid]"
514 This option expects an array reference with exactly two elements:
515 $uid and $gid. These values correspond to the numeric User ID
516 (UID) and Group ID (GID) of the owner of the files respectively.
517
518 When the "exUnixN" option is present it will trigger the creation
519 of a UnixN extra field (ID is "ux") in both the local and central
520 zip headers. This will be populated with $uid and $gid. The UID
521 & GID are stored as 32-bit integers.
522
523 If the "Minimal" option is set to true, this option will be
524 ignored.
525
526 By default no UnixN extra field is created.
527
528 "Comment => $comment"
529 Stores the contents of $comment in the Central File Header of the
530 zip file.
531
532 Set the "Efs" option to true if you want to store a UTF8 comment.
533
534 By default, no comment field is written to the zip file.
535
536 "ZipComment => $comment"
537 Stores the contents of $comment in the End of Central Directory
538 record of the zip file.
539
540 By default, no comment field is written to the zip file.
541
542 "Method => $method"
543 Controls which compression method is used. At present four
544 compression methods are supported, namely Store (no compression at
545 all), Deflate, Bzip2 and Lzma.
546
547 The symbols, ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2 and
548 ZIP_CM_LZMA are used to select the compression method.
549
550 These constants are not imported by "IO::Compress::Zip" by
551 default.
552
553 use IO::Compress::Zip qw(:zip_method);
554 use IO::Compress::Zip qw(:constants);
555 use IO::Compress::Zip qw(:all);
556
557 Note that to create Bzip2 content, the module
558 "IO::Compress::Bzip2" must be installed. A fatal error will be
559 thrown if you attempt to create Bzip2 content when
560 "IO::Compress::Bzip2" is not available.
561
562 Note that to create Lzma content, the module "IO::Compress::Lzma"
563 must be installed. A fatal error will be thrown if you attempt to
564 create Lzma content when "IO::Compress::Lzma" is not available.
565
566 The default method is ZIP_CM_DEFLATE.
567
568 "Stream => 0|1"
569 This option controls whether the zip file/buffer output is created
570 in streaming mode.
571
572 Note that when outputting to a file with streaming mode disabled
573 ("Stream" is 0), the output file must be seekable.
574
575 The default is 1.
576
577 "Zip64 => 0|1"
578 Create a Zip64 zip file/buffer. This option is used if you want to
579 store files larger than 4 Gig or store more than 64K files in a
580 single zip archive.
581
582 "Zip64" will be automatically set, as needed, if working with the
583 one-shot interface when the input is either a filename or a scalar
584 reference.
585
586 If you intend to manipulate the Zip64 zip files created with this
587 module using an external zip/unzip, make sure that it supports
588 Zip64.
589
590 In particular, if you are using Info-Zip you need to have zip
591 version 3.x or better to update a Zip64 archive and unzip version
592 6.x to read a zip64 archive.
593
594 The default is 0.
595
596 "TextFlag => 0|1"
597 This parameter controls the setting of a bit in the zip central
598 header. It is used to signal that the data stored in the zip
599 file/buffer is probably text.
600
601 In one-shot mode this flag will be set to true if the Perl "-T"
602 operator thinks the file contains text.
603
604 The default is 0.
605
606 "ExtraFieldLocal => $data"
607 "ExtraFieldCentral => $data"
608 The "ExtraFieldLocal" option is used to store additional metadata
609 in the local header for the zip file/buffer. The
610 "ExtraFieldCentral" does the same for the matching central header.
611
612 An extra field consists of zero or more subfields. Each subfield
613 consists of a two byte header followed by the subfield data.
614
615 The list of subfields can be supplied in any of the following
616 formats
617
618 ExtraFieldLocal => [$id1, $data1,
619 $id2, $data2,
620 ...
621 ]
622
623 ExtraFieldLocal => [ [$id1 => $data1],
624 [$id2 => $data2],
625 ...
626 ]
627
628 ExtraFieldLocal => { $id1 => $data1,
629 $id2 => $data2,
630 ...
631 }
632
633 Where $id1, $id2 are two byte subfield ID's.
634
635 If you use the hash syntax, you have no control over the order in
636 which the ExtraSubFields are stored, plus you cannot have
637 SubFields with duplicate ID.
638
639 Alternatively the list of subfields can by supplied as a scalar,
640 thus
641
642 ExtraField => $rawdata
643
644 In this case "IO::Compress::Zip" will check that $rawdata consists
645 of zero or more conformant sub-fields.
646
647 The Extended Time field (ID "UT"), set using the "exTime" option,
648 and the Unix2 extra field (ID "Ux), set using the "exUnix2"
649 option, are examples of extra fields.
650
651 If the "Minimal" option is set to true, this option will be
652 ignored.
653
654 The maximum size of an extra field 65535 bytes.
655
656 "Minimal => 1|0"
657 If specified, this option will disable the creation of all extra
658 fields in the zip local and central headers. So the "exTime",
659 "exUnix2", "exUnixN", "ExtraFieldLocal" and "ExtraFieldCentral"
660 options will be ignored.
661
662 This parameter defaults to 0.
663
664 "BlockSize100K => number"
665 Specify the number of 100K blocks bzip2 uses during compression.
666
667 Valid values are from 1 to 9, where 9 is best compression.
668
669 This option is only valid if the "Method" is ZIP_CM_BZIP2. It is
670 ignored otherwise.
671
672 The default is 1.
673
674 "WorkFactor => number"
675 Specifies how much effort bzip2 should take before resorting to a
676 slower fallback compression algorithm.
677
678 Valid values range from 0 to 250, where 0 means use the default
679 value 30.
680
681 This option is only valid if the "Method" is ZIP_CM_BZIP2. It is
682 ignored otherwise.
683
684 The default is 0.
685
686 "Preset => number"
687 Used to choose the LZMA compression preset.
688
689 Valid values are 0-9 and "LZMA_PRESET_DEFAULT".
690
691 0 is the fastest compression with the lowest memory usage and the
692 lowest compression.
693
694 9 is the slowest compression with the highest memory usage but
695 with the best compression.
696
697 This option is only valid if the "Method" is ZIP_CM_LZMA. It is
698 ignored otherwise.
699
700 Defaults to "LZMA_PRESET_DEFAULT" (6).
701
702 "Extreme => 0|1"
703 Makes LZMA compression a lot slower, but a small compression gain.
704
705 This option is only valid if the "Method" is ZIP_CM_LZMA. It is
706 ignored otherwise.
707
708 Defaults to 0.
709
710 -Level
711 Defines the compression level used by zlib. The value should
712 either be a number between 0 and 9 (0 means no compression and 9
713 is maximum compression), or one of the symbolic constants defined
714 below.
715
716 Z_NO_COMPRESSION
717 Z_BEST_SPEED
718 Z_BEST_COMPRESSION
719 Z_DEFAULT_COMPRESSION
720
721 The default is Z_DEFAULT_COMPRESSION.
722
723 Note, these constants are not imported by "IO::Compress::Zip" by
724 default.
725
726 use IO::Compress::Zip qw(:strategy);
727 use IO::Compress::Zip qw(:constants);
728 use IO::Compress::Zip qw(:all);
729
730 -Strategy
731 Defines the strategy used to tune the compression. Use one of the
732 symbolic constants defined below.
733
734 Z_FILTERED
735 Z_HUFFMAN_ONLY
736 Z_RLE
737 Z_FIXED
738 Z_DEFAULT_STRATEGY
739
740 The default is Z_DEFAULT_STRATEGY.
741
742 "Strict => 0|1"
743 This is a placeholder option.
744
745 Examples
746 TODO
747
749 print
750 Usage is
751
752 $z->print($data)
753 print $z $data
754
755 Compresses and outputs the contents of the $data parameter. This has
756 the same behaviour as the "print" built-in.
757
758 Returns true if successful.
759
760 printf
761 Usage is
762
763 $z->printf($format, $data)
764 printf $z $format, $data
765
766 Compresses and outputs the contents of the $data parameter.
767
768 Returns true if successful.
769
770 syswrite
771 Usage is
772
773 $z->syswrite $data
774 $z->syswrite $data, $length
775 $z->syswrite $data, $length, $offset
776
777 Compresses and outputs the contents of the $data parameter.
778
779 Returns the number of uncompressed bytes written, or "undef" if
780 unsuccessful.
781
782 write
783 Usage is
784
785 $z->write $data
786 $z->write $data, $length
787 $z->write $data, $length, $offset
788
789 Compresses and outputs the contents of the $data parameter.
790
791 Returns the number of uncompressed bytes written, or "undef" if
792 unsuccessful.
793
794 flush
795 Usage is
796
797 $z->flush;
798 $z->flush($flush_type);
799
800 Flushes any pending compressed data to the output file/buffer.
801
802 This method takes an optional parameter, $flush_type, that controls how
803 the flushing will be carried out. By default the $flush_type used is
804 "Z_FINISH". Other valid values for $flush_type are "Z_NO_FLUSH",
805 "Z_SYNC_FLUSH", "Z_FULL_FLUSH" and "Z_BLOCK". It is strongly
806 recommended that you only set the "flush_type" parameter if you fully
807 understand the implications of what it does - overuse of "flush" can
808 seriously degrade the level of compression achieved. See the "zlib"
809 documentation for details.
810
811 Returns true on success.
812
813 tell
814 Usage is
815
816 $z->tell()
817 tell $z
818
819 Returns the uncompressed file offset.
820
821 eof
822 Usage is
823
824 $z->eof();
825 eof($z);
826
827 Returns true if the "close" method has been called.
828
829 seek
830 $z->seek($position, $whence);
831 seek($z, $position, $whence);
832
833 Provides a sub-set of the "seek" functionality, with the restriction
834 that it is only legal to seek forward in the output file/buffer. It is
835 a fatal error to attempt to seek backward.
836
837 Empty parts of the file/buffer will have NULL (0x00) bytes written to
838 them.
839
840 The $whence parameter takes one the usual values, namely SEEK_SET,
841 SEEK_CUR or SEEK_END.
842
843 Returns 1 on success, 0 on failure.
844
845 binmode
846 Usage is
847
848 $z->binmode
849 binmode $z ;
850
851 This is a noop provided for completeness.
852
853 opened
854 $z->opened()
855
856 Returns true if the object currently refers to a opened file/buffer.
857
858 autoflush
859 my $prev = $z->autoflush()
860 my $prev = $z->autoflush(EXPR)
861
862 If the $z object is associated with a file or a filehandle, this method
863 returns the current autoflush setting for the underlying filehandle. If
864 "EXPR" is present, and is non-zero, it will enable flushing after every
865 write/print operation.
866
867 If $z is associated with a buffer, this method has no effect and always
868 returns "undef".
869
870 Note that the special variable $| cannot be used to set or retrieve the
871 autoflush setting.
872
873 input_line_number
874 $z->input_line_number()
875 $z->input_line_number(EXPR)
876
877 This method always returns "undef" when compressing.
878
879 fileno
880 $z->fileno()
881 fileno($z)
882
883 If the $z object is associated with a file or a filehandle, "fileno"
884 will return the underlying file descriptor. Once the "close" method is
885 called "fileno" will return "undef".
886
887 If the $z object is associated with a buffer, this method will return
888 "undef".
889
890 close
891 $z->close() ;
892 close $z ;
893
894 Flushes any pending compressed data and then closes the output
895 file/buffer.
896
897 For most versions of Perl this method will be automatically invoked if
898 the IO::Compress::Zip object is destroyed (either explicitly or by the
899 variable with the reference to the object going out of scope). The
900 exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In these
901 cases, the "close" method will be called automatically, but not until
902 global destruction of all live objects when the program is terminating.
903
904 Therefore, if you want your scripts to be able to run on all versions
905 of Perl, you should call "close" explicitly and not rely on automatic
906 closing.
907
908 Returns true on success, otherwise 0.
909
910 If the "AutoClose" option has been enabled when the IO::Compress::Zip
911 object was created, and the object is associated with a file, the
912 underlying file will also be closed.
913
914 newStream([OPTS])
915 Usage is
916
917 $z->newStream( [OPTS] )
918
919 Closes the current compressed data stream and starts a new one.
920
921 OPTS consists of any of the options that are available when creating
922 the $z object.
923
924 See the "Constructor Options" section for more details.
925
926 deflateParams
927 Usage is
928
929 $z->deflateParams
930
931 TODO
932
934 A number of symbolic constants are required by some methods in
935 "IO::Compress::Zip". None are imported by default.
936
937 :all Imports "zip", $ZipError and all symbolic constants that can be
938 used by "IO::Compress::Zip". Same as doing this
939
940 use IO::Compress::Zip qw(zip $ZipError :constants) ;
941
942 :constants
943 Import all symbolic constants. Same as doing this
944
945 use IO::Compress::Zip qw(:flush :level :strategy :zip_method) ;
946
947 :flush
948 These symbolic constants are used by the "flush" method.
949
950 Z_NO_FLUSH
951 Z_PARTIAL_FLUSH
952 Z_SYNC_FLUSH
953 Z_FULL_FLUSH
954 Z_FINISH
955 Z_BLOCK
956
957 :level
958 These symbolic constants are used by the "Level" option in the
959 constructor.
960
961 Z_NO_COMPRESSION
962 Z_BEST_SPEED
963 Z_BEST_COMPRESSION
964 Z_DEFAULT_COMPRESSION
965
966 :strategy
967 These symbolic constants are used by the "Strategy" option in the
968 constructor.
969
970 Z_FILTERED
971 Z_HUFFMAN_ONLY
972 Z_RLE
973 Z_FIXED
974 Z_DEFAULT_STRATEGY
975
976 :zip_method
977 These symbolic constants are used by the "Method" option in the
978 constructor.
979
980 ZIP_CM_STORE
981 ZIP_CM_DEFLATE
982 ZIP_CM_BZIP2
983
985 Apache::GZip Revisited
986 See IO::Compress::FAQ
987
988 Working with Net::FTP
989 See IO::Compress::FAQ
990
992 Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip,
993 IO::Compress::Deflate, IO::Uncompress::Inflate,
994 IO::Compress::RawDeflate, IO::Uncompress::RawInflate,
995 IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma,
996 IO::Uncompress::UnLzma, IO::Compress::Xz, IO::Uncompress::UnXz,
997 IO::Compress::Lzip, IO::Uncompress::UnLzip, IO::Compress::Lzop,
998 IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf,
999 IO::Compress::Zstd, IO::Uncompress::UnZstd, IO::Uncompress::AnyInflate,
1000 IO::Uncompress::AnyUncompress
1001
1002 IO::Compress::FAQ
1003
1004 File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
1005
1006 For RFC 1950, 1951 and 1952 see
1007 <http://www.faqs.org/rfcs/rfc1950.html>,
1008 <http://www.faqs.org/rfcs/rfc1951.html> and
1009 <http://www.faqs.org/rfcs/rfc1952.html>
1010
1011 The zlib compression library was written by Jean-loup Gailly
1012 "gzip@prep.ai.mit.edu" and Mark Adler "madler@alumni.caltech.edu".
1013
1014 The primary site for the zlib compression library is
1015 <http://www.zlib.org>.
1016
1017 The primary site for gzip is <http://www.gzip.org>.
1018
1020 This module was written by Paul Marquess, "pmqs@cpan.org".
1021
1023 See the Changes file.
1024
1026 Copyright (c) 2005-2019 Paul Marquess. All rights reserved.
1027
1028 This program is free software; you can redistribute it and/or modify it
1029 under the same terms as Perl itself.
1030
1031
1032
1033perl v5.30.0 2019-08-12 IO::Compress::Zip(3)