PHP 8.1.28 Released!

bzread

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

bzreadEsegue la lettura binaria di un file bzip2

Descrizione

bzread(resource $bz, int $lunghezza = ?): string

bzread() legge fino a lunghezza byte dal puntatore bzip2 specificato da bz. La pettura termina quando lunghezza byte (decompressi) sono stati letti o quando viene raggiunto l'EOF. Se il parametro opzionale lunghezza è omesso, bzread() leggerà 1024 byte (decompressi) ogni volta.

Example #1 Esempio di bzread()

<?php

$file
= "/tmp/foo.bz2";
$bz = bzopen($file, "r") or die("Non ho potuto aprire $file");

$File_decompresso = '';
while (!
feof($bz)) {
$file_decompresso .= bzread($bz, 4096);
}
bzclose($bz);

echo
"Il contenuto di $file è: <br />\n";
echo
$file_decompresso;

?>

Vedere anche bzwrite(), feof() e bzopen().

add a note

User Contributed Notes 2 notes

up
3
user@anonymous
12 years ago
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);
up
2
Anonymous
8 years ago
The earlier posted code has a small bug in it: it uses bzerror instead of bzerrno. Should be like this:

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