Compress-Bzip2
view release on metacpan or search on metacpan
lib/Compress/Bzip2.pm view on Meta::CPAN
=head2 B<$byteswritten = $bz-E<gt>bzwrite($buffer [, $limit]) ;>
Writes the contents of B<$buffer> to the compressed file. Returns the
number of bytes actually written, or 0 on error.
If $limit is given and non-zero, then only that many bytes from
$buffer will be written.
=head2 B<$status = $bz-E<gt>bzflush($flush) ;>
Flushes all pending output to the compressed file.
Works identically to the I<zlib> function it interfaces to. Note that
the use of B<bzflush> can degrade compression.
Returns C<BZ_OK> if B<$flush> is C<BZ_FINISH> and all output could be
flushed. Otherwise the bzlib error code is returned.
Refer to the I<bzlib> documentation for the valid values of B<$flush>.
=head2 B<$status = $bz-E<gt>bzeof() ;>
Returns 1 if the end of file has been detected while reading the input
file, otherwise returns 0.
=head2 B<$bz-E<gt>bzclose>
Closes the compressed file. Any pending data is flushed to the file
before it is closed.
=head2 B<$bz-E<gt>bzsetparams( [PARAMS] );>
Change settings for the deflate stream C<$bz>.
The list of the valid options is shown below. Options not specified
will remain unchanged.
=over 5
=item B<-verbosity>
Defines the verbosity level. Valid values are 0 through 4,
The default is C<-verbosity =E<gt> 0>.
=item B<-blockSize100k>
For bzip object opened for stream deflation or write.
Defines the buffering factor of compression method. The algorithm
buffers all data until the buffer is full, then it flushes all the
data out. Use -blockSize100k to specify the size of the buffer.
Valid settings are 1 through 9, representing a blocking in multiples
of 100k.
Note that each such block has an overhead of leading and trailing
synchronization bytes. bzip2 recovery uses this information to
pull useable data out of a corrupted file.
A streaming application would probably want to set the blocking low.
=item B<-workFactor>
For bzip object opened for stream deflation or write.
The workFactor setting tells the deflation algorithm how much work
to invest to compensate for repetitive data.
workFactor may be a number from 0 to 250 inclusive. The default setting
is 30.
See the bzip documentation for more information.
=item B<-small>
For bzip object opened for stream inflation or read.
B<small> may be 0 or 1. Set C<small> to one to use a slower, less
memory intensive algorithm.
=back
=head2 B<$bz-E<gt>bzerror>
Returns the I<bzlib> error message or number for the last operation
associated with B<$bz>. The return value will be the I<bzlib> error
number when used in a numeric context and the I<bzlib> error message
when used in a string context. The I<bzlib> error number constants,
shown below, are available for use.
BZ_CONFIG_ERROR
BZ_DATA_ERROR
BZ_DATA_ERROR_MAGIC
BZ_FINISH
BZ_FINISH_OK
BZ_FLUSH
BZ_FLUSH_OK
BZ_IO_ERROR
BZ_MAX_UNUSED
BZ_MEM_ERROR
BZ_OK
BZ_OUTBUFF_FULL
BZ_PARAM_ERROR
BZ_RUN
BZ_RUN_OK
BZ_SEQUENCE_ERROR
BZ_STREAM_END
BZ_UNEXPECTED_EOF
=head2 B<$bz-E<gt>bzclearerr>
=head2 B<$bzerrno>
The B<$bzerrno> scalar holds the error code associated with the most
recent I<bzip2> routine. Note that unlike B<bzerror()>, the error is
I<not> associated with a particular file.
As with B<bzerror()> it returns an error number in numeric context and
an error message in string context. Unlike B<bzerror()> though, the
error message will correspond to the I<bzlib> message when the error is
associated with I<bzlib> itself, or the UNIX error message when it is
not (i.e. I<bzlib> returned C<Z_ERRORNO>).
As there is an overlap between the error numbers used by I<bzlib> and
UNIX, B<$bzerrno> should only be used to check for the presence of
I<an> error in numeric context. Use B<bzerror()> to check for specific
I<bzlib> errors. The I<bzcat> example below shows how the variable can
be used safely.
=head2 B<$bz-E<gt>prefix>
Returns the additional 5 byte header which is prepended to the bzip2
header starting with C<BZh> when using memBzip/compress.
=head1 Compress::Bzip2 Utilities
Options: -d -c -z -f -v -k -s -1..9
=head2 bzip2( [OPTS], filename)
=head2 bunzip2(filename)
=head2 bzcat(filenames...)
=head2 bzlibversion()
=head2 bzinflateInit( opts... )
=head1 Internal Utilties
=head2 bz_seterror(errno, msg)
=head2 $bz-E<gt>is_read()
=head2 $bz-E<gt>is_stream()
=head2 $bz-E<gt>is_write()
=head2 $bz-E<gt>total_in()
=head2 $bz-E<gt>total_out()
=head2 version()
=head1 Compress::Bzip2 1.03 COMPATIBILITY
While the 2.x thread forked off of 1.00, another line of development
came to a head at 1.03. The 1.03 version worked with bzlib 1.0.2, had
improvements to the error handling, single buffer inflate/deflate, a
streaming interface to inflate/deflate, and a cpan style test suite.
=head2 B<$dest = compress( $string, [$level] )>
Alias to L<memBzip>, this compresses string, using the optional
compression level, 1 through 9, the default being 6. Returns a string
containing the compressed data.
On error I<undef> is returned.
=head2 B<$dest = decompress($string, [$level])>
Alias to L<memBunzip>, this decompresses the data in string, returning a
string containing the decompressed data.
On error I<undef> is returned.
=head2 uncompress($string, [$level])
Another alias to L<memBunzip>
=head2 B<$stream = compress_init( [PARAMS] )>
Alias to bzdeflateInit. In addition to the named parameters
documented for bzdeflateInit, the following are accepted:
-level, alias to -blockSize100k
-buffer, to set the buffer size.
The -buffer option is ignored. The intermediate buffer size is not
changeable.
=head2 B<$stream = decompress_init( [PARAMS] )>
Alias to bzinflateInit. See bzinflateInit for a description of the parameters.
The option "-buffer" is accepted, but ignored.
=head2 B<$output = $stream-E<gt>add( $string )>
Add data to be compressed/decompressed. Returns whatever output is available
(possibly none, if it's still buffering it), or undef on error.
=head2 B<$output = $stream-E<gt>finish( [$string] )>
Finish the operation; takes an optional final data string. Whatever is
returned completes the output; returns undef on error.
=head2 B<$stream-E<gt>error>
Like the function, but applies to the current object only. Note that errors
in a stream object are also returned by the function.
=head2 B<$stream-E<gt>input_size>
Alias to total_in. Total bytes passed to the stream.
=head2 B<$stream-E<gt>output_size>
Alias to total_out. Total bytes received from the stream.
=head1 GZIP COMPATIBILITY INTERFACE
lib/Compress/Bzip2.pm view on Meta::CPAN
Essentially, an in-memory bzip file is created. It creates a minimal
bzip header, which adds 5 bytes before the bzip2 specific BZh header.
=head2 B<$uncompressed = memBunzip($buffer);>
Uncompresses B<$buffer>. If successful it returns the uncompressed
data. Otherwise it returns I<undef>.
The source buffer can either be a scalar or a scalar reference.
The buffer parameter can either be a scalar or a scalar reference. The
contents of the buffer parameter are destroyed after calling this
function.
=head1 STREAM DEFLATE (= COMPRESS)
The Perl interface will I<always> consume the complete input buffer
before returning. Also the output buffer returned will be
automatically grown to fit the amount of output available.
Here is a definition of the interface available:
=head2 B<($d, $status) = bzdeflateInit( [PARAMS] )>
Initialises a deflation stream.
If successful, it will return the initialised deflation stream, B<$d>
and B<$status> of C<BZ_OK> in a list context. In scalar context it
returns the deflation stream, B<$d>, only.
If not successful, the returned deflation stream (B<$d>) will be
I<undef> and B<$status> will hold the exact I<bzip2> error code.
The function optionally takes a number of named options specified as
C<-Name=E<gt>value> pairs. This allows individual options to be
tailored without having to specify them all in the parameter list.
Here is a list of the valid options:
=over 5
=item B<-verbosity>
Defines the verbosity level. Valid values are 0 through 4,
The default is C<-verbosity =E<gt> 0>.
=item B<-blockSize100k>
Defines the buffering factor of compression method. The algorithm
buffers all data until the buffer is full, then it flushes all the
data out. Use -blockSize100k to specify the size of the buffer.
Valid settings are 1 through 9, representing a blocking in multiples
of 100k.
Note that each such block has an overhead of leading and trailing
synchronization bytes. bzip2 recovery uses this information to
pull useable data out of a corrupted file.
A streaming application would probably want to set the blocking low.
=item B<-workFactor>
The workFactor setting tells the deflation algorithm how much work
to invest to compensate for repetitive data.
workFactor may be a number from 0 to 250 inclusive. The default setting
is 30.
See the bzip documentation for more information.
=back
Here is an example of using the B<deflateInit> optional parameter list
to override the default buffer size and compression level. All other
options will take their default values.
bzdeflateInit( -blockSize100k => 1, -verbosity => 1 );
=head2 B<($out, $status) = $d-E<gt>bzdeflate($buffer)>
Deflates the contents of B<$buffer>. The buffer can either be a scalar
or a scalar reference. When finished, B<$buffer> will be
completely processed (assuming there were no errors). If the deflation
was successful it returns deflated output, B<$out>, and a status
value, B<$status>, of C<Z_OK>.
On error, B<$out> will be I<undef> and B<$status> will contain the
I<zlib> error code.
In a scalar context B<bzdeflate> will return B<$out> only.
As with the internal buffering of the I<deflate> function in I<bzip2>,
it is not necessarily the case that any output will be produced by
this method. So don't rely on the fact that B<$out> is empty for an
error test. In fact, given the size of bzdeflates internal buffer,
with most files it's likely you won't see any output at all until
flush or close.
=head2 B<($out, $status) = $d-E<gt>bzflush([flush_type])>
Typically used to finish the deflation. Any pending output will be
returned via B<$out>. B<$status> will have a value C<BZ_OK> if
successful.
In a scalar context B<bzflush> will return B<$out> only.
Note that flushing can seriously degrade the compression ratio, so it
should only be used to terminate a decompression (using C<BZ_FLUSH>) or
when you want to create a I<full flush point> (using C<BZ_FINISH>).
The allowable values for C<flush_type> are C<BZ_FLUSH> and C<BZ_FINISH>.
For a handle opened for "w" (bzwrite), the default is C<BZ_FLUSH>.
For a stream, the default for C<flush_type> is C<BZ_FINISH> (which is
essentially a close and reopen).
It is strongly recommended that you only set the C<flush_type>
parameter if you fully understand the implications of what it
does. See the C<bzip2> documentation for details.
lib/Compress/Bzip2.pm view on Meta::CPAN
gzopen
gzinflateInit
gzdeflateInit
memGzip
memGunzip
$gzerrno
=head1 Exportable constants
All the I<bzlib> constants are automatically imported when you make use
of I<Compress::Bzip2>.
BZ_CONFIG_ERROR
BZ_DATA_ERROR
BZ_DATA_ERROR_MAGIC
BZ_FINISH
BZ_FINISH_OK
BZ_FLUSH
BZ_FLUSH_OK
BZ_IO_ERROR
BZ_MAX_UNUSED
BZ_MEM_ERROR
BZ_OK
BZ_OUTBUFF_FULL
BZ_PARAM_ERROR
BZ_RUN
BZ_RUN_OK
BZ_SEQUENCE_ERROR
BZ_STREAM_END
BZ_UNEXPECTED_EOF
=head1 SEE ALSO
The documentation for zlib, bzip2 and Compress::Zlib.
=head1 AUTHOR
Rob Janes, E<lt>arjay at cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2005 by Rob Janes
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
=head1 AUTHOR
The I<Compress::Bzip2> module was originally written by Gawdi Azem
F<azemgi@rupert.informatik.uni-stuttgart.de>.
The first I<Compress::Bzip2> module was written by Gawdi Azem
F<azemgi@rupert.informatik.uni-stuttgart.de>. It provided an
interface to the in memory inflate and deflate routines.
I<Compress::Bzip2> was subsequently passed on to Marco Carnut
F<kiko@tempest.com.br> who shepherded it through to version 1.03, a
set of changes which included upgrades to handle bzlib 1.0.2, and
improvements to the in memory inflate and deflate routines. The
streaming interface and error information were added by David Robins
F<dbrobins@davidrobins.net>.
Version 2 of I<Compress::Bzip2> is due to Rob Janes, of
arjay@cpan.org. This release is intended to give an interface
close to that of Compress::Zlib. It's development forks from 1.00,
not 1.03, so the streaming interface is not the same as that in 1.03,
although apparently compatible as it passes the 1.03 test suite.
Minor subsequent fixes and releases were done by Reini Urban,
rurban@cpan.org.
=head1 MODIFICATION HISTORY
See the Changes file.
2.00 Second public release of I<Compress::Bzip2>.
( run in 1.217 second using v1.01-cache-2.11-cpan-140bd7fdf52 )