1# File : Bzip2.pm 2# Author : Rob Janes 3# Created : 14 April 2005 4# Modified : 2015-12-08 rurban 5# Version : 2.24 6# 7# Copyright (c) 2005 Rob Janes. All rights reserved. 8# This program is free software; you can redistribute it and/or 9# modify it under the same terms as Perl itself. 10# 11 12package Compress::Bzip2; 13 14use 5.006; 15our $VERSION = "2.24"; 16use strict; 17use warnings; 18 19use Carp; 20use Getopt::Std; 21use Fcntl qw(:DEFAULT :mode); 22 23require Exporter; 24use AutoLoader; 25 26our @ISA = qw(Exporter); 27 28# Items to export into callers namespace by default. Note: do not export 29# names by default without a very good reason. Use EXPORT_OK instead. 30# Do not simply export all your public functions/methods/constants. 31 32# This allows declaration use Compress::Bzip2 ':all'; 33# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK 34# will save memory. 35our %EXPORT_TAGS = 36 ( 'constants' => [ qw( 37 BZ_CONFIG_ERROR 38 BZ_DATA_ERROR 39 BZ_DATA_ERROR_MAGIC 40 BZ_FINISH 41 BZ_FINISH_OK 42 BZ_FLUSH 43 BZ_FLUSH_OK 44 BZ_IO_ERROR 45 BZ_MAX_UNUSED 46 BZ_MEM_ERROR 47 BZ_OK 48 BZ_OUTBUFF_FULL 49 BZ_PARAM_ERROR 50 BZ_RUN 51 BZ_RUN_OK 52 BZ_SEQUENCE_ERROR 53 BZ_STREAM_END 54 BZ_UNEXPECTED_EOF 55 ) ], 56 57 'utilities' => [ qw( 58 &bzopen 59 &bzinflateInit 60 &bzdeflateInit 61 &memBzip &memBunzip 62 &compress &decompress 63 &bzip2 &bunzip2 64 &bzlibversion 65 $bzerrno 66 ) ], 67 68 'bzip1' => [ qw( 69 &compress 70 &decompress 71 &compress_init 72 &decompress_init 73 &version 74 ) ], 75 76 'gzip' => [ qw( 77 &gzopen 78 &inflateInit 79 &deflateInit 80 &compress &uncompress 81 &adler32 &crc32 82 83 ZLIB_VERSION 84 85 $gzerrno 86 87 Z_OK 88 Z_STREAM_END 89 Z_NEED_DICT 90 Z_ERRNO 91 Z_STREAM_ERROR 92 Z_DATA_ERROR 93 Z_MEM_ERROR 94 Z_BUF_ERROR 95 Z_VERSION_ERROR 96 97 Z_NO_FLUSH 98 Z_PARTIAL_FLUSH 99 Z_SYNC_FLUSH 100 Z_FULL_FLUSH 101 Z_FINISH 102 Z_BLOCK 103 104 Z_NO_COMPRESSION 105 Z_BEST_SPEED 106 Z_BEST_COMPRESSION 107 Z_DEFAULT_COMPRESSION 108 109 Z_FILTERED 110 Z_HUFFMAN_ONLY 111 Z_RLE 112 Z_DEFAULT_STRATEGY 113 114 Z_BINARY 115 Z_ASCII 116 Z_UNKNOWN 117 118 Z_DEFLATED 119 Z_NULL 120 ) ], 121 ); 122 123our @EXPORT_OK = ( @{ $EXPORT_TAGS{'utilities'} }, 124 @{ $EXPORT_TAGS{'constants'} }, 125 @{ $EXPORT_TAGS{'bzip1'} }, 126 @{ $EXPORT_TAGS{'gzip'} }, 127 ); 128 129$EXPORT_TAGS{'all'} = [ @EXPORT_OK ]; 130 131our @EXPORT = ( @{ $EXPORT_TAGS{'utilities'} }, @{ $EXPORT_TAGS{'constants'} } ); 132 133our $bzerrno = ""; 134our $gzerrno; 135*gzerrno = \$bzerrno; 136 137# Zlib compatibility 138## 139use constant ZLIB_VERSION => '1.x'; 140# allowed flush values 141use constant { Z_NO_FLUSH => 0, Z_PARTIAL_FLUSH => 1, Z_SYNC_FLUSH => 2, 142 Z_FULL_FLUSH => 3, Z_FINISH => 4, Z_BLOCK => 5 }; 143# return codes for functions, positive normal, negative error 144use constant { Z_OK => 0, Z_STREAM_END => 1, Z_NEED_DICT => 2, Z_ERRNO => -1, 145 Z_STREAM_ERROR => -2, Z_DATA_ERROR => -3, Z_MEM_ERROR => -4, 146 Z_BUF_ERROR => -5, Z_VERSION_ERROR => -6 }; 147# compression levels 148use constant { Z_NO_COMPRESSION => 0, Z_BEST_SPEED => 1, 149 Z_BEST_COMPRESSION => 9, Z_DEFAULT_COMPRESSION => -1 }; 150# compression strategy, for deflateInit 151use constant { Z_FILTERED => 1, Z_HUFFMAN_ONLY => 2, Z_RLE => 3, 152 Z_DEFAULT_STRATEGY => 0 }; 153# possible values of data_type (inflate) 154use constant { Z_BINARY => 0, Z_ASCII => 1, Z_UNKNOWN => 2 }; 155# the deflate compression method 156use constant Z_DEFLATED => 8; 157# for initialization 158use constant Z_NULL => 0; 159 160## gzopen, $gzerror, gzerror, gzclose, gzreadline, gzwrite 161 162sub AUTOLOAD { 163 # This AUTOLOAD is used to 'autoload' constants from the constant() 164 # XS function. 165 166 my $constname; 167 our $AUTOLOAD; 168 ($constname = $AUTOLOAD) =~ s/.*:://; 169 croak "&Compress::Bzip2::constant not defined" if $constname eq 'constant'; 170 my ($error, $val) = constant($constname); 171 if ($error) { croak $error; } 172 { 173 no strict 'refs'; 174 # Fixed between 5.005_53 and 5.005_61 175#XXX if ($] >= 5.00561) { 176#XXX *$AUTOLOAD = sub () { $val }; 177#XXX } 178#XXX else { 179 *$AUTOLOAD = sub { $val }; 180#XXX } 181 } 182 goto &$AUTOLOAD; 183} 184 185require XSLoader; 186XSLoader::load('Compress::Bzip2', $VERSION); 187 188#bootstrap Compress::Bzip2 $VERSION; 189 190############################################################################## 191## file compress uncompress commands 192 193sub _writefileopen ( $$;$ ) { 194 ## open a protected file for write 195 my ( $handle, $filename, $force ) = @_; 196 197 if ( sysopen($handle, $filename, $force ? O_WRONLY|O_CREAT|O_TRUNC : O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR) ) { 198 $_[0] = $handle if !defined($_[0]); 199 return $handle; 200 } 201 202 return undef; 203} 204 205sub _stat_snapshot ( $ ) { 206 my ( $filename ) = @_; 207 return undef if !defined($filename); 208 209 my @stats = stat $filename; 210 if (!@stats) { 211 warn "stat of $filename failed: $!\n" if !@stats; 212 return undef; 213 } 214 215 return \@stats; 216} 217 218sub _check_stat ( $$;$ ) { 219 my ( $filename, $statsnap, $force ) = @_; 220 221 if ( !defined($statsnap) || (ref($statsnap) eq 'ARRAY' && @$statsnap == 0) ) { 222 $statsnap = _stat_snapshot( $filename ); 223 if ( $statsnap ) { 224 if ( @_>1 ) { 225 if ( !defined($_[1]) ) { 226 $_[1] = $statsnap; 227 } 228 elsif ( ref($_[1]) eq 'ARRAY' && @{ $_[1] } == 0 ) { 229 @{ $_[1] } = @$statsnap; 230 } 231 } 232 } 233 else { 234 return undef; 235 } 236 } 237 238 if ( S_ISDIR( $statsnap->[2] ) ) { 239 bz_seterror( &BZ_IO_ERROR, "file $filename is a directory" ); 240 return 0; 241 } 242 243 if ( !S_ISREG( $statsnap->[2] ) ) { 244 bz_seterror( &BZ_IO_ERROR, "file $filename is not a normal file" ); 245 return 0; 246 } 247 248 if ( !$force && S_ISLNK( $statsnap->[2] ) ) { 249 bz_seterror( &BZ_IO_ERROR, "file $filename is a symlink" ); 250 return 0; 251 } 252 253 if ( !$force && $statsnap->[3] > 1 ) { 254 bz_seterror( &BZ_IO_ERROR, "file $filename has too many hard links" ); 255 return 0; 256 } 257 258 return 1; 259} 260 261sub _set_stat_from_snapshot ( $$ ) { 262 my ( $filename, $statsnap ) = @_; 263 264 if ( !chmod( S_IMODE( $statsnap->[2] ), $filename ) ) { 265 bz_seterror( &BZ_IO_ERROR, "chmod ".sprintf('%03o', S_IMODE( $statsnap->[2] ))." $filename failed: $!" ); 266 return undef; 267 } 268 269 if ( !utime @$statsnap[8,9], $filename ) { 270 bz_seterror( &BZ_IO_ERROR, 271 "utime " . join(' ',map { strftime('%Y-%m-%d %H:%M:%S', localtime $_) } @$statsnap[8,9] ) . 272 " $filename failed: $!" ); 273 return undef; 274 } 275 276 if ( !chown @$statsnap[4,5], $filename ) { 277 bz_seterror( &BZ_IO_ERROR, 278 "chown " . join(':', ( getpwuid($statsnap->[4]) )[0], ( getgrgid($statsnap->[5]) )[0]) . 279 " $filename failed: $!" ); 280 return 0; 281 } 282 283 return 1; 284} 285 286sub bzip2 ( @ ) { 287 return _process_files( 'bzip2', 'cfvks123456789', @_ ); 288} 289 290sub bunzip2 ( @ ) { 291 return _process_files( 'bunzip2', 'cdzfks123456789', @_ ); 292} 293 294sub bzcat ( @ ) { 295 return _process_files( 'bzcat', 'cdzfks123456789', @_ ); 296} 297 298sub _process_files ( @ ) { 299 my $command = shift; 300 my $opts = shift; 301 302 local @ARGV = @_; 303 304 my %opts; 305 return undef if !getopt( $opts, \%opts ); 306 # c compress or decompress to stdout 307 # d decompress 308 # z compress 309 # f force 310 # v verbose 311 # k keep 312 # s small 313 # 123456789 314 315 $opts{c} = 1 if $command eq 'bzcat'; 316 $opts{d} = 1 if $command eq 'bunzip2' || $command eq 'bzcat'; 317 $opts{z} = 1 if $command eq 'bzip2'; 318 319 my $read_from_stdin; 320 my ( $in, $bzin ); 321 my ( $out, $bzout ); 322 323 if ( !@ARGV ) { 324 $read_from_stdin = 1; 325 $opts{c} = 1; 326 if ( !open( $in, "<&STDIN" ) ) { 327 die "Error: failed to input from STDIN: '$!'\n"; 328 } 329 330 $bzin = bzopen( $in, "r" ); 331 } 332 333 if ( $opts{c} ) { 334 if ( !open( $out, ">&STDOUT" ) ) { 335 die "Error: failed to output to STDOUT: '$!'\n"; 336 } 337 338 $bzout = bzopen( $out, "w" ); 339 } 340 341 if ( !$opts{d} && !$opts{z} ) { 342 die "Error: neither compress nor decompress was indicated.\n"; 343 } 344 345 my $doneflag = 0; 346 while ( !$doneflag ) { 347 my $infile; 348 my $outfile; 349 my @statbuf; 350 351 if ( !$read_from_stdin ) { 352 $infile = shift @ARGV; 353 if ( ! -r $infile ) { 354 print STDERR "Error: file $infile is not readable\n"; 355 next; 356 } 357 358 @statbuf = stat _; 359 if ( !@statbuf ) { 360 print STDERR "Error: failed to stat $infile: '$!'\n"; 361 next; 362 } 363 364 if ( !_check_stat( $infile, \@statbuf, $opts{f} ) ) { 365 print STDERR "Error: file $infile stat check fails: $bzerrno\n"; 366 next; 367 } 368 } 369 370 my $outfile_exists; 371 if ( !$opts{c} ) { 372 undef $out; 373 if ( $opts{d} ) { 374 $outfile = $infile . '.bz2'; 375 } 376 elsif ( $opts{z} ) { 377 $outfile = $infile =~ /\.bz2$/ ? substr($infile,0,-4) : $infile.'.out'; 378 } 379 380 $outfile_exists = -e $outfile; 381 if ( !_writefileopen( $out, $outfile, $opts{f} ) ) { 382 print STDERR "Error: failed to open $outfile for write: '$!'\n"; 383 next; 384 } 385 } 386 387 if ( !$read_from_stdin ) { 388 undef $in; 389 if ( !open( $in, $infile ) ) { 390 print STDERR "Error: unable to open $infile: '$!'\n"; 391 unlink( $outfile ) if !$outfile_exists; 392 next; 393 } 394 } 395 396 if ( $opts{d} ) { 397 $bzin = bzopen( $in, "r" ) if !$read_from_stdin; 398 399 my $buf; 400 my $notdone = 1; 401 while ( $notdone ) { 402 my $ln = bzread( $in, $buf, 1024 ); 403 if ( $ln > 0 ) { 404 syswrite( $out, $buf, $ln ); 405 } 406 elsif ( $ln == 0 ) { 407 undef $notdone; 408 } 409 else { 410 } 411 } 412 413 close($out); 414 415 if ( !$read_from_stdin ) { 416 bzclose($in); 417 unlink( $infile ) if !$opts{k}; 418 _set_stat_from_snapshot( $outfile, \@statbuf ); 419 } 420 } 421 elsif ( $opts{z} ) { 422 $bzout = bzopen( $out, "w" ) if !$opts{c}; 423 424 my $buf; 425 my $notdone = 1; 426 while ( $notdone ) { 427 my $ln = sysread( $in, $buf, 1024 ); 428 if ( $ln > 0 ) { 429 bzwrite( $bzout, $buf, $ln ); 430 } 431 elsif ( $ln == 0 ) { 432 undef $notdone; 433 } 434 else { 435 } 436 } 437 438 close($in); 439 440 if ( !$opts{c} ) { 441 bzclose($bzout); 442 unlink( $infile ) if !$opts{k}; 443 _set_stat_from_snapshot( $outfile, \@statbuf ); 444 } 445 } 446 } 447} 448 449############################################################################## 450############################################################################## 451## compatibility with Compress::Bzip2 1.03 452 453sub add ( $$ ) { 454 my ( $obj, $buffer ) = @_; 455 456 my @res = $obj->is_write ? $obj->bzdeflate( $buffer ) : $obj->bzinflate( $buffer ); 457 458 return $res[0]; 459} 460 461sub finish ( $;$ ) { 462 my ( $obj, $buffer ) = @_; 463 my ( @res, $out ); 464 465 if ( defined($buffer) ) { 466 @res = $obj->is_write ? $obj->bzdeflate( $buffer ) : $obj->bzinflate( $buffer ); 467 return undef if $res[1] != &BZ_OK; 468 469 $out = $res[0]; 470 } 471 $out = '' if !defined($out); 472 473 @res = $obj->bzclose; 474 return undef if $res[1] != &BZ_OK; 475 476 return $out.$res[0]; 477} 478 479sub input_size ( $ ) { 480 my ( $obj ) = @_; 481 return $obj->total_in; 482} 483 484sub output_size ( $ ) { 485 my ( $obj ) = @_; 486 return $obj->total_out; 487} 488 489sub version ( ) { 490 return bzlibversion(); 491} 492 493sub error ( $ ) { 494 return $_[0]->bzerror; 495} 496 497############################################################################## 498############################################################################## 499## THE Compress::Zlib compatibility section 500 501sub _bzerror2gzerror { 502 my ( $bz_error_num ) = @_; 503 my $gz_error_num = 504 $bz_error_num == &BZ_OK ? Z_OK : 505 $bz_error_num == &BZ_RUN_OK ? Z_OK : 506 $bz_error_num == &BZ_FLUSH_OK ? Z_STREAM_END : 507 $bz_error_num == &BZ_FINISH_OK ? Z_STREAM_END : 508 $bz_error_num == &BZ_STREAM_END ? Z_STREAM_END : 509 510 $bz_error_num == &BZ_SEQUENCE_ERROR ? Z_VERSION_ERROR : 511 $bz_error_num == &BZ_PARAM_ERROR ? Z_ERRNO : 512 $bz_error_num == &BZ_MEM_ERROR ? Z_MEM_ERROR : 513 $bz_error_num == &BZ_DATA_ERROR ? Z_DATA_ERROR : 514 $bz_error_num == &BZ_DATA_ERROR_MAGIC ? Z_DATA_ERROR : 515 $bz_error_num == &BZ_IO_ERROR ? Z_ERRNO : 516 $bz_error_num == &BZ_UNEXPECTED_EOF ? Z_STREAM_ERROR : 517 $bz_error_num == &BZ_OUTBUFF_FULL ? Z_BUF_ERROR : 518 $bz_error_num == &BZ_CONFIG_ERROR ? Z_VERSION_ERROR : 519 Z_VERSION_ERROR 520 ; 521 522 return $gz_error_num; 523} 524 525sub gzopen ( $$ ) { 526 goto &bzopen; 527} 528 529sub gzread ( $$;$ ) { 530 goto &bzread; 531} 532 533sub gzreadline ( $$ ) { 534 goto &bzreadline; 535} 536 537sub gzwrite ( $$ ) { 538 goto &bzwrite; 539} 540 541sub gzflush ( $;$ ) { 542 my ( $obj, $flush ) = @_; 543 return Z_OK if $flush == Z_NO_FLUSH; 544 goto &bzflush; 545} 546 547sub gzclose ( $ ) { 548 goto &bzclose; 549} 550 551sub gzeof ( $ ) { 552 goto &bzeof; 553} 554 555sub gzsetparams ( $$$ ) { 556 ## ignore params 557 my ( $obj, $level, $strategy ) = @_; 558 return Z_OK; 559} 560 561sub gzerror ( $ ) { 562 goto &bzerror; 563} 564 565sub deflateInit ( @ ) { 566 ## ignore all options: 567 ## -Level, -Method, -WindowBits, -MemLevel, -Strategy, -Dictionary, -Bufsize 568 569 my @res = bzdeflateInit(); 570 return $res[0] if !wantarray; 571 572 return ( $res[0], _bzerror2gzerror( $res[1] ) ); 573} 574 575sub deflate ( $$ ) { 576 my ( $obj, $buffer ) = @_; 577 578 my @res = $obj->bzdeflate( $buffer ); 579 580 return $res[0] if !wantarray; 581 return ( $res[0], _bzerror2gzerror( $res[1] ) ); 582} 583 584sub deflateParams ( $;@ ) { 585 ## ignore all options 586 return Z_OK; 587} 588 589sub flush ( $;$ ) { 590 my ( $obj, $flush_type ) = @_; 591 592 $flush_type = Z_FINISH if !defined($flush_type); 593 return Z_OK if $flush_type == Z_NO_FLUSH; 594 595 my $bz_flush_type; 596 my @res; 597 598 $bz_flush_type = 599 $flush_type == Z_PARTIAL_FLUSH || $flush_type == Z_SYNC_FLUSH ? &BZ_FLUSH : 600 $flush_type == Z_FULL_FLUSH ? &BZ_FINISH : 601 &BZ_FINISH; 602 603 @res = $obj->bzflush( $bz_flush_type ); 604 605 return $res[0] if !wantarray; 606 return ( $res[0], _bzerror2gzerror( $res[1] ) ); 607} 608 609sub dict_adler ( $ ) { 610 return 1; # ??? 611} 612 613sub msg ( $ ) { 614 my ( $obj ) = @_; 615 616 return ''.($obj->bzerror).''; # stringify 617} 618 619sub inflateInit ( @ ) { 620 ## ignore all options: 621 ## -WindowBits, -Dictionary, -Bufsize 622 623 my @res = bzinflateInit(); 624 return $res[0] if !wantarray; 625 626 return ( $res[0], _bzerror2gzerror( $res[1] ) ); 627} 628 629sub inflate ( $$ ) { 630 my ( $obj, $buffer ) = @_; 631 632 my @res = $obj->bzinflate( $buffer ); 633 634 return $res[0] if !wantarray; 635 return ( $res[0], _bzerror2gzerror( $res[1] ) ); 636} 637 638sub inflateSync ( $ ) { 639 return Z_VERSION_ERROR; # ?? what 640} 641 642sub memGzip ( $ ) { 643 goto &memBzip; 644} 645 646sub memGunzip ( $ ) { 647 goto &memBunzip; 648} 649 650sub adler32 ( $;$ ) { 651 return 0; 652} 653 654sub crc32 ( $;$ ) { 655 return 0; 656} 657 658# sub compress ( $;$ ) { 659# ## ignore $level 660# my ( $source, $level ) = @_; 661# return memBzip( $source ); 662# } 663 664sub uncompress ( $ ) { 665 my ( $source, $level ) = @_; 666 return memBunzip( $source ); 667} 668 669# Autoload methods go after =cut, and are processed by the autosplit program. 670 6711; 672 673__END__ 674 675=pod 676 677=head1 NAME 678 679Compress::Bzip2 - Interface to Bzip2 compression library 680 681=head1 SYNOPSIS 682 683 use Compress::Bzip2 qw(:all :constant :utilities :gzip); 684 685 ($bz, $status) = bzdeflateInit( [PARAMS] ); 686 ($out, $status) = $bz->bzdeflate($buffer) ; # compress 687 688 ($bz, $status) = bzinflateInit( [PARAMS] ); 689 ($out, $status) = $bz->bzinflate($buffer); # uncompress 690 691 ($out, $status) = $bz->bzflush() ; 692 ($out, $status) = $bz->bzclose() ; 693 694 $dest = memBzip($source); 695 alias compress 696 $dest = memBunzip($source); 697 alias decompress 698 699 $bz = Compress::Bzip2->new( [PARAMS] ); 700 701 $bz = bzopen($filename or filehandle, $mode); 702 alternate, with $bz created by new(): 703 $bz->bzopen($filename or filehandle, $mode); 704 705 $bytesread = $bz->bzread($buffer [,$size]) ; 706 $bytesread = $bz->bzreadline($line); 707 $byteswritten = $bz->bzwrite($buffer [,$limit]); 708 $errstring = $bz->bzerror(); 709 $status = $bz->bzeof(); 710 $status = $bz->bzflush(); 711 $status = $bz->bzclose() ; 712 713 $status = $bz->bzsetparams( $param => $setting ); 714 715 $bz->total_in() ; 716 $bz->total_out() ; 717 718 $verstring = $bz->bzversion(); 719 720 $Compress::Bzip2::bzerrno 721 722=head1 DESCRIPTION 723 724The I<Compress::Bzip2> module provides a Perl interface to the B<bzip2> 725compression library (see L</AUTHOR> for details about where to get 726I<Bzip2>). A relevant subset of the functionality provided by I<bzip2> 727is available in I<Compress::Bzip2>. 728 729All string parameters can either be a scalar or a scalar reference. 730 731The module can be split into two general areas of functionality, namely 732in-memory compression/decompression and read/write access to I<bzip2> 733files. Each of these areas will be discussed separately below. 734 735B<NOTE> 736 737I<Compress::Bzip2> is just a simple I<bzip2> binding, comparable to the 738old L<Compress::Zlib> library. It is not well integrated into PerlIO, 739use the preferred L<IO::Compress::Bzip2> instead. 740 741 742=head1 FILE READ/WRITE INTERFACE 743 744A number of functions are supplied in I<bzlib> for reading and writing 745I<bzip2> files. Unfortunately, most of them are not suitable. So, this 746module provides another interface, built over top of the low level bzlib 747methods. 748 749=head2 B<$bz = bzopen(filename or filehandle, mode)> 750 751This function returns an object which is used to access the other 752I<bzip2> methods. 753 754The B<mode> parameter is used to specify both whether the file is 755opened for reading or writing, with "r" or "w" respectively. 756 757If a reference to an open filehandle is passed in place of the 758filename, it better be positioned to the start of a 759compression/decompression sequence. 760 761WARNING: With Perl 5.6 you cannot use a filehandle because of 762SEGV in destruction with bzclose or an implicit close. 763 764=head2 B<$bz = Compress::Bzip2-E<gt>new( [PARAMS] )> 765 766Create a Compress::Bzip2 object. Optionally, provide 767compression/decompression parameters as a keyword => setting list. 768See I<bzsetparams()> for a description of the parameters. 769 770=head2 B<$bz-E<gt>bzopen(filename or filehandle, mode)> 771 772This is bzopen, but it uses an object previously created by the new 773method. Other than that, it is identical to the above bzopen. 774 775=head2 B<$bytesread = $bz-E<gt>bzread($buffer [, $size]) ;> 776 777Reads B<$size> bytes from the compressed file into B<$buffer>. If 778B<$size> is not specified, it will default to 4096. If the scalar 779B<$buffer> is not large enough, it will be extended automatically. 780 781Returns the number of bytes actually read. On EOF it returns 0 and in 782the case of an error, -1. 783 784=head2 B<$bytesread = $bz-E<gt>bzreadline($line) ;> 785 786Reads the next line from the compressed file into B<$line>. 787 788Returns the number of bytes actually read. On EOF it returns 0 and in 789the case of an error, -1. 790 791It IS legal to intermix calls to B<bzread> and B<bzreadline>. 792 793At this time B<bzreadline> ignores the variable C<$/> 794(C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use). The 795end of a line is denoted by the C character C<'\n'>. 796 797=head2 B<$byteswritten = $bz-E<gt>bzwrite($buffer [, $limit]) ;> 798 799Writes the contents of B<$buffer> to the compressed file. Returns the 800number of bytes actually written, or 0 on error. 801 802If $limit is given and non-zero, then only that many bytes from 803$buffer will be written. 804 805=head2 B<$status = $bz-E<gt>bzflush($flush) ;> 806 807Flushes all pending output to the compressed file. 808Works identically to the I<zlib> function it interfaces to. Note that 809the use of B<bzflush> can degrade compression. 810 811Returns C<BZ_OK> if B<$flush> is C<BZ_FINISH> and all output could be 812flushed. Otherwise the bzlib error code is returned. 813 814Refer to the I<bzlib> documentation for the valid values of B<$flush>. 815 816=head2 B<$status = $bz-E<gt>bzeof() ;> 817 818Returns 1 if the end of file has been detected while reading the input 819file, otherwise returns 0. 820 821=head2 B<$bz-E<gt>bzclose> 822 823Closes the compressed file. Any pending data is flushed to the file 824before it is closed. 825 826=head2 B<$bz-E<gt>bzsetparams( [PARAMS] );> 827 828Change settings for the deflate stream C<$bz>. 829 830The list of the valid options is shown below. Options not specified 831will remain unchanged. 832 833=over 5 834 835=item B<-verbosity> 836 837Defines the verbosity level. Valid values are 0 through 4, 838 839The default is C<-verbosity =E<gt> 0>. 840 841=item B<-blockSize100k> 842 843For bzip object opened for stream deflation or write. 844 845Defines the buffering factor of compression method. The algorithm 846buffers all data until the buffer is full, then it flushes all the 847data out. Use -blockSize100k to specify the size of the buffer. 848 849Valid settings are 1 through 9, representing a blocking in multiples 850of 100k. 851 852Note that each such block has an overhead of leading and trailing 853synchronization bytes. bzip2 recovery uses this information to 854pull useable data out of a corrupted file. 855 856A streaming application would probably want to set the blocking low. 857 858=item B<-workFactor> 859 860For bzip object opened for stream deflation or write. 861 862The workFactor setting tells the deflation algorithm how much work 863to invest to compensate for repetitive data. 864 865workFactor may be a number from 0 to 250 inclusive. The default setting 866is 30. 867 868See the bzip documentation for more information. 869 870=item B<-small> 871 872For bzip object opened for stream inflation or read. 873 874B<small> may be 0 or 1. Set C<small> to one to use a slower, less 875memory intensive algorithm. 876 877=back 878 879=head2 B<$bz-E<gt>bzerror> 880 881Returns the I<bzlib> error message or number for the last operation 882associated with B<$bz>. The return value will be the I<bzlib> error 883number when used in a numeric context and the I<bzlib> error message 884when used in a string context. The I<bzlib> error number constants, 885shown below, are available for use. 886 887 BZ_CONFIG_ERROR 888 BZ_DATA_ERROR 889 BZ_DATA_ERROR_MAGIC 890 BZ_FINISH 891 BZ_FINISH_OK 892 BZ_FLUSH 893 BZ_FLUSH_OK 894 BZ_IO_ERROR 895 BZ_MAX_UNUSED 896 BZ_MEM_ERROR 897 BZ_OK 898 BZ_OUTBUFF_FULL 899 BZ_PARAM_ERROR 900 BZ_RUN 901 BZ_RUN_OK 902 BZ_SEQUENCE_ERROR 903 BZ_STREAM_END 904 BZ_UNEXPECTED_EOF 905 906=head2 B<$bz-E<gt>bzclearerr> 907 908=head2 B<$bzerrno> 909 910The B<$bzerrno> scalar holds the error code associated with the most 911recent I<bzip2> routine. Note that unlike B<bzerror()>, the error is 912I<not> associated with a particular file. 913 914As with B<bzerror()> it returns an error number in numeric context and 915an error message in string context. Unlike B<bzerror()> though, the 916error message will correspond to the I<bzlib> message when the error is 917associated with I<bzlib> itself, or the UNIX error message when it is 918not (i.e. I<bzlib> returned C<Z_ERRORNO>). 919 920As there is an overlap between the error numbers used by I<bzlib> and 921UNIX, B<$bzerrno> should only be used to check for the presence of 922I<an> error in numeric context. Use B<bzerror()> to check for specific 923I<bzlib> errors. The I<bzcat> example below shows how the variable can 924be used safely. 925 926=head2 B<$bz-E<gt>prefix> 927 928Returns the additional 5 byte header which is prepended to the bzip2 929header starting with C<BZh> when using memBzip/compress. 930 931=head1 Compress::Bzip2 Utilities 932 933Options: -d -c -z -f -v -k -s -1..9 934 935=head2 bzip2( [OPTS], filename) 936 937=head2 bunzip2(filename) 938 939=head2 bzcat(filenames...) 940 941=head2 bzlibversion() 942 943=head2 bzinflateInit( opts... ) 944 945=head1 Internal Utilties 946 947=head2 bz_seterror(errno, msg) 948=head2 $bz-E<gt>is_read() 949=head2 $bz-E<gt>is_stream() 950=head2 $bz-E<gt>is_write() 951=head2 $bz-E<gt>total_in() 952=head2 $bz-E<gt>total_out() 953=head2 version() 954 955=head1 Compress::Bzip2 1.03 COMPATIBILITY 956 957While the 2.x thread forked off of 1.00, another line of development 958came to a head at 1.03. The 1.03 version worked with bzlib 1.0.2, had 959improvements to the error handling, single buffer inflate/deflate, a 960streaming interface to inflate/deflate, and a cpan style test suite. 961 962=head2 B<$dest = compress( $string, [$level] )> 963 964Alias to L<memBzip>, this compresses string, using the optional 965compression level, 1 through 9, the default being 6. Returns a string 966containing the compressed data. 967 968On error I<undef> is returned. 969 970=head2 B<$dest = decompress($string, [$level])> 971 972Alias to L<memBunzip>, this decompresses the data in string, returning a 973string containing the decompressed data. 974 975On error I<undef> is returned. 976 977=head2 uncompress($string, [$level]) 978 979Another alias to L<memBunzip> 980 981=head2 B<$stream = compress_init( [PARAMS] )> 982 983Alias to bzdeflateInit. In addition to the named parameters 984documented for bzdeflateInit, the following are accepted: 985 986 -level, alias to -blockSize100k 987 -buffer, to set the buffer size. 988 989The -buffer option is ignored. The intermediate buffer size is not 990changeable. 991 992=head2 B<$stream = decompress_init( [PARAMS] )> 993 994Alias to bzinflateInit. See bzinflateInit for a description of the parameters. 995The option "-buffer" is accepted, but ignored. 996 997=head2 B<$output = $stream-E<gt>add( $string )> 998 999Add data to be compressed/decompressed. Returns whatever output is available 1000(possibly none, if it's still buffering it), or undef on error. 1001 1002=head2 B<$output = $stream-E<gt>finish( [$string] )> 1003 1004Finish the operation; takes an optional final data string. Whatever is 1005returned completes the output; returns undef on error. 1006 1007=head2 B<$stream-E<gt>error> 1008 1009Like the function, but applies to the current object only. Note that errors 1010in a stream object are also returned by the function. 1011 1012=head2 B<$stream-E<gt>input_size> 1013 1014Alias to total_in. Total bytes passed to the stream. 1015 1016=head2 B<$stream-E<gt>output_size> 1017 1018Alias to total_out. Total bytes received from the stream. 1019 1020=head1 GZIP COMPATIBILITY INTERFACE 1021 1022Except for the exact state and error numbers, this package presents an 1023interface very much like that given by the Compress::Zlib package. 1024Mostly, if you take the method name, state or error number from 1025Compress::Zlib and replace the "g" with a "b", your code should work. 1026 1027To make the interoperability even easier, all the Compress::Zlib method 1028names have been used as aliases or cover functions for the bzip2 methods. 1029 1030Therefore, most code that uses Compress::Zlib should be able to use 1031this package, with a one line change. 1032 1033Simply change 1034 1035 $gz = Compress::Zlib::gzopen( "filename", "w" ); 1036 1037to 1038 1039 $gz = Compress::Bzip2::gzopen( "filename", "w" ); 1040 1041Some of the Compress::Zlib aliases don't return anything useful, like 1042crc32 or adler32, cause bzip2 doesn't do that sort of thing. 1043 1044=head2 B< $gz = gzopen( $filename, $mode ) > 1045 1046Alias for bzopen. 1047 1048=head2 B< $gz-E<gt>gzread( $buffer, [ $length ] ) > 1049 1050Alias for bzread. 1051 1052=head2 B< $gz-E<gt>gzreadline( $buffer ) > 1053 1054Alias for bzreadline. 1055 1056=head2 B< $gz-E<gt>gzwrite( $buffer ) > 1057 1058Alias for bzwrite. 1059 1060=head2 B< $gz-E<gt>gzflush( [$flushtype] ) > 1061 1062Alias for bzflush, with return code translation. 1063 1064=head2 B< $gz-E<gt>gzclose( ) > 1065 1066Alias for bzclose. 1067 1068=head2 B< $gz-E<gt>gzeof( ) > 1069 1070Alias for bzeof. 1071 1072=head2 B< $gz-E<gt>gzerror( ) > 1073 1074Alias for bzerror. 1075 1076=head2 B< $gz-E<gt>gzsetparams( $level, $strategy ) > 1077 1078This is a no-op. 1079 1080=head2 B< $d = deflateInit( [OPTS] ) > 1081 1082Alias for bzdeflateInit, with return code translation. 1083 1084All OPTS are ignored. 1085 1086=head2 B< $d-E<gt>deflate( $buffer ) > 1087 1088Alias for bzdeflate, with return code translation. 1089 1090=head2 B< $d-E<gt>deflateParams( [OPTS] ) > 1091 1092This is a no-op. 1093 1094=head2 B< $d-E<gt>flush( [$flushtype] ) > 1095 1096Cover function for bzflush or bzclose, depending on $flushtype. 1097 1098See the Compress::Zlib documentation for more information. 1099 1100=head2 B< $d-E<gt>dict_adler( ) > 1101 1102This is a no-op. 1103 1104=head2 B< $d-E<gt>msg( ) > 1105 1106This is a no-op. 1107 1108=head2 B< $d = inflateInit( [OPTS] ) > 1109 1110Alias for bzinflateInit, with return code translation. 1111 1112All OPTS are ignored. 1113 1114=head2 B< $d-E<gt>inflate( ) > 1115 1116Alias for bzinflate, with return code translation. 1117 1118=head2 B< $d-E<gt>inflateSync( ) > 1119 1120This is a no-op. 1121 1122=head2 B< $d-E<gt>adler32( $crc ) > 1123 1124This is a no-op. 1125 1126=head2 B< $d-E<gt>crc32( $crc ) > 1127 1128This is a no-op. 1129 1130=head2 B< $buffer = memGzip( $buffer ) > 1131 1132Alias for memBzip. 1133 1134=head2 B< $buffer = memGunzip( $buffer ) > 1135 1136Alias for memBunzip. 1137 1138=head1 IN-MEMORY COMPRESS/UNCOMPRESS 1139 1140Two high-level functions are provided by I<bzlib> to perform in-memory 1141compression. They are B<memBzip> and B<memBunzip>. Two Perl subs are 1142provided which provide similar functionality. 1143 1144=head2 B<$compressed = memBzip($buffer);> 1145 1146Compresses B<$buffer>. If successful it returns the compressed 1147data. Otherwise it returns I<undef>. 1148 1149The buffer parameter can either be a scalar or a scalar reference. 1150 1151Essentially, an in-memory bzip file is created. It creates a minimal 1152bzip header, which adds 5 bytes before the bzip2 specific BZh header. 1153 1154=head2 B<$uncompressed = memBunzip($buffer);> 1155 1156Uncompresses B<$buffer>. If successful it returns the uncompressed 1157data. Otherwise it returns I<undef>. 1158 1159The source buffer can either be a scalar or a scalar reference. 1160 1161The buffer parameter can either be a scalar or a scalar reference. The 1162contents of the buffer parameter are destroyed after calling this 1163function. 1164 1165=head1 STREAM DEFLATE (= COMPRESS) 1166 1167The Perl interface will I<always> consume the complete input buffer 1168before returning. Also the output buffer returned will be 1169automatically grown to fit the amount of output available. 1170 1171Here is a definition of the interface available: 1172 1173=head2 B<($d, $status) = bzdeflateInit( [PARAMS] )> 1174 1175Initialises a deflation stream. 1176 1177If successful, it will return the initialised deflation stream, B<$d> 1178and B<$status> of C<BZ_OK> in a list context. In scalar context it 1179returns the deflation stream, B<$d>, only. 1180 1181If not successful, the returned deflation stream (B<$d>) will be 1182I<undef> and B<$status> will hold the exact I<bzip2> error code. 1183 1184The function optionally takes a number of named options specified as 1185C<-Name=E<gt>value> pairs. This allows individual options to be 1186tailored without having to specify them all in the parameter list. 1187 1188Here is a list of the valid options: 1189 1190=over 5 1191 1192=item B<-verbosity> 1193 1194Defines the verbosity level. Valid values are 0 through 4, 1195 1196The default is C<-verbosity =E<gt> 0>. 1197 1198=item B<-blockSize100k> 1199 1200Defines the buffering factor of compression method. The algorithm 1201buffers all data until the buffer is full, then it flushes all the 1202data out. Use -blockSize100k to specify the size of the buffer. 1203 1204Valid settings are 1 through 9, representing a blocking in multiples 1205of 100k. 1206 1207Note that each such block has an overhead of leading and trailing 1208synchronization bytes. bzip2 recovery uses this information to 1209pull useable data out of a corrupted file. 1210 1211A streaming application would probably want to set the blocking low. 1212 1213=item B<-workFactor> 1214 1215The workFactor setting tells the deflation algorithm how much work 1216to invest to compensate for repetitive data. 1217 1218workFactor may be a number from 0 to 250 inclusive. The default setting 1219is 30. 1220 1221See the bzip documentation for more information. 1222 1223=back 1224 1225Here is an example of using the B<deflateInit> optional parameter list 1226to override the default buffer size and compression level. All other 1227options will take their default values. 1228 1229 bzdeflateInit( -blockSize100k => 1, -verbosity => 1 ); 1230 1231=head2 B<($out, $status) = $d-E<gt>bzdeflate($buffer)> 1232 1233Deflates the contents of B<$buffer>. The buffer can either be a scalar 1234or a scalar reference. When finished, B<$buffer> will be 1235completely processed (assuming there were no errors). If the deflation 1236was successful it returns deflated output, B<$out>, and a status 1237value, B<$status>, of C<Z_OK>. 1238 1239On error, B<$out> will be I<undef> and B<$status> will contain the 1240I<zlib> error code. 1241 1242In a scalar context B<bzdeflate> will return B<$out> only. 1243 1244As with the internal buffering of the I<deflate> function in I<bzip2>, 1245it is not necessarily the case that any output will be produced by 1246this method. So don't rely on the fact that B<$out> is empty for an 1247error test. In fact, given the size of bzdeflates internal buffer, 1248with most files it's likely you won't see any output at all until 1249flush or close. 1250 1251=head2 B<($out, $status) = $d-E<gt>bzflush([flush_type])> 1252 1253Typically used to finish the deflation. Any pending output will be 1254returned via B<$out>. B<$status> will have a value C<BZ_OK> if 1255successful. 1256 1257In a scalar context B<bzflush> will return B<$out> only. 1258 1259Note that flushing can seriously degrade the compression ratio, so it 1260should only be used to terminate a decompression (using C<BZ_FLUSH>) or 1261when you want to create a I<full flush point> (using C<BZ_FINISH>). 1262 1263The allowable values for C<flush_type> are C<BZ_FLUSH> and C<BZ_FINISH>. 1264 1265For a handle opened for "w" (bzwrite), the default is C<BZ_FLUSH>. 1266For a stream, the default for C<flush_type> is C<BZ_FINISH> (which is 1267essentially a close and reopen). 1268 1269It is strongly recommended that you only set the C<flush_type> 1270parameter if you fully understand the implications of what it 1271does. See the C<bzip2> documentation for details. 1272 1273=head2 Example 1274 1275Here is a trivial example of using B<bzdeflate>. It simply reads standard 1276input, deflates it and writes it to standard output. 1277 1278 use strict ; 1279 use warnings ; 1280 1281 use Compress::Bzip2 ; 1282 1283 binmode STDIN; 1284 binmode STDOUT; 1285 my $x = bzdeflateInit() 1286 or die "Cannot create a deflation stream\n" ; 1287 1288 my ($output, $status) ; 1289 while (<>) 1290 { 1291 ($output, $status) = $x->bzdeflate($_) ; 1292 1293 $status == BZ_OK 1294 or die "deflation failed\n" ; 1295 1296 print $output ; 1297 } 1298 1299 ($output, $status) = $x->bzclose() ; 1300 1301 $status == BZ_OK 1302 or die "deflation failed\n" ; 1303 1304 print $output ; 1305 1306=head1 STREAM INFLATE 1307 1308Here is a definition of the interface: 1309 1310=head2 B<($i, $status) = inflateInit()> 1311 1312Initialises an inflation stream. 1313 1314In a list context it returns the inflation stream, B<$i>, and the 1315I<zlib> status code (B<$status>). In a scalar context it returns the 1316inflation stream only. 1317 1318If successful, B<$i> will hold the inflation stream and B<$status> will 1319be C<BZ_OK>. 1320 1321If not successful, B<$i> will be I<undef> and B<$status> will hold the 1322I<bzlib.h> error code. 1323 1324The function optionally takes a number of named options specified as 1325C<-Name=E<gt>value> pairs. This allows individual options to be 1326tailored without having to specify them all in the parameter list. 1327 1328For backward compatibility, it is also possible to pass the parameters 1329as a reference to a hash containing the name=>value pairs. 1330 1331The function takes one optional parameter, a reference to a hash. The 1332contents of the hash allow the deflation interface to be tailored. 1333 1334Here is a list of the valid options: 1335 1336=over 5 1337 1338=item B<-small> 1339 1340B<small> may be 0 or 1. Set C<small> to one to use a slower, less 1341memory intensive algorithm. 1342 1343=item B<-verbosity> 1344 1345Defines the verbosity level. Valid values are 0 through 4, 1346 1347The default is C<-verbosity =E<gt> 0>. 1348 1349=back 1350 1351Here is an example of using the B<bzinflateInit> optional parameter. 1352 1353 bzinflateInit( -small => 1, -verbosity => 1 ); 1354 1355=head2 B<($out, $status) = $i-E<gt>bzinflate($buffer)> 1356 1357Inflates the complete contents of B<$buffer>. The buffer can either be 1358a scalar or a scalar reference. 1359 1360Returns C<BZ_OK> if successful and C<BZ_STREAM_END> if the end of the 1361compressed data has been successfully reached. If not successful, 1362B<$out> will be I<undef> and B<$status> will hold the I<bzlib> error 1363code. 1364 1365The C<$buffer> parameter is modified by C<bzinflate>. On completion it 1366will contain what remains of the input buffer after inflation. This 1367means that C<$buffer> will be an empty string when the return status 1368is C<BZ_OK>. When the return status is C<BZ_STREAM_END> the C<$buffer> 1369parameter will contains what (if anything) was stored in the input 1370buffer after the deflated data stream. 1371 1372This feature is useful when processing a file format that encapsulates 1373a compressed data stream. 1374 1375=head2 Example 1376 1377Here is an example of using B<bzinflate>. 1378 1379 use strict ; 1380 use warnings ; 1381 1382 use Compress::Bzip2; 1383 1384 my $x = bzinflateInit() 1385 or die "Cannot create a inflation stream\n" ; 1386 1387 my $input = '' ; 1388 binmode STDIN; 1389 binmode STDOUT; 1390 1391 my ($output, $status) ; 1392 while (read(STDIN, $input, 4096)) 1393 { 1394 ($output, $status) = $x->bzinflate(\$input) ; 1395 1396 print $output 1397 if $status == BZ_OK or $status == BZ_STREAM_END ; 1398 1399 last if $status != BZ_OK ; 1400 } 1401 1402 die "inflation failed\n" 1403 unless $status == BZ_STREAM_END ; 1404 1405=head1 EXAMPLES 1406 1407Here are some example scripts of using the interface. 1408 1409=head2 B<A bzcat function> 1410 1411 use strict ; 1412 use warnings ; 1413 1414 use Compress::Bzip2 ; 1415 1416 die "Usage: bzcat file...\n" unless @ARGV ; 1417 1418 my $file ; 1419 1420 foreach $file (@ARGV) { 1421 my $buffer ; 1422 1423 my $bz = bzopen($file, "rb") 1424 or die "Cannot open $file: $bzerrno\n" ; 1425 1426 print $buffer while $bz->bzread($buffer) > 0 ; 1427 1428 die "Error reading from $file: $bzerrno" . ($bzerrno+0) . "\n" 1429 if $bzerrno != BZ_STREAM_END ; 1430 1431 $bz->bzclose() ; 1432 } 1433 1434=head2 B<A grep using bzreadline> 1435 1436 use strict ; 1437 use warnings ; 1438 1439 use Compress::Bzip2 ; 1440 1441 die "Usage: bzgrep pattern file...\n" unless @ARGV >= 2; 1442 1443 my $pattern = shift ; 1444 1445 my $file ; 1446 1447 foreach $file (@ARGV) { 1448 my $bz = bzopen($file, "rb") 1449 or die "Cannot open $file: $bzerrno\n" ; 1450 1451 while ($bz->bzreadline($_) > 0) { 1452 print if /$pattern/ ; 1453 } 1454 1455 die "Error reading from $file: $bzerrno\n" 1456 if $bzerrno != Z_STREAM_END ; 1457 1458 $bz->bzclose() ; 1459 } 1460 1461=head2 B<Streaming Compression> 1462 1463This script, I<bzstream>, does the opposite of the I<bzcat> script 1464above. It reads from standard input and writes a bzip file to standard 1465output. 1466 1467 use strict ; 1468 use warnings ; 1469 1470 use Compress::Bzip2 ; 1471 1472 binmode STDOUT; # bzopen only sets it on the fd 1473 1474 my $bz = bzopen(\*STDOUT, "wb") 1475 or die "Cannot open stdout: $bzerrno\n" ; 1476 1477 while (<>) { 1478 $bz->bzwrite($_) or die "error writing: $bzerrno\n" ; 1479 } 1480 1481 $bz->bzclose ; 1482 1483=head1 EXPORT 1484 1485Use the tags :all, :utilities, :constants, :bzip1 and :gzip. 1486 1487=head2 Export tag :all 1488 1489This exports all the exportable methods. 1490 1491=head2 Export tag :constants 1492 1493This exports only the BZ_* constants. 1494 1495=head2 Export tag :bzip1 1496 1497This exports the Compress::Bzip2 1.x functions, for compatibility. 1498 1499 compress 1500 decompress 1501 compress_init 1502 decompress_init 1503 version 1504 1505These are actually aliases to memBzip and memBunzip. 1506 1507=head2 Export tag :utilities 1508 1509This gives an interface to the bzip2 methods. 1510 1511 bzopen 1512 bzinflateInit 1513 bzdeflateInit 1514 memBzip 1515 memBunzip 1516 bzip2 1517 bunzip2 1518 bzcat 1519 bzlibversion 1520 $bzerrno 1521 1522=head2 Export tag :gzip 1523 1524This gives compatibility with Compress::Zlib. 1525 1526 gzopen 1527 gzinflateInit 1528 gzdeflateInit 1529 memGzip 1530 memGunzip 1531 $gzerrno 1532 1533=head1 Exportable constants 1534 1535All the I<bzlib> constants are automatically imported when you make use 1536of I<Compress::Bzip2>. 1537 1538 BZ_CONFIG_ERROR 1539 BZ_DATA_ERROR 1540 BZ_DATA_ERROR_MAGIC 1541 BZ_FINISH 1542 BZ_FINISH_OK 1543 BZ_FLUSH 1544 BZ_FLUSH_OK 1545 BZ_IO_ERROR 1546 BZ_MAX_UNUSED 1547 BZ_MEM_ERROR 1548 BZ_OK 1549 BZ_OUTBUFF_FULL 1550 BZ_PARAM_ERROR 1551 BZ_RUN 1552 BZ_RUN_OK 1553 BZ_SEQUENCE_ERROR 1554 BZ_STREAM_END 1555 BZ_UNEXPECTED_EOF 1556 1557=head1 SEE ALSO 1558 1559The documentation for zlib, bzip2 and Compress::Zlib. 1560 1561=head1 AUTHOR 1562 1563Rob Janes, E<lt>arjay at cpan.orgE<gt> 1564 1565=head1 COPYRIGHT AND LICENSE 1566 1567Copyright (C) 2005 by Rob Janes 1568 1569This library is free software; you can redistribute it and/or modify 1570it under the same terms as Perl itself, either Perl version 5.8.3 or, 1571at your option, any later version of Perl 5 you may have available. 1572 1573=head1 AUTHOR 1574 1575The I<Compress::Bzip2> module was originally written by Gawdi Azem 1576F<azemgi@rupert.informatik.uni-stuttgart.de>. 1577 1578The first I<Compress::Bzip2> module was written by Gawdi Azem 1579F<azemgi@rupert.informatik.uni-stuttgart.de>. It provided an 1580interface to the in memory inflate and deflate routines. 1581 1582I<Compress::Bzip2> was subsequently passed on to Marco Carnut 1583F<kiko@tempest.com.br> who shepherded it through to version 1.03, a 1584set of changes which included upgrades to handle bzlib 1.0.2, and 1585improvements to the in memory inflate and deflate routines. The 1586streaming interface and error information were added by David Robins 1587F<dbrobins@davidrobins.net>. 1588 1589Version 2 of I<Compress::Bzip2> is due to Rob Janes, of 1590arjay@cpan.org. This release is intended to give an interface 1591close to that of Compress::Zlib. It's development forks from 1.00, 1592not 1.03, so the streaming interface is not the same as that in 1.03, 1593although apparently compatible as it passes the 1.03 test suite. 1594 1595Minor subsequent fixes and releases were done by Reini Urban, 1596rurban@cpan.org. 1597 1598=head1 MODIFICATION HISTORY 1599 1600See the Changes file. 1601 16022.00 Second public release of I<Compress::Bzip2>. 1603 1604