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