downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

bzwrite> <bzopen
[edit] Last updated: Fri, 25 May 2012

view this page in

bzread

(PHP 4 >= 4.0.4, PHP 5)

bzreadバイナリ対応の bzip2 ファイル読み込み

説明

string bzread ( resource $bz [, int $length = 1024 ] )

bzread() は、与えられた bzip2 ファイルポインタから読み込みます。

読み込みは、(圧縮前の状態で) length バイトが読み込まれたか、EOF に達したかのどちらか最初に来た方で終了します。

パラメータ

bz

ファイルポインタ。これは有効である必要があり、 bzopen() によりオープンされたファイルを指してい る必要があります。

length

指定されない場合、bzread() は一度に (圧縮前の状態で) 1024バイト読み込みます。 最大で 8192 バイト (圧縮前) までを一度に読み込みます。

返り値

非圧縮データ、もしくはエラー時に FALSE を返します。

例1 bzread() の例

<?php

$file 
"/tmp/foo.bz2";
$bz bzopen($file"r") or die("Couldn't open $file");

$decompressed_file '';
while (!
feof($bz)) {
  
$decompressed_file .= bzread($bz4096);
}
bzclose($bz);

echo 
"The contents of $file are: <br />\n";
echo 
$decompressed_file;

?>

参考

  • bzwrite() - バイナリ対応の bzip2 ファイルへの書き込み
  • feof() - ファイルポインタがファイル終端に達しているかどうか調べる
  • bzopen() - bzip2 圧縮されたファイルをオープンする



add a note add a note User Contributed Notes bzread
user@anonymous 15-Apr-2012 07:10
Make sure you check for bzerror while looping through a bzfile. bzread will not detect a compression error and can continue forever even at the cost of 100% cpu.

$fh = bzopen('file.bz2','r');
while(!feof($fh)) {
  $buffer = bzread($fh);
  if($buffer === FALSE) die('Read problem');
  if(bzerror($fh) !== 0) die('Compression Problem');
}
bzclose($fh);

 
show source | credits | sitemap | contact | advertising | mirror sites