File Coverage

blib/lib/IO/Compress/Deflate.pm
Criterion Covered Total %
statement 45 45 100.0
branch 1 2 50.0
condition n/a
subroutine 17 17 100.0
pod 2 9 22.2
total 65 73 89.0


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