Movatterモバイル変換


[0]ホーム

URL:


Compress::Raw::Bzip2
(source,CPAN)
version 2.074
You are viewing the version of this documentation from Perl 5.26.3.View the latest version

CONTENTS

#NAME

Compress::Raw::Bzip2 - Low-Level Interface to bzip2 compression library

#SYNOPSIS

use Compress::Raw::Bzip2 ;my ($bz, $status) = new Compress::Raw::Bzip2 [OPTS]    or die "Cannot create bzip2 object: $bzerno\n";$status = $bz->bzdeflate($input, $output);$status = $bz->bzflush($output);$status = $bz->bzclose($output);my ($bz, $status) = new Compress::Raw::Bunzip2 [OPTS]    or die "Cannot create bunzip2 object: $bzerno\n";$status = $bz->bzinflate($input, $output);my $version = Compress::Raw::Bzip2::bzlibversion();

#DESCRIPTION

Compress::Raw::Bzip2 provides an interface to the in-memory compression/uncompression functions from the bzip2 compression library.

Although the primary purpose for the existence ofCompress::Raw::Bzip2 is for use by theIO::Compress::Bzip2 andIO::Compress::Bunzip2 modules, it can be used on its own for simple compression/uncompression tasks.

#Compression

#($z, $status) = new Compress::Raw::Bzip2 $appendOutput, $blockSize100k, $workfactor;

Creates a new compression object.

If successful, it will return the initialised compression object,$z and a$status ofBZ_OK in a list context. In scalar context it returns the deflation object,$z, only.

If not successful, the returned compression object,$z, will beundef and$status will hold the abzip2 error code.

Below is a list of the valid options:

#$appendOutput

Controls whether the compressed data is appended to the output buffer in thebzdeflate,bzflush andbzclose methods.

Defaults to 1.

#$blockSize100k

To quote the bzip2 documentation

blockSize100k specifies the block size to be used for compression. Itshould be a value between 1 and 9 inclusive, and the actual block sizeused is 100000 x this figure. 9 gives the best compression but takesmost memory.

Defaults to 1.

#$workfactor

To quote the bzip2 documentation

This parameter controls how the compression phase behaves whenpresented with worst case, highly repetitive, input data. Ifcompression runs into difficulties caused by repetitive data, thelibrary switches from the standard sorting algorithm to a fallbackalgorithm. The fallback is slower than the standard algorithm byperhaps a factor of three, but always behaves reasonably, no matter howbad the input.Lower values of workFactor reduce the amount of effort the standardalgorithm will expend before resorting to the fallback. You should setthis parameter carefully; too low, and many inputs will be handled bythe fallback algorithm and so compress rather slowly, too high, andyour average-to-worst case compression times can become very large. Thedefault value of 30 gives reasonable behaviour over a wide range ofcircumstances.Allowable values range from 0 to 250 inclusive. 0 is a special case,equivalent to using the default value of 30.

Defaults to 0.

#$status = $bz->bzdeflate($input, $output);

Reads the contents of$input, compresses it and writes the compressed data to$output.

ReturnsBZ_RUN_OK on success and abzip2 error code on failure.

IfappendOutput is enabled in the constructor for the bzip2 object, the compressed data will be appended to$output. If not enabled,$output will be truncated before the compressed data is written to it.

#$status = $bz->bzflush($output);

Flushes any pending compressed data to$output.

ReturnsBZ_RUN_OK on success and abzip2 error code on failure.

#$status = $bz->bzclose($output);

Terminates the compressed data stream and flushes any pending compressed data to$output.

ReturnsBZ_STREAM_END on success and abzip2 error code on failure.

#Example

#Uncompression

#($z, $status) = new Compress::Raw::Bunzip2 $appendOutput, $consumeInput, $small, $verbosity, $limitOutput;

If successful, it will return the initialised uncompression object,$z and a$status ofBZ_OK in a list context. In scalar context it returns the deflation object,$z, only.

If not successful, the returned uncompression object,$z, will beundef and$status will hold the abzip2 error code.

Below is a list of the valid options:

#$appendOutput

Controls whether the compressed data is appended to the output buffer in thebzinflate,bzflush andbzclose methods.

Defaults to 1.

#$consumeInput
#$small

To quote the bzip2 documentation

If small is nonzero, the library will use an alternative decompressionalgorithm which uses less memory but at the cost of decompressing moreslowly (roughly speaking, half the speed, but the maximum memoryrequirement drops to around 2300k).

Defaults to 0.

#$limitOutput

TheLimitOutput option changes the behavior of the$i->bzinflate method so that the amount of memory used by the output buffer can be limited.

WhenLimitOutput is used the size of the output buffer used will either be the 16k or the amount of memory already allocated to$output, whichever is larger. Predicting the output size available is tricky, so don't rely on getting an exact output buffer size.

WhenLimitOutout is not specified$i->bzinflate will use as much memory as it takes to write all the uncompressed data it creates by uncompressing the input buffer.

IfLimitOutput is enabled, theConsumeInput option will also be enabled.

This option defaults to false.

#$verbosity

This parameter is ignored.

Defaults to 0.

#$status = $z->bzinflate($input, $output);

Uncompresses$input and writes the uncompressed data to$output.

ReturnsBZ_OK if the uncompression was successful, but the end of the compressed data stream has not been reached. ReturnsBZ_STREAM_END on successful uncompression and the end of the compression stream has been reached.

IfconsumeInput is enabled in the constructor for the bunzip2 object,$input will have all compressed data removed from it after uncompression. OnBZ_OK return this will mean that$input will be an empty string; whenBZ_STREAM_END$input will either be an empty string or will contain whatever data immediately followed the compressed data stream.

IfappendOutput is enabled in the constructor for the bunzip2 object, the uncompressed data will be appended to$output. If not enabled,$output will be truncated before the uncompressed data is written to it.

#Misc

#my $version = Compress::Raw::Bzip2::bzlibversion();

Returns the version of the underlying bzip2 library.

#Constants

The following bzip2 constants are exported by this module

BZ_RUNBZ_FLUSHBZ_FINISHBZ_OKBZ_RUN_OKBZ_FLUSH_OKBZ_FINISH_OKBZ_STREAM_ENDBZ_SEQUENCE_ERRORBZ_PARAM_ERRORBZ_MEM_ERRORBZ_DATA_ERRORBZ_DATA_ERROR_MAGICBZ_IO_ERRORBZ_UNEXPECTED_EOFBZ_OUTBUFF_FULLBZ_CONFIG_ERROR

#SEE ALSO

Compress::Zlib,IO::Compress::Gzip,IO::Uncompress::Gunzip,IO::Compress::Deflate,IO::Uncompress::Inflate,IO::Compress::RawDeflate,IO::Uncompress::RawInflate,IO::Compress::Bzip2,IO::Uncompress::Bunzip2,IO::Compress::Lzma,IO::Uncompress::UnLzma,IO::Compress::Xz,IO::Uncompress::UnXz,IO::Compress::Lzop,IO::Uncompress::UnLzop,IO::Compress::Lzf,IO::Uncompress::UnLzf,IO::Uncompress::AnyInflate,IO::Uncompress::AnyUncompress

IO::Compress::FAQ

File::GlobMapper,Archive::Zip,Archive::Tar,IO::Zlib

The primary site for the bzip2 program ishttp://www.bzip.org.

See the moduleCompress::Bzip2

#AUTHOR

This module was written by Paul Marquess,pmqs@cpan.org.

#MODIFICATION HISTORY

See the Changes file.

#COPYRIGHT AND LICENSE

Copyright (c) 2005-2017 Paul Marquess. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp