<?php
/**
* @return bool
* @param string $in
* @param string $out
* @desc compressing the file with the bzip2-extension
*/
function bzip2 ($in, $out)
{
if (!file_exists ($in) || !is_readable ($in))
return false;
if ((!file_exists ($out) && !is_writeable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
return false;
$in_file = fopen ($in, "rb");
$out_file = bzopen ($out, "wb");
while (!feof ($in_file)) {
$buffer = fgets ($in_file, 4096);
bzwrite ($out_file, $buffer, 4096);
}
fclose ($in_file);
bzclose ($out_file);
return true;
}
/**
* @return bool
* @param string $in
* @param string $out
* @desc uncompressing the file with the bzip2-extension
*/
function bunzip2 ($in, $out)
{
if (!file_exists ($in) || !is_readable ($in))
return false;
if ((!file_exists ($out) && !is_writeable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
return false;
$in_file = bzopen ($in, "rb");
$out_file = fopen ($out, "wb");
while ($buffer = bzread ($in_file, 4096)) {
fwrite ($out_file, $buffer, 4096);
}
bzclose ($in_file);
fclose ($out_file);
return true;
}
?>
Bzip2 圧縮関数
導入
bzip2関数は、bzip2 (.bz2)圧縮されたファイルを透過的に読み書きする ために使用されます。
要件
このモジュールは、Julian Seward により作成された » bzip2ライブラリの関数を使用して います。このモジュールは、bzip2/libbzip2の バージョン >= 1.0.xを必要とします。
インストール手順
PHP の bzip2 サポートはデフォルトでは有効となっていません。 bzip2 サポートを有効とするには、PHP をコンパイルする際に設定オプション --with-bz2[=DIR] を使用する必要があります。
実行時設定
設定ディレクティブは定義されていません。
リソース型
この拡張モジュールは、リソース型として処理を行うbz2ファイルを指す ファイルポインタを定義します。
定義済み定数
定数は定義されていません。
例
この例は、テンポラリファイルをオープンし、テスト用の文字列を書き 込みます。この後、このファイルの内容を出力します。
Example#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文字読み込む
print bzread($bz, 10);
// ファイルの終端まで出力(または次の1024文字)し、閉じる
print bzread($bz);
bzclose($bz);
?>
目次
- bzclose — bzip2 ファイルを閉じる
- bzcompress — 文字列をbzip2形式のデータに圧縮する
- bzdecompress — bzip2 形式のデータを解凍する
- bzerrno — bzip2 エラー番号を返す
- bzerror — bzip2 エラー番号とエラー文字列を配列で返す
- bzerrstr — bzip2 エラー文字列を返す
- bzflush — 全てのバッファリングされたデータを強制的に書き込む
- bzopen — bzip2 圧縮されたファイルをオープンする
- bzread — バイナリ対応の bzip2 ファイル読み込み
- bzwrite — バイナリ対応の bzip2 ファイルへの書き込み
Bzip2
ec10 at gmx dot net
21-May-2004 03:34
21-May-2004 03:34