1package IO::Compress::RawDeflate ; 2 3# create RFC1951 4# 5use strict ; 6use warnings; 7use bytes; 8 9use IO::Compress::Base 2.084 ; 10use IO::Compress::Base::Common 2.084 qw(:Status ); 11use IO::Compress::Adapter::Deflate 2.084 ; 12 13require Exporter ; 14 15our ($VERSION, @ISA, @EXPORT_OK, %DEFLATE_CONSTANTS, %EXPORT_TAGS, $RawDeflateError); 16 17$VERSION = '2.084'; 18$RawDeflateError = ''; 19 20@ISA = qw(IO::Compress::Base Exporter); 21@EXPORT_OK = qw( $RawDeflateError rawdeflate ) ; 22push @EXPORT_OK, @IO::Compress::Adapter::Deflate::EXPORT_OK ; 23 24%EXPORT_TAGS = %IO::Compress::Adapter::Deflate::DEFLATE_CONSTANTS; 25 26 27{ 28 my %seen; 29 foreach (keys %EXPORT_TAGS ) 30 { 31 push @{$EXPORT_TAGS{constants}}, 32 grep { !$seen{$_}++ } 33 @{ $EXPORT_TAGS{$_} } 34 } 35 $EXPORT_TAGS{all} = $EXPORT_TAGS{constants} ; 36} 37 38 39%DEFLATE_CONSTANTS = %EXPORT_TAGS; 40 41#push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; 42 43Exporter::export_ok_tags('all'); 44 45 46 47sub new 48{ 49 my $class = shift ; 50 51 my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$RawDeflateError); 52 53 return $obj->_create(undef, @_); 54} 55 56sub rawdeflate 57{ 58 my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$RawDeflateError); 59 return $obj->_def(@_); 60} 61 62sub ckParams 63{ 64 my $self = shift ; 65 my $got = shift; 66 67 return 1 ; 68} 69 70sub mkComp 71{ 72 my $self = shift ; 73 my $got = shift ; 74 75 my ($obj, $errstr, $errno) = IO::Compress::Adapter::Deflate::mkCompObject( 76 $got->getValue('crc32'), 77 $got->getValue('adler32'), 78 $got->getValue('level'), 79 $got->getValue('strategy') 80 ); 81 82 return $self->saveErrorString(undef, $errstr, $errno) 83 if ! defined $obj; 84 85 return $obj; 86} 87 88 89sub mkHeader 90{ 91 my $self = shift ; 92 return ''; 93} 94 95sub mkTrailer 96{ 97 my $self = shift ; 98 return ''; 99} 100 101sub mkFinalTrailer 102{ 103 return ''; 104} 105 106 107#sub newHeader 108#{ 109# my $self = shift ; 110# return ''; 111#} 112 113sub getExtraParams 114{ 115 my $self = shift ; 116 return getZlibParams(); 117} 118 119use IO::Compress::Base::Common 2.084 qw(:Parse); 120use Compress::Raw::Zlib 2.084 qw(Z_DEFLATED Z_DEFAULT_COMPRESSION Z_DEFAULT_STRATEGY); 121our %PARAMS = ( 122 #'method' => [IO::Compress::Base::Common::Parse_unsigned, Z_DEFLATED], 123 'level' => [IO::Compress::Base::Common::Parse_signed, Z_DEFAULT_COMPRESSION], 124 'strategy' => [IO::Compress::Base::Common::Parse_signed, Z_DEFAULT_STRATEGY], 125 126 'crc32' => [IO::Compress::Base::Common::Parse_boolean, 0], 127 'adler32' => [IO::Compress::Base::Common::Parse_boolean, 0], 128 'merge' => [IO::Compress::Base::Common::Parse_boolean, 0], 129 ); 130 131sub getZlibParams 132{ 133 return %PARAMS; 134} 135 136sub getInverseClass 137{ 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} = new U64(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 = new IO::Compress::RawDeflate $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 270=head1 DESCRIPTION 271 272This module provides a Perl interface that allows writing compressed 273data to files or buffer as defined in RFC 1951. 274 275Note that RFC 1951 data is not a good choice of compression format 276to use in isolation, especially if you want to auto-detect it. 277 278For reading RFC 1951 files/buffers, see the companion module 279L<IO::Uncompress::RawInflate|IO::Uncompress::RawInflate>. 280 281=head1 Functional Interface 282 283A top-level function, C<rawdeflate>, is provided to carry out 284"one-shot" compression between buffers and/or files. For finer 285control over the compression process, see the L</"OO Interface"> 286section. 287 288 use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; 289 290 rawdeflate $input_filename_or_reference => $output_filename_or_reference [,OPTS] 291 or die "rawdeflate failed: $RawDeflateError\n"; 292 293The functional interface needs Perl5.005 or better. 294 295=head2 rawdeflate $input_filename_or_reference => $output_filename_or_reference [, OPTS] 296 297C<rawdeflate> expects at least two parameters, 298C<$input_filename_or_reference> and C<$output_filename_or_reference>. 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 <$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 407Unless specified below, the optional parameters for C<rawdeflate>, 408C<OPTS>, are the same as those used with the OO interface defined in the 409L</"Constructor Options"> section 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 Examples 476 477To read the contents of the file C<file1.txt> and write the compressed 478data to the file C<file1.txt.1951>. 479 480 use strict ; 481 use warnings ; 482 use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; 483 484 my $input = "file1.txt"; 485 rawdeflate $input => "$input.1951" 486 or die "rawdeflate failed: $RawDeflateError\n"; 487 488To read from an existing Perl filehandle, C<$input>, and write the 489compressed data to a buffer, C<$buffer>. 490 491 use strict ; 492 use warnings ; 493 use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; 494 use IO::File ; 495 496 my $input = new IO::File "<file1.txt" 497 or die "Cannot open 'file1.txt': $!\n" ; 498 my $buffer ; 499 rawdeflate $input => \$buffer 500 or die "rawdeflate failed: $RawDeflateError\n"; 501 502To compress all files in the directory "/my/home" that match "*.txt" 503and store the compressed data in the same directory 504 505 use strict ; 506 use warnings ; 507 use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; 508 509 rawdeflate '</my/home/*.txt>' => '<*.1951>' 510 or die "rawdeflate failed: $RawDeflateError\n"; 511 512and if you want to compress each file one at a time, this will do the trick 513 514 use strict ; 515 use warnings ; 516 use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; 517 518 for my $input ( glob "/my/home/*.txt" ) 519 { 520 my $output = "$input.1951" ; 521 rawdeflate $input => $output 522 or die "Error compressing '$input': $RawDeflateError\n"; 523 } 524 525=head1 OO Interface 526 527=head2 Constructor 528 529The format of the constructor for C<IO::Compress::RawDeflate> is shown below 530 531 my $z = new IO::Compress::RawDeflate $output [,OPTS] 532 or die "IO::Compress::RawDeflate failed: $RawDeflateError\n"; 533 534It returns an C<IO::Compress::RawDeflate> object on success and undef on failure. 535The variable C<$RawDeflateError> will contain an error message on failure. 536 537If you are running Perl 5.005 or better the object, C<$z>, returned from 538IO::Compress::RawDeflate can be used exactly like an L<IO::File|IO::File> filehandle. 539This means that all normal output file operations can be carried out 540with C<$z>. 541For example, to write to a compressed file/buffer you can use either of 542these forms 543 544 $z->print("hello world\n"); 545 print $z "hello world\n"; 546 547The mandatory parameter C<$output> is used to control the destination 548of the compressed data. This parameter can take one of these forms. 549 550=over 5 551 552=item A filename 553 554If the C<$output> parameter is a simple scalar, it is assumed to be a 555filename. This file will be opened for writing and the compressed data 556will be written to it. 557 558=item A filehandle 559 560If the C<$output> parameter is a filehandle, the compressed data will be 561written to it. 562The string '-' can be used as an alias for standard output. 563 564=item A scalar reference 565 566If C<$output> is a scalar reference, the compressed data will be stored 567in C<$$output>. 568 569=back 570 571If the C<$output> parameter is any other type, C<IO::Compress::RawDeflate>::new will 572return undef. 573 574=head2 Constructor Options 575 576C<OPTS> is any combination of the following options: 577 578=over 5 579 580=item C<< AutoClose => 0|1 >> 581 582This option is only valid when the C<$output> parameter is a filehandle. If 583specified, and the value is true, it will result in the C<$output> being 584closed once either the C<close> method is called or the C<IO::Compress::RawDeflate> 585object is destroyed. 586 587This parameter defaults to 0. 588 589=item C<< Append => 0|1 >> 590 591Opens C<$output> in append mode. 592 593The behaviour of this option is dependent on the type of C<$output>. 594 595=over 5 596 597=item * A Buffer 598 599If C<$output> is a buffer and C<Append> is enabled, all compressed data 600will be append to the end of C<$output>. Otherwise C<$output> will be 601cleared before any data is written to it. 602 603=item * A Filename 604 605If C<$output> is a filename and C<Append> is enabled, the file will be 606opened in append mode. Otherwise the contents of the file, if any, will be 607truncated before any compressed data is written to it. 608 609=item * A Filehandle 610 611If C<$output> is a filehandle, the file pointer will be positioned to the 612end of the file via a call to C<seek> before any compressed data is written 613to it. Otherwise the file pointer will not be moved. 614 615=back 616 617This parameter defaults to 0. 618 619=item C<< Merge => 0|1 >> 620 621This option is used to compress input data and append it to an existing 622compressed data stream in C<$output>. The end result is a single compressed 623data stream stored in C<$output>. 624 625It is a fatal error to attempt to use this option when C<$output> is not an 626RFC 1951 data stream. 627 628There are a number of other limitations with the C<Merge> option: 629 630=over 5 631 632=item 1 633 634This module needs to have been built with zlib 1.2.1 or better to work. A 635fatal error will be thrown if C<Merge> is used with an older version of 636zlib. 637 638=item 2 639 640If C<$output> is a file or a filehandle, it must be seekable. 641 642=back 643 644This parameter defaults to 0. 645 646=item -Level 647 648Defines the compression level used by zlib. The value should either be 649a number between 0 and 9 (0 means no compression and 9 is maximum 650compression), or one of the symbolic constants defined below. 651 652 Z_NO_COMPRESSION 653 Z_BEST_SPEED 654 Z_BEST_COMPRESSION 655 Z_DEFAULT_COMPRESSION 656 657The default is Z_DEFAULT_COMPRESSION. 658 659Note, these constants are not imported by C<IO::Compress::RawDeflate> by default. 660 661 use IO::Compress::RawDeflate qw(:strategy); 662 use IO::Compress::RawDeflate qw(:constants); 663 use IO::Compress::RawDeflate qw(:all); 664 665=item -Strategy 666 667Defines the strategy used to tune the compression. Use one of the symbolic 668constants defined below. 669 670 Z_FILTERED 671 Z_HUFFMAN_ONLY 672 Z_RLE 673 Z_FIXED 674 Z_DEFAULT_STRATEGY 675 676The default is Z_DEFAULT_STRATEGY. 677 678=item C<< Strict => 0|1 >> 679 680This is a placeholder option. 681 682=back 683 684=head2 Examples 685 686TODO 687 688=head1 Methods 689 690=head2 print 691 692Usage is 693 694 $z->print($data) 695 print $z $data 696 697Compresses and outputs the contents of the C<$data> parameter. This 698has the same behaviour as the C<print> built-in. 699 700Returns true if successful. 701 702=head2 printf 703 704Usage is 705 706 $z->printf($format, $data) 707 printf $z $format, $data 708 709Compresses and outputs the contents of the C<$data> parameter. 710 711Returns true if successful. 712 713=head2 syswrite 714 715Usage is 716 717 $z->syswrite $data 718 $z->syswrite $data, $length 719 $z->syswrite $data, $length, $offset 720 721Compresses and outputs the contents of the C<$data> parameter. 722 723Returns the number of uncompressed bytes written, or C<undef> if 724unsuccessful. 725 726=head2 write 727 728Usage is 729 730 $z->write $data 731 $z->write $data, $length 732 $z->write $data, $length, $offset 733 734Compresses and outputs the contents of the C<$data> parameter. 735 736Returns the number of uncompressed bytes written, or C<undef> if 737unsuccessful. 738 739=head2 flush 740 741Usage is 742 743 $z->flush; 744 $z->flush($flush_type); 745 746Flushes any pending compressed data to the output file/buffer. 747 748This method takes an optional parameter, C<$flush_type>, that controls 749how the flushing will be carried out. By default the C<$flush_type> 750used is C<Z_FINISH>. Other valid values for C<$flush_type> are 751C<Z_NO_FLUSH>, C<Z_SYNC_FLUSH>, C<Z_FULL_FLUSH> and C<Z_BLOCK>. It is 752strongly recommended that you only set the C<flush_type> parameter if 753you fully understand the implications of what it does - overuse of C<flush> 754can seriously degrade the level of compression achieved. See the C<zlib> 755documentation for details. 756 757Returns true on success. 758 759=head2 tell 760 761Usage is 762 763 $z->tell() 764 tell $z 765 766Returns the uncompressed file offset. 767 768=head2 eof 769 770Usage is 771 772 $z->eof(); 773 eof($z); 774 775Returns true if the C<close> method has been called. 776 777=head2 seek 778 779 $z->seek($position, $whence); 780 seek($z, $position, $whence); 781 782Provides a sub-set of the C<seek> functionality, with the restriction 783that it is only legal to seek forward in the output file/buffer. 784It is a fatal error to attempt to seek backward. 785 786Empty parts of the file/buffer will have NULL (0x00) bytes written to them. 787 788The C<$whence> parameter takes one the usual values, namely SEEK_SET, 789SEEK_CUR or SEEK_END. 790 791Returns 1 on success, 0 on failure. 792 793=head2 binmode 794 795Usage is 796 797 $z->binmode 798 binmode $z ; 799 800This is a noop provided for completeness. 801 802=head2 opened 803 804 $z->opened() 805 806Returns true if the object currently refers to a opened file/buffer. 807 808=head2 autoflush 809 810 my $prev = $z->autoflush() 811 my $prev = $z->autoflush(EXPR) 812 813If the C<$z> object is associated with a file or a filehandle, this method 814returns the current autoflush setting for the underlying filehandle. If 815C<EXPR> is present, and is non-zero, it will enable flushing after every 816write/print operation. 817 818If C<$z> is associated with a buffer, this method has no effect and always 819returns C<undef>. 820 821B<Note> that the special variable C<$|> B<cannot> be used to set or 822retrieve the autoflush setting. 823 824=head2 input_line_number 825 826 $z->input_line_number() 827 $z->input_line_number(EXPR) 828 829This method always returns C<undef> when compressing. 830 831=head2 fileno 832 833 $z->fileno() 834 fileno($z) 835 836If the C<$z> object is associated with a file or a filehandle, C<fileno> 837will return the underlying file descriptor. Once the C<close> method is 838called C<fileno> will return C<undef>. 839 840If the C<$z> object is associated with a buffer, this method will return 841C<undef>. 842 843=head2 close 844 845 $z->close() ; 846 close $z ; 847 848Flushes any pending compressed data and then closes the output file/buffer. 849 850For most versions of Perl this method will be automatically invoked if 851the IO::Compress::RawDeflate object is destroyed (either explicitly or by the 852variable with the reference to the object going out of scope). The 853exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In 854these cases, the C<close> method will be called automatically, but 855not until global destruction of all live objects when the program is 856terminating. 857 858Therefore, if you want your scripts to be able to run on all versions 859of Perl, you should call C<close> explicitly and not rely on automatic 860closing. 861 862Returns true on success, otherwise 0. 863 864If the C<AutoClose> option has been enabled when the IO::Compress::RawDeflate 865object was created, and the object is associated with a file, the 866underlying file will also be closed. 867 868=head2 newStream([OPTS]) 869 870Usage is 871 872 $z->newStream( [OPTS] ) 873 874Closes the current compressed data stream and starts a new one. 875 876OPTS consists of any of the options that are available when creating 877the C<$z> object. 878 879See the L</"Constructor Options"> section for more details. 880 881=head2 deflateParams 882 883Usage is 884 885 $z->deflateParams 886 887TODO 888 889=head1 Importing 890 891A number of symbolic constants are required by some methods in 892C<IO::Compress::RawDeflate>. None are imported by default. 893 894=over 5 895 896=item :all 897 898Imports C<rawdeflate>, C<$RawDeflateError> and all symbolic 899constants that can be used by C<IO::Compress::RawDeflate>. Same as doing this 900 901 use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError :constants) ; 902 903=item :constants 904 905Import all symbolic constants. Same as doing this 906 907 use IO::Compress::RawDeflate qw(:flush :level :strategy) ; 908 909=item :flush 910 911These symbolic constants are used by the C<flush> method. 912 913 Z_NO_FLUSH 914 Z_PARTIAL_FLUSH 915 Z_SYNC_FLUSH 916 Z_FULL_FLUSH 917 Z_FINISH 918 Z_BLOCK 919 920=item :level 921 922These symbolic constants are used by the C<Level> option in the constructor. 923 924 Z_NO_COMPRESSION 925 Z_BEST_SPEED 926 Z_BEST_COMPRESSION 927 Z_DEFAULT_COMPRESSION 928 929=item :strategy 930 931These symbolic constants are used by the C<Strategy> option in the constructor. 932 933 Z_FILTERED 934 Z_HUFFMAN_ONLY 935 Z_RLE 936 Z_FIXED 937 Z_DEFAULT_STRATEGY 938 939=back 940 941=head1 EXAMPLES 942 943=head2 Apache::GZip Revisited 944 945See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited"> 946 947=head2 Working with Net::FTP 948 949See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP"> 950 951=head1 SEE ALSO 952 953L<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> 954 955L<IO::Compress::FAQ|IO::Compress::FAQ> 956 957L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>, 958L<Archive::Tar|Archive::Tar>, 959L<IO::Zlib|IO::Zlib> 960 961For RFC 1950, 1951 and 1952 see 962L<http://www.faqs.org/rfcs/rfc1950.html>, 963L<http://www.faqs.org/rfcs/rfc1951.html> and 964L<http://www.faqs.org/rfcs/rfc1952.html> 965 966The I<zlib> compression library was written by Jean-loup Gailly 967C<gzip@prep.ai.mit.edu> and Mark Adler C<madler@alumni.caltech.edu>. 968 969The primary site for the I<zlib> compression library is 970L<http://www.zlib.org>. 971 972The primary site for gzip is L<http://www.gzip.org>. 973 974=head1 AUTHOR 975 976This module was written by Paul Marquess, C<pmqs@cpan.org>. 977 978=head1 MODIFICATION HISTORY 979 980See the Changes file. 981 982=head1 COPYRIGHT AND LICENSE 983 984Copyright (c) 2005-2019 Paul Marquess. All rights reserved. 985 986This program is free software; you can redistribute it and/or 987modify it under the same terms as Perl itself. 988 989