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