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, 18 Sep 2009

view this page in

bzread

(PHP 4 >= 4.0.4, PHP 5)

bzreadBinary safe bzip2 file read

Описание

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

bzread() reads from the given bzip2 file pointer.

Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first.

Параметри

bz

The file pointer. It must be valid and must point to a file successfully opened by bzopen().

length

If not specified, bzread() will read 1024 (uncompressed) bytes at a time.

Връщани стойности

Returns the uncompressed data, or FALSE on error.

Примери

Example #1 bzread() example

<?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() - Binary safe bzip2 file write
  • feof() - Проверява дали указателят е в края на файла
  • bzopen() - Opens a bzip2 compressed file



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 | stats | sitemap | contact | advertising | mirror sites