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);
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 바이트를 읽습니다.
반환값
압축해제된 데이터를 반환하거나, 오류 시엔 FALSE를 반환합니다.
예제
Example #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($bz, 4096);
}
bzclose($bz);
echo "The contents of $file are: <br />\n";
echo $decompressed_file;
?>
user@anonymous
15-Apr-2012 07:10
