Debian Codegraph @

upstream/opensuse-tumbleweed/man3/IO::Compress::RawDeflate.3pm

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