(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
bzread — Lectura binaria de un archivo bzip2
bzread() lee desde el puntero de archivo bzip2 dado.
La lectura se detiene cuando length (no comprimido)
caracteres han sido leídos o si se alcanza el final del archivo, el primero de los dos que
ocurra.
bzlength
Devuelve los datos no comprimidos o false si ocurre un error.
Ejemplo #1 Ejemplo con bzread()
<?php
$file = "/tmp/foo.bz2";
$bz = bzopen($file, "r") or die("Imposible abrir el archivo $file");
$decompressed_file = '';
while (!feof($bz)) {
$decompressed_file .= bzread($bz, 4096);
}
bzclose($bz);
echo "El contenido del archivo $file es : <br />\n";
echo $decompressed_file;
?>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);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);