目錄

名稱

Compress::Raw::Bzip2 - bzip2 壓縮函式庫的低階介面

語法

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();

說明

Compress::Raw::Bzip2 提供介面存取 bzip2 壓縮函式庫中的記憶體壓縮/解壓縮函式。

儘管 Compress::Raw::Bzip2 存在的首要目的是供 IO::Compress::Bzip2IO::Compress::Bunzip2 模組使用,但它也可以單獨用於簡單的壓縮/解壓縮任務。

壓縮

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

建立新的壓縮物件。

如果成功,它會在清單內容中傳回已初始化的壓縮物件 $z 和狀態 BZ_OK。在純量內容中,它只會傳回壓縮物件 $z

如果沒有成功,傳回的壓縮物件 $z 會是 undef,而 $status 會包含一個 bzip2 錯誤碼。

以下是有效選項的清單

$appendOutput

控制是否在 bzdeflatebzflushbzclose 方法中將壓縮資料附加到輸出緩衝區。

預設為 1。

$blockSize100k

引用 bzip2 文件

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

預設為 1。

$workfactor

引用 bzip2 文件

This parameter controls how the compression phase behaves when
presented with worst case, highly repetitive, input data. If
compression runs into difficulties caused by repetitive data, the
library switches from the standard sorting algorithm to a fallback
algorithm. The fallback is slower than the standard algorithm by
perhaps a factor of three, but always behaves reasonably, no matter how
bad the input.

Lower values of workFactor reduce the amount of effort the standard
algorithm will expend before resorting to the fallback. You should set
this parameter carefully; too low, and many inputs will be handled by
the fallback algorithm and so compress rather slowly, too high, and
your average-to-worst case compression times can become very large. The
default value of 30 gives reasonable behaviour over a wide range of
circumstances.

Allowable values range from 0 to 250 inclusive. 0 is a special case,
equivalent to using the default value of 30.

預設為 0。

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

讀取 $input 的內容,將其壓縮並將壓縮資料寫入 $output

如果成功,傳回 BZ_RUN_OK,如果失敗,傳回 bzip2 錯誤碼。

如果在 bzip2 物件的建構函式中啟用 appendOutput,壓縮資料會附加到 $output。如果未啟用,壓縮資料寫入 $output 之前,$output 會被截斷。

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

將任何待處理的壓縮資料沖刷到 $output

如果成功,傳回 BZ_RUN_OK,如果失敗,傳回 bzip2 錯誤碼。

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

終止壓縮資料串流,並將任何待處理的壓縮資料沖刷到 $output

如果成功,傳回 BZ_STREAM_END,如果失敗,傳回 bzip2 錯誤碼。

範例

解壓縮

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

如果成功,它會在清單內容中傳回已初始化的解壓縮物件 $z 和狀態 BZ_OK。在純量內容中,它只會傳回解壓縮物件 $z

如果沒有成功,傳回的解壓縮物件 $z 會是 undef,而 $status 會包含一個 bzip2 錯誤碼。

以下是有效選項的清單

$appendOutput

控制是否在 bzinflatebzflushbzclose 方法中將壓縮資料附加到輸出緩衝區。

預設為 1。

$consumeInput
$small

引用 bzip2 文件

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

預設為 0。

$limitOutput

LimitOutput 選項會變更 $i->bzinflate 方法的行為,以便限制輸出緩衝區使用的記憶體量。

使用 LimitOutput 時,所使用的輸出緩衝區大小將為 16k 或已配置給 $output 的記憶體量(以較大者為準)。預測可用的輸出大小很棘手,因此不要依賴取得確切的輸出緩衝區大小。

未指定 LimitOutout 時,$i->bzinflate 會使用解壓縮輸入緩衝區所建立的所有未壓縮資料所需的記憶體量。

如果啟用 LimitOutput,也會啟用 ConsumeInput 選項。

此選項預設為 false。

$verbosity

此參數會被忽略。

預設為 0。

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

解壓縮 $input,並將解壓縮的資料寫入 $output

如果解壓縮成功,但尚未到達壓縮資料串流的結尾,則傳回 BZ_OK。在成功解壓縮且已到達壓縮串流的結尾時,傳回 BZ_STREAM_END

如果在 bunzip2 物件的建構函式中啟用 consumeInput,解壓縮後會從 $input 中移除所有壓縮資料。傳回 BZ_OK 時,表示 $input 會是空字串;傳回 BZ_STREAM_END 時,$input 會是空字串,或會包含緊接在壓縮資料串流之後的任何資料。

如果在 bunzip2 物件的建構函式中啟用 appendOutput,解壓縮的資料會附加到 $output。如果未啟用,會在將解壓縮的資料寫入 $output 之前將其截斷。

雜項

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

傳回底層 bzip2 函式庫的版本。

常數

此模組會匯出下列 bzip2 常數

BZ_RUN
BZ_FLUSH
BZ_FINISH

BZ_OK
BZ_RUN_OK
BZ_FLUSH_OK
BZ_FINISH_OK
BZ_STREAM_END
BZ_SEQUENCE_ERROR
BZ_PARAM_ERROR
BZ_MEM_ERROR
BZ_DATA_ERROR
BZ_DATA_ERROR_MAGIC
BZ_IO_ERROR
BZ_UNEXPECTED_EOF
BZ_OUTBUFF_FULL
BZ_CONFIG_ERROR

支援

一般回饋/問題/錯誤報告應傳送至 https://github.com/pmqs/Compress-Raw-Bzip2/issues(建議)或 https://rt.cpan.org/Public/Dist/Display.html?Name=Compress-Raw-Bzip2

另請參閱

Compress::ZlibIO::Compress::GzipIO::Uncompress::GunzipIO::Compress::DeflateIO::Uncompress::InflateIO::Compress::RawDeflateIO::Uncompress::RawInflateIO::Compress::Bzip2IO::Uncompress::Bunzip2IO::Compress::LzmaIO::Uncompress::UnLzmaIO::Compress::XzIO::Uncompress::UnXzIO::Compress::LzipIO::Uncompress::UnLzipIO::Compress::LzopIO::Uncompress::UnLzopIO::Compress::LzfIO::Uncompress::UnLzfIO::Compress::ZstdIO::Uncompress::UnZstdIO::Uncompress::AnyInflateIO::Uncompress::AnyUncompress

IO::Compress::FAQ

File::GlobMapperArchive::ZipArchive::TarIO::Zlib

bzip2 程式的主要網站為 https://sourceware.org/bzip2/

請參閱模組 Compress::Bzip2

作者

此模組由 Paul Marquess 編寫,電子郵件為 pmqs@cpan.org

修改記錄

請參閱變更檔案。

版權和授權

版權所有 (c) 2005-2023 Paul Marquess。保留所有權利。

此程式為自由軟體;您可以在與 Perl 相同的條款下重新散布或修改它。