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