CakeFest 2024: The Official CakePHP Conference

bzread

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

bzreadBzip2 dosyasını ikil olarak okur

Açıklama

bzread(resource $bz, int $uzunluk = 1024): string|false

bzread(), bzip2 dosya tanıtıcısı verilen dosyayı okur.

Sıkıştırıması açılmış veri belirtilen uzunluk baytlık uzunluğa eriştiği zaman veya dosya sonuna varıldığı zaman okuma işlemi sona erer. Bir kerede en fazla 8192 sıkıştırılmamış bayt okunur.

Bağımsız Değişkenler

bz

Dosya tanıtıcısı. Geçerli ve bzopen() işlevi tarafından açılmış bir dosyayı göstermelidir.

uzunluk

Eğer belirtilmemişse, bzread() her seferinde 1024 baytlık sıkıştırması açılmış veri okuyacaktır.

Dönen Değerler

Sıkıştırması açılmış veriyi veya hata durumunda false döndürür.

Örnekler

Örnek 1 - bzread() örneği

<?php

$dosya
= '/tmp/foo.bz2';
$bz = bzopen($dosya, 'r') or die("Belirtilen $dosya dosyası açılamadı.");

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

echo
"Belirtilen dosya $dosya içeriği: <br />\n";
echo
$acilmis_icerik;

?>

Ayrıca Bakınız

  • bzwrite() - Bzip2 dosyasını ikil olarak yazar
  • feof() - Bir dosya tanıtıcısı üzerinde konum dosya sonunda mı diye bakar
  • bzopen() - Bzip2 sıkıştırmalı bir dosyayı açar

add a note

User Contributed Notes 2 notes

up
3
user@anonymous
11 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