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