IX. Bzip2 壓縮函數

簡介

Bzip2 函數用來透明的讀寫 bzip2(.bz2)壓縮檔。

需求

本模組使用 Julian Seward 寫的 bzip2 庫。此模組需要 bzip2/libbzip2 版本 >= 1.0.x。

安裝

PHP 的 bzip2 支援預設未開啟。編譯 PHP 時需要 --with-bz2[=DIR] 配置選項來啟動 bzip2 支援。

運行時配置

本增加模組在 php.ini 中未定義任何配置選項。

資源類型

本增加定義了一種資源類型:一個檔案指標,指向正在被動作的 bz2 檔案。

預定義常量

本增加模組未定義任何常量。

範例

該例子開啟一暫存檔案,並寫入一測試字串,然後列印檔案內容。

例子 1. Bzip2 例子

<?php

$filename 
"/tmp/testfile.bz2";
$str "This is a test string.\n";

// 以寫入模式開啟檔案
$bz bzopen($filename"w");

// 寫入字串到檔案
bzwrite($bz$str);

// 關閉檔案
bzclose($bz);

// 以讀取模式開啟檔案
$bz bzopen($filename"r");

// 讀取 10 個字元
echo bzread($bz10);

// 輸出直到檔案結尾(或後續的 1024 位元組)並關閉它。
echo bzread($bz);

bzclose($bz);

?>
目錄
bzclose -- Close a bzip2 file
bzcompress -- Compress a string into bzip2 encoded data
bzdecompress -- Decompresses bzip2 encoded data
bzerrno -- Returns a bzip2 error number
bzerror --  Returns the bzip2 error number and error string in an array
bzerrstr -- Returns a bzip2 error string
bzflush -- Force a write of all buffered data
bzopen -- Opens a bzip2 compressed file
bzread -- Binary safe bzip2 file read
bzwrite -- Binary safe bzip2 file write