Commit | Line | Data |
25f0751f |
1 | package IO::Compress::Deflate ; |
2 | |
3 | use strict ; |
4 | use warnings; |
5 | use bytes; |
6 | |
7 | require Exporter ; |
8 | |
9b5fd1d4 |
9 | use IO::Compress::RawDeflate 2.024 ; |
25f0751f |
10 | |
9b5fd1d4 |
11 | use Compress::Raw::Zlib 2.024 ; |
12 | use IO::Compress::Zlib::Constants 2.024 ; |
13 | use IO::Compress::Base::Common 2.024 qw(createSelfTiedObject); |
25f0751f |
14 | |
15 | |
16 | our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $DeflateError); |
17 | |
9b5fd1d4 |
18 | $VERSION = '2.024'; |
25f0751f |
19 | $DeflateError = ''; |
20 | |
21 | @ISA = qw(Exporter IO::Compress::RawDeflate); |
22 | @EXPORT_OK = qw( $DeflateError deflate ) ; |
23 | %EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ; |
24 | push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; |
25 | Exporter::export_ok_tags('all'); |
26 | |
27 | |
28 | sub new |
29 | { |
30 | my $class = shift ; |
31 | |
32 | my $obj = createSelfTiedObject($class, \$DeflateError); |
33 | return $obj->_create(undef, @_); |
34 | } |
35 | |
36 | sub deflate |
37 | { |
38 | my $obj = createSelfTiedObject(undef, \$DeflateError); |
39 | return $obj->_def(@_); |
40 | } |
41 | |
42 | |
43 | sub bitmask($$$$) |
44 | { |
45 | my $into = shift ; |
46 | my $value = shift ; |
47 | my $offset = shift ; |
48 | my $mask = shift ; |
49 | |
50 | return $into | (($value & $mask) << $offset ) ; |
51 | } |
52 | |
53 | sub mkDeflateHdr($$$;$) |
54 | { |
55 | my $method = shift ; |
56 | my $cinfo = shift; |
57 | my $level = shift; |
58 | my $fdict_adler = shift ; |
59 | |
60 | my $cmf = 0; |
61 | my $flg = 0; |
62 | my $fdict = 0; |
63 | $fdict = 1 if defined $fdict_adler; |
64 | |
65 | $cmf = bitmask($cmf, $method, ZLIB_CMF_CM_OFFSET, ZLIB_CMF_CM_BITS); |
66 | $cmf = bitmask($cmf, $cinfo, ZLIB_CMF_CINFO_OFFSET, ZLIB_CMF_CINFO_BITS); |
67 | |
68 | $flg = bitmask($flg, $fdict, ZLIB_FLG_FDICT_OFFSET, ZLIB_FLG_FDICT_BITS); |
69 | $flg = bitmask($flg, $level, ZLIB_FLG_LEVEL_OFFSET, ZLIB_FLG_LEVEL_BITS); |
70 | |
71 | my $fcheck = 31 - ($cmf * 256 + $flg) % 31 ; |
72 | $flg = bitmask($flg, $fcheck, ZLIB_FLG_FCHECK_OFFSET, ZLIB_FLG_FCHECK_BITS); |
73 | |
74 | my $hdr = pack("CC", $cmf, $flg) ; |
75 | $hdr .= pack("N", $fdict_adler) if $fdict ; |
76 | |
77 | return $hdr; |
78 | } |
79 | |
80 | sub mkHeader |
81 | { |
82 | my $self = shift ; |
83 | my $param = shift ; |
84 | |
85 | my $level = $param->value('Level'); |
86 | my $strategy = $param->value('Strategy'); |
87 | |
88 | my $lflag ; |
89 | $level = 6 |
90 | if $level == Z_DEFAULT_COMPRESSION ; |
91 | |
92 | if (ZLIB_VERNUM >= 0x1210) |
93 | { |
94 | if ($strategy >= Z_HUFFMAN_ONLY || $level < 2) |
95 | { $lflag = ZLIB_FLG_LEVEL_FASTEST } |
96 | elsif ($level < 6) |
97 | { $lflag = ZLIB_FLG_LEVEL_FAST } |
98 | elsif ($level == 6) |
99 | { $lflag = ZLIB_FLG_LEVEL_DEFAULT } |
100 | else |
101 | { $lflag = ZLIB_FLG_LEVEL_SLOWEST } |
102 | } |
103 | else |
104 | { |
105 | $lflag = ($level - 1) >> 1 ; |
106 | $lflag = 3 if $lflag > 3 ; |
107 | } |
108 | |
109 | #my $wbits = (MAX_WBITS - 8) << 4 ; |
110 | my $wbits = 7; |
111 | mkDeflateHdr(ZLIB_CMF_CM_DEFLATED, $wbits, $lflag); |
112 | } |
113 | |
114 | sub ckParams |
115 | { |
116 | my $self = shift ; |
117 | my $got = shift; |
118 | |
119 | $got->value('ADLER32' => 1); |
120 | return 1 ; |
121 | } |
122 | |
123 | |
124 | sub mkTrailer |
125 | { |
126 | my $self = shift ; |
127 | return pack("N", *$self->{Compress}->adler32()) ; |
128 | } |
129 | |
130 | sub mkFinalTrailer |
131 | { |
132 | return ''; |
133 | } |
134 | |
135 | #sub newHeader |
136 | #{ |
137 | # my $self = shift ; |
138 | # return *$self->{Header}; |
139 | #} |
140 | |
141 | sub getExtraParams |
142 | { |
143 | my $self = shift ; |
144 | return $self->getZlibParams(), |
145 | } |
146 | |
147 | sub getInverseClass |
148 | { |
149 | return ('IO::Uncompress::Inflate', |
150 | \$IO::Uncompress::Inflate::InflateError); |
151 | } |
152 | |
153 | sub getFileInfo |
154 | { |
155 | my $self = shift ; |
156 | my $params = shift; |
157 | my $file = shift ; |
158 | |
159 | } |
160 | |
161 | |
162 | |
163 | 1; |
164 | |
165 | __END__ |
166 | |
167 | =head1 NAME |
168 | |
cb7abd7f |
169 | IO::Compress::Deflate - Write RFC 1950 files/buffers |
170 | |
25f0751f |
171 | |
172 | |
173 | =head1 SYNOPSIS |
174 | |
175 | use IO::Compress::Deflate qw(deflate $DeflateError) ; |
176 | |
25f0751f |
177 | my $status = deflate $input => $output [,OPTS] |
178 | or die "deflate failed: $DeflateError\n"; |
179 | |
180 | my $z = new IO::Compress::Deflate $output [,OPTS] |
181 | or die "deflate failed: $DeflateError\n"; |
182 | |
183 | $z->print($string); |
184 | $z->printf($format, $string); |
185 | $z->write($string); |
186 | $z->syswrite($string [, $length, $offset]); |
187 | $z->flush(); |
188 | $z->tell(); |
189 | $z->eof(); |
190 | $z->seek($position, $whence); |
191 | $z->binmode(); |
192 | $z->fileno(); |
193 | $z->opened(); |
194 | $z->autoflush(); |
195 | $z->input_line_number(); |
196 | $z->newStream( [OPTS] ); |
197 | |
198 | $z->deflateParams(); |
199 | |
200 | $z->close() ; |
201 | |
202 | $DeflateError ; |
203 | |
204 | # IO::File mode |
205 | |
206 | print $z $string; |
207 | printf $z $format, $string; |
208 | tell $z |
209 | eof $z |
210 | seek $z, $position, $whence |
211 | binmode $z |
212 | fileno $z |
213 | close $z ; |
214 | |
215 | |
216 | =head1 DESCRIPTION |
217 | |
25f0751f |
218 | This module provides a Perl interface that allows writing compressed |
219 | data to files or buffer as defined in RFC 1950. |
220 | |
25f0751f |
221 | For reading RFC 1950 files/buffers, see the companion module |
222 | L<IO::Uncompress::Inflate|IO::Uncompress::Inflate>. |
223 | |
25f0751f |
224 | =head1 Functional Interface |
225 | |
226 | A top-level function, C<deflate>, is provided to carry out |
227 | "one-shot" compression between buffers and/or files. For finer |
228 | control over the compression process, see the L</"OO Interface"> |
229 | section. |
230 | |
231 | use IO::Compress::Deflate qw(deflate $DeflateError) ; |
232 | |
233 | deflate $input => $output [,OPTS] |
234 | or die "deflate failed: $DeflateError\n"; |
235 | |
25f0751f |
236 | The functional interface needs Perl5.005 or better. |
237 | |
25f0751f |
238 | =head2 deflate $input => $output [, OPTS] |
239 | |
25f0751f |
240 | C<deflate> expects at least two parameters, C<$input> and C<$output>. |
241 | |
242 | =head3 The C<$input> parameter |
243 | |
244 | The parameter, C<$input>, is used to define the source of |
245 | the uncompressed data. |
246 | |
247 | It can take one of the following forms: |
248 | |
249 | =over 5 |
250 | |
251 | =item A filename |
252 | |
253 | If the C<$input> parameter is a simple scalar, it is assumed to be a |
254 | filename. This file will be opened for reading and the input data |
255 | will be read from it. |
256 | |
257 | =item A filehandle |
258 | |
259 | If the C<$input> parameter is a filehandle, the input data will be |
260 | read from it. |
261 | The string '-' can be used as an alias for standard input. |
262 | |
263 | =item A scalar reference |
264 | |
265 | If C<$input> is a scalar reference, the input data will be read |
266 | from C<$$input>. |
267 | |
268 | =item An array reference |
269 | |
270 | If C<$input> is an array reference, each element in the array must be a |
271 | filename. |
272 | |
273 | The input data will be read from each file in turn. |
274 | |
275 | The complete array will be walked to ensure that it only |
276 | contains valid filenames before any data is compressed. |
277 | |
25f0751f |
278 | =item An Input FileGlob string |
279 | |
280 | If C<$input> is a string that is delimited by the characters "<" and ">" |
281 | C<deflate> will assume that it is an I<input fileglob string>. The |
282 | input is the list of files that match the fileglob. |
283 | |
284 | If the fileglob does not match any files ... |
285 | |
286 | See L<File::GlobMapper|File::GlobMapper> for more details. |
287 | |
25f0751f |
288 | =back |
289 | |
290 | If the C<$input> parameter is any other type, C<undef> will be returned. |
291 | |
25f0751f |
292 | =head3 The C<$output> parameter |
293 | |
294 | The parameter C<$output> is used to control the destination of the |
295 | compressed data. This parameter can take one of these forms. |
296 | |
297 | =over 5 |
298 | |
299 | =item A filename |
300 | |
301 | If the C<$output> parameter is a simple scalar, it is assumed to be a |
302 | filename. This file will be opened for writing and the compressed |
303 | data will be written to it. |
304 | |
305 | =item A filehandle |
306 | |
307 | If the C<$output> parameter is a filehandle, the compressed data |
308 | will be written to it. |
309 | The string '-' can be used as an alias for standard output. |
310 | |
25f0751f |
311 | =item A scalar reference |
312 | |
313 | If C<$output> is a scalar reference, the compressed data will be |
314 | stored in C<$$output>. |
315 | |
25f0751f |
316 | =item An Array Reference |
317 | |
318 | If C<$output> is an array reference, the compressed data will be |
319 | pushed onto the array. |
320 | |
321 | =item An Output FileGlob |
322 | |
323 | If C<$output> is a string that is delimited by the characters "<" and ">" |
324 | C<deflate> will assume that it is an I<output fileglob string>. The |
325 | output is the list of files that match the fileglob. |
326 | |
327 | When C<$output> is an fileglob string, C<$input> must also be a fileglob |
328 | string. Anything else is an error. |
329 | |
330 | =back |
331 | |
332 | If the C<$output> parameter is any other type, C<undef> will be returned. |
333 | |
25f0751f |
334 | =head2 Notes |
335 | |
336 | When C<$input> maps to multiple files/buffers and C<$output> is a single |
c70c1701 |
337 | file/buffer the input files/buffers will be stored |
338 | in C<$output> as a concatenated series of compressed data streams. |
339 | |
25f0751f |
340 | =head2 Optional Parameters |
341 | |
342 | Unless specified below, the optional parameters for C<deflate>, |
343 | C<OPTS>, are the same as those used with the OO interface defined in the |
344 | L</"Constructor Options"> section below. |
345 | |
346 | =over 5 |
347 | |
e7d45986 |
348 | =item C<< AutoClose => 0|1 >> |
25f0751f |
349 | |
350 | This option applies to any input or output data streams to |
351 | C<deflate> that are filehandles. |
352 | |
353 | If C<AutoClose> is specified, and the value is true, it will result in all |
354 | input and/or output filehandles being closed once C<deflate> has |
355 | completed. |
356 | |
357 | This parameter defaults to 0. |
358 | |
e7d45986 |
359 | =item C<< BinModeIn => 0|1 >> |
25f0751f |
360 | |
361 | When reading from a file or filehandle, set C<binmode> before reading. |
362 | |
363 | Defaults to 0. |
364 | |
e7d45986 |
365 | =item C<< Append => 0|1 >> |
25f0751f |
366 | |
9b5fd1d4 |
367 | The behaviour of this option is dependent on the type of output data |
368 | stream. |
369 | |
370 | =over 5 |
371 | |
372 | =item * A Buffer |
373 | |
374 | If C<Append> is enabled, all compressed data will be append to the end of |
375 | the output buffer. Otherwise the output buffer will be cleared before any |
376 | compressed data is written to it. |
377 | |
378 | =item * A Filename |
379 | |
380 | If C<Append> is enabled, the file will be opened in append mode. Otherwise |
381 | the contents of the file, if any, will be truncated before any compressed |
382 | data is written to it. |
383 | |
384 | =item * A Filehandle |
385 | |
386 | If C<Append> is enabled, the filehandle will be positioned to the end of |
387 | the file via a call to C<seek> before any compressed data is |
388 | written to it. Otherwise the file pointer will not be moved. |
389 | |
390 | =back |
391 | |
392 | When C<Append> is specified, and set to true, it will I<append> all compressed |
393 | data to the output data stream. |
394 | |
395 | So when the output is a filehandle it will carry out a seek to the eof |
396 | before writing any compressed data. If the output is a filename, it will be opened for |
397 | appending. If the output is a buffer, all compressed data will be appened to |
398 | the existing buffer. |
399 | |
400 | Conversely when C<Append> is not specified, or it is present and is set to |
401 | false, it will operate as follows. |
402 | |
403 | When the output is a filename, it will truncate the contents of the file |
404 | before writing any compressed data. If the output is a filehandle |
405 | its position will not be changed. If the output is a buffer, it will be |
406 | wiped before any compressed data is output. |
407 | |
408 | Defaults to 0. |
25f0751f |
409 | |
25f0751f |
410 | =back |
411 | |
25f0751f |
412 | =head2 Examples |
413 | |
414 | To read the contents of the file C<file1.txt> and write the compressed |
415 | data to the file C<file1.txt.1950>. |
416 | |
417 | use strict ; |
418 | use warnings ; |
419 | use IO::Compress::Deflate qw(deflate $DeflateError) ; |
420 | |
421 | my $input = "file1.txt"; |
422 | deflate $input => "$input.1950" |
423 | or die "deflate failed: $DeflateError\n"; |
424 | |
25f0751f |
425 | To read from an existing Perl filehandle, C<$input>, and write the |
426 | compressed data to a buffer, C<$buffer>. |
427 | |
428 | use strict ; |
429 | use warnings ; |
430 | use IO::Compress::Deflate qw(deflate $DeflateError) ; |
431 | use IO::File ; |
432 | |
433 | my $input = new IO::File "<file1.txt" |
434 | or die "Cannot open 'file1.txt': $!\n" ; |
435 | my $buffer ; |
436 | deflate $input => \$buffer |
437 | or die "deflate failed: $DeflateError\n"; |
438 | |
439 | To compress all files in the directory "/my/home" that match "*.txt" |
440 | and store the compressed data in the same directory |
441 | |
442 | use strict ; |
443 | use warnings ; |
444 | use IO::Compress::Deflate qw(deflate $DeflateError) ; |
445 | |
446 | deflate '</my/home/*.txt>' => '<*.1950>' |
447 | or die "deflate failed: $DeflateError\n"; |
448 | |
449 | and if you want to compress each file one at a time, this will do the trick |
450 | |
451 | use strict ; |
452 | use warnings ; |
453 | use IO::Compress::Deflate qw(deflate $DeflateError) ; |
454 | |
455 | for my $input ( glob "/my/home/*.txt" ) |
456 | { |
457 | my $output = "$input.1950" ; |
458 | deflate $input => $output |
459 | or die "Error compressing '$input': $DeflateError\n"; |
460 | } |
461 | |
25f0751f |
462 | =head1 OO Interface |
463 | |
464 | =head2 Constructor |
465 | |
466 | The format of the constructor for C<IO::Compress::Deflate> is shown below |
467 | |
468 | my $z = new IO::Compress::Deflate $output [,OPTS] |
469 | or die "IO::Compress::Deflate failed: $DeflateError\n"; |
470 | |
471 | It returns an C<IO::Compress::Deflate> object on success and undef on failure. |
472 | The variable C<$DeflateError> will contain an error message on failure. |
473 | |
474 | If you are running Perl 5.005 or better the object, C<$z>, returned from |
475 | IO::Compress::Deflate can be used exactly like an L<IO::File|IO::File> filehandle. |
476 | This means that all normal output file operations can be carried out |
477 | with C<$z>. |
478 | For example, to write to a compressed file/buffer you can use either of |
479 | these forms |
480 | |
481 | $z->print("hello world\n"); |
482 | print $z "hello world\n"; |
483 | |
484 | The mandatory parameter C<$output> is used to control the destination |
485 | of the compressed data. This parameter can take one of these forms. |
486 | |
487 | =over 5 |
488 | |
489 | =item A filename |
490 | |
491 | If the C<$output> parameter is a simple scalar, it is assumed to be a |
492 | filename. This file will be opened for writing and the compressed data |
493 | will be written to it. |
494 | |
495 | =item A filehandle |
496 | |
497 | If the C<$output> parameter is a filehandle, the compressed data will be |
498 | written to it. |
499 | The string '-' can be used as an alias for standard output. |
500 | |
25f0751f |
501 | =item A scalar reference |
502 | |
503 | If C<$output> is a scalar reference, the compressed data will be stored |
504 | in C<$$output>. |
505 | |
506 | =back |
507 | |
508 | If the C<$output> parameter is any other type, C<IO::Compress::Deflate>::new will |
509 | return undef. |
510 | |
511 | =head2 Constructor Options |
512 | |
513 | C<OPTS> is any combination of the following options: |
514 | |
515 | =over 5 |
516 | |
e7d45986 |
517 | =item C<< AutoClose => 0|1 >> |
25f0751f |
518 | |
519 | This option is only valid when the C<$output> parameter is a filehandle. If |
520 | specified, and the value is true, it will result in the C<$output> being |
521 | closed once either the C<close> method is called or the C<IO::Compress::Deflate> |
522 | object is destroyed. |
523 | |
524 | This parameter defaults to 0. |
525 | |
e7d45986 |
526 | =item C<< Append => 0|1 >> |
25f0751f |
527 | |
528 | Opens C<$output> in append mode. |
529 | |
530 | The behaviour of this option is dependent on the type of C<$output>. |
531 | |
532 | =over 5 |
533 | |
534 | =item * A Buffer |
535 | |
536 | If C<$output> is a buffer and C<Append> is enabled, all compressed data |
9b5fd1d4 |
537 | will be append to the end of C<$output>. Otherwise C<$output> will be |
25f0751f |
538 | cleared before any data is written to it. |
539 | |
540 | =item * A Filename |
541 | |
542 | If C<$output> is a filename and C<Append> is enabled, the file will be |
543 | opened in append mode. Otherwise the contents of the file, if any, will be |
544 | truncated before any compressed data is written to it. |
545 | |
546 | =item * A Filehandle |
547 | |
548 | If C<$output> is a filehandle, the file pointer will be positioned to the |
549 | end of the file via a call to C<seek> before any compressed data is written |
550 | to it. Otherwise the file pointer will not be moved. |
551 | |
552 | =back |
553 | |
554 | This parameter defaults to 0. |
555 | |
e7d45986 |
556 | =item C<< Merge => 0|1 >> |
25f0751f |
557 | |
558 | This option is used to compress input data and append it to an existing |
559 | compressed data stream in C<$output>. The end result is a single compressed |
560 | data stream stored in C<$output>. |
561 | |
25f0751f |
562 | It is a fatal error to attempt to use this option when C<$output> is not an |
563 | RFC 1950 data stream. |
564 | |
25f0751f |
565 | There are a number of other limitations with the C<Merge> option: |
566 | |
567 | =over 5 |
568 | |
569 | =item 1 |
570 | |
571 | This module needs to have been built with zlib 1.2.1 or better to work. A |
572 | fatal error will be thrown if C<Merge> is used with an older version of |
573 | zlib. |
574 | |
575 | =item 2 |
576 | |
577 | If C<$output> is a file or a filehandle, it must be seekable. |
578 | |
579 | =back |
580 | |
25f0751f |
581 | This parameter defaults to 0. |
582 | |
25f0751f |
583 | =item -Level |
584 | |
585 | Defines the compression level used by zlib. The value should either be |
586 | a number between 0 and 9 (0 means no compression and 9 is maximum |
587 | compression), or one of the symbolic constants defined below. |
588 | |
589 | Z_NO_COMPRESSION |
590 | Z_BEST_SPEED |
591 | Z_BEST_COMPRESSION |
592 | Z_DEFAULT_COMPRESSION |
593 | |
594 | The default is Z_DEFAULT_COMPRESSION. |
595 | |
596 | Note, these constants are not imported by C<IO::Compress::Deflate> by default. |
597 | |
598 | use IO::Compress::Deflate qw(:strategy); |
599 | use IO::Compress::Deflate qw(:constants); |
600 | use IO::Compress::Deflate qw(:all); |
601 | |
602 | =item -Strategy |
603 | |
604 | Defines the strategy used to tune the compression. Use one of the symbolic |
605 | constants defined below. |
606 | |
607 | Z_FILTERED |
608 | Z_HUFFMAN_ONLY |
609 | Z_RLE |
610 | Z_FIXED |
611 | Z_DEFAULT_STRATEGY |
612 | |
613 | The default is Z_DEFAULT_STRATEGY. |
614 | |
e7d45986 |
615 | =item C<< Strict => 0|1 >> |
25f0751f |
616 | |
25f0751f |
617 | This is a placeholder option. |
618 | |
25f0751f |
619 | =back |
620 | |
621 | =head2 Examples |
622 | |
623 | TODO |
624 | |
625 | =head1 Methods |
626 | |
627 | =head2 print |
628 | |
629 | Usage is |
630 | |
631 | $z->print($data) |
632 | print $z $data |
633 | |
634 | Compresses and outputs the contents of the C<$data> parameter. This |
635 | has the same behaviour as the C<print> built-in. |
636 | |
637 | Returns true if successful. |
638 | |
639 | =head2 printf |
640 | |
641 | Usage is |
642 | |
643 | $z->printf($format, $data) |
644 | printf $z $format, $data |
645 | |
646 | Compresses and outputs the contents of the C<$data> parameter. |
647 | |
648 | Returns true if successful. |
649 | |
650 | =head2 syswrite |
651 | |
652 | Usage is |
653 | |
654 | $z->syswrite $data |
655 | $z->syswrite $data, $length |
656 | $z->syswrite $data, $length, $offset |
657 | |
658 | Compresses and outputs the contents of the C<$data> parameter. |
659 | |
660 | Returns the number of uncompressed bytes written, or C<undef> if |
661 | unsuccessful. |
662 | |
663 | =head2 write |
664 | |
665 | Usage is |
666 | |
667 | $z->write $data |
668 | $z->write $data, $length |
669 | $z->write $data, $length, $offset |
670 | |
671 | Compresses and outputs the contents of the C<$data> parameter. |
672 | |
673 | Returns the number of uncompressed bytes written, or C<undef> if |
674 | unsuccessful. |
675 | |
676 | =head2 flush |
677 | |
678 | Usage is |
679 | |
25f0751f |
680 | $z->flush; |
681 | $z->flush($flush_type); |
682 | |
25f0751f |
683 | Flushes any pending compressed data to the output file/buffer. |
684 | |
25f0751f |
685 | This method takes an optional parameter, C<$flush_type>, that controls |
686 | how the flushing will be carried out. By default the C<$flush_type> |
687 | used is C<Z_FINISH>. Other valid values for C<$flush_type> are |
688 | C<Z_NO_FLUSH>, C<Z_SYNC_FLUSH>, C<Z_FULL_FLUSH> and C<Z_BLOCK>. It is |
689 | strongly recommended that you only set the C<flush_type> parameter if |
690 | you fully understand the implications of what it does - overuse of C<flush> |
691 | can seriously degrade the level of compression achieved. See the C<zlib> |
692 | documentation for details. |
693 | |
25f0751f |
694 | Returns true on success. |
695 | |
25f0751f |
696 | =head2 tell |
697 | |
698 | Usage is |
699 | |
700 | $z->tell() |
701 | tell $z |
702 | |
703 | Returns the uncompressed file offset. |
704 | |
705 | =head2 eof |
706 | |
707 | Usage is |
708 | |
709 | $z->eof(); |
710 | eof($z); |
711 | |
25f0751f |
712 | Returns true if the C<close> method has been called. |
713 | |
25f0751f |
714 | =head2 seek |
715 | |
716 | $z->seek($position, $whence); |
717 | seek($z, $position, $whence); |
718 | |
25f0751f |
719 | Provides a sub-set of the C<seek> functionality, with the restriction |
720 | that it is only legal to seek forward in the output file/buffer. |
721 | It is a fatal error to attempt to seek backward. |
722 | |
723 | Empty parts of the file/buffer will have NULL (0x00) bytes written to them. |
724 | |
25f0751f |
725 | The C<$whence> parameter takes one the usual values, namely SEEK_SET, |
726 | SEEK_CUR or SEEK_END. |
727 | |
728 | Returns 1 on success, 0 on failure. |
729 | |
730 | =head2 binmode |
731 | |
732 | Usage is |
733 | |
734 | $z->binmode |
735 | binmode $z ; |
736 | |
737 | This is a noop provided for completeness. |
738 | |
739 | =head2 opened |
740 | |
741 | $z->opened() |
742 | |
743 | Returns true if the object currently refers to a opened file/buffer. |
744 | |
745 | =head2 autoflush |
746 | |
747 | my $prev = $z->autoflush() |
748 | my $prev = $z->autoflush(EXPR) |
749 | |
750 | If the C<$z> object is associated with a file or a filehandle, this method |
751 | returns the current autoflush setting for the underlying filehandle. If |
752 | C<EXPR> is present, and is non-zero, it will enable flushing after every |
753 | write/print operation. |
754 | |
755 | If C<$z> is associated with a buffer, this method has no effect and always |
756 | returns C<undef>. |
757 | |
758 | B<Note> that the special variable C<$|> B<cannot> be used to set or |
759 | retrieve the autoflush setting. |
760 | |
761 | =head2 input_line_number |
762 | |
763 | $z->input_line_number() |
764 | $z->input_line_number(EXPR) |
765 | |
25f0751f |
766 | This method always returns C<undef> when compressing. |
767 | |
25f0751f |
768 | =head2 fileno |
769 | |
770 | $z->fileno() |
771 | fileno($z) |
772 | |
d54256af |
773 | If the C<$z> object is associated with a file or a filehandle, C<fileno> |
774 | will return the underlying file descriptor. Once the C<close> method is |
775 | called C<fileno> will return C<undef>. |
25f0751f |
776 | |
d54256af |
777 | If the C<$z> object is is associated with a buffer, this method will return |
778 | C<undef>. |
25f0751f |
779 | |
780 | =head2 close |
781 | |
782 | $z->close() ; |
783 | close $z ; |
784 | |
25f0751f |
785 | Flushes any pending compressed data and then closes the output file/buffer. |
786 | |
25f0751f |
787 | For most versions of Perl this method will be automatically invoked if |
788 | the IO::Compress::Deflate object is destroyed (either explicitly or by the |
789 | variable with the reference to the object going out of scope). The |
790 | exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In |
791 | these cases, the C<close> method will be called automatically, but |
792 | not until global destruction of all live objects when the program is |
793 | terminating. |
794 | |
795 | Therefore, if you want your scripts to be able to run on all versions |
796 | of Perl, you should call C<close> explicitly and not rely on automatic |
797 | closing. |
798 | |
799 | Returns true on success, otherwise 0. |
800 | |
801 | If the C<AutoClose> option has been enabled when the IO::Compress::Deflate |
802 | object was created, and the object is associated with a file, the |
803 | underlying file will also be closed. |
804 | |
25f0751f |
805 | =head2 newStream([OPTS]) |
806 | |
807 | Usage is |
808 | |
809 | $z->newStream( [OPTS] ) |
810 | |
811 | Closes the current compressed data stream and starts a new one. |
812 | |
e7d45986 |
813 | OPTS consists of any of the the options that are available when creating |
814 | the C<$z> object. |
25f0751f |
815 | |
e7d45986 |
816 | See the L</"Constructor Options"> section for more details. |
25f0751f |
817 | |
25f0751f |
818 | =head2 deflateParams |
819 | |
820 | Usage is |
821 | |
822 | $z->deflateParams |
823 | |
824 | TODO |
825 | |
25f0751f |
826 | =head1 Importing |
827 | |
25f0751f |
828 | A number of symbolic constants are required by some methods in |
829 | C<IO::Compress::Deflate>. None are imported by default. |
830 | |
25f0751f |
831 | =over 5 |
832 | |
833 | =item :all |
834 | |
25f0751f |
835 | Imports C<deflate>, C<$DeflateError> and all symbolic |
836 | constants that can be used by C<IO::Compress::Deflate>. Same as doing this |
837 | |
838 | use IO::Compress::Deflate qw(deflate $DeflateError :constants) ; |
839 | |
840 | =item :constants |
841 | |
842 | Import all symbolic constants. Same as doing this |
843 | |
844 | use IO::Compress::Deflate qw(:flush :level :strategy) ; |
845 | |
846 | =item :flush |
847 | |
848 | These symbolic constants are used by the C<flush> method. |
849 | |
850 | Z_NO_FLUSH |
851 | Z_PARTIAL_FLUSH |
852 | Z_SYNC_FLUSH |
853 | Z_FULL_FLUSH |
854 | Z_FINISH |
855 | Z_BLOCK |
856 | |
857 | =item :level |
858 | |
859 | These symbolic constants are used by the C<Level> option in the constructor. |
860 | |
861 | Z_NO_COMPRESSION |
862 | Z_BEST_SPEED |
863 | Z_BEST_COMPRESSION |
864 | Z_DEFAULT_COMPRESSION |
865 | |
25f0751f |
866 | =item :strategy |
867 | |
868 | These symbolic constants are used by the C<Strategy> option in the constructor. |
869 | |
870 | Z_FILTERED |
871 | Z_HUFFMAN_ONLY |
872 | Z_RLE |
873 | Z_FIXED |
874 | Z_DEFAULT_STRATEGY |
2b4e0969 |
875 | |
876 | |
25f0751f |
877 | |
878 | |
879 | =back |
880 | |
25f0751f |
881 | =head1 EXAMPLES |
882 | |
d54256af |
883 | =head2 Apache::GZip Revisited |
e7d45986 |
884 | |
319fab50 |
885 | See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited"> |
e7d45986 |
886 | |
d54256af |
887 | |
e7d45986 |
888 | |
d54256af |
889 | =head2 Working with Net::FTP |
e7d45986 |
890 | |
319fab50 |
891 | See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP"> |
e7d45986 |
892 | |
25f0751f |
893 | =head1 SEE ALSO |
894 | |
9b5fd1d4 |
895 | L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, 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 |
896 | |
897 | L<Compress::Zlib::FAQ|Compress::Zlib::FAQ> |
898 | |
899 | L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>, |
900 | L<Archive::Tar|Archive::Tar>, |
901 | L<IO::Zlib|IO::Zlib> |
902 | |
25f0751f |
903 | For RFC 1950, 1951 and 1952 see |
904 | F<http://www.faqs.org/rfcs/rfc1950.html>, |
905 | F<http://www.faqs.org/rfcs/rfc1951.html> and |
906 | F<http://www.faqs.org/rfcs/rfc1952.html> |
907 | |
908 | The I<zlib> compression library was written by Jean-loup Gailly |
909 | F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>. |
910 | |
911 | The primary site for the I<zlib> compression library is |
912 | F<http://www.zlib.org>. |
913 | |
914 | The primary site for gzip is F<http://www.gzip.org>. |
915 | |
25f0751f |
916 | =head1 AUTHOR |
917 | |
cb7abd7f |
918 | This module was written by Paul Marquess, F<pmqs@cpan.org>. |
25f0751f |
919 | |
25f0751f |
920 | =head1 MODIFICATION HISTORY |
921 | |
922 | See the Changes file. |
923 | |
924 | =head1 COPYRIGHT AND LICENSE |
25f0751f |
925 | |
9b5fd1d4 |
926 | Copyright (c) 2005-2010 Paul Marquess. All rights reserved. |
25f0751f |
927 | |
928 | This program is free software; you can redistribute it and/or |
929 | modify it under the same terms as Perl itself. |
930 | |