Since seek after the end is not considered an error, I doubt that "while (gzseek ($fh, $eof) == 0) $eof += $d;" will get into infinite loop.
gzseek
(PHP 4, PHP 5)
gzseek — Gzipli dosya göstericisini konumlar
Açıklama
$dt
, int $konum
[, int $nereye = SEEK_SET
] )Belirtilen dosya tanıtıcısında dosya göstericisini belirtilen konuma taşır. gzseek(dt, konum, SEEK_SET) C çağrısına eşdeğerdir.
Dosya okumak için açılmışsa bu işlev yine de taklit edilir ama işlem oldukça yavaşlar. Dosya yazmak için açılmışsa sadece ileri yönde konumlamalar desteklenir; gzseek() konumlamanın ardından yeni konuma kadar olan bölgeyi sıfırlarla doldurur.
Değiştirgeler
-
dt -
Gzipli dosya tanıtıcısı. gzopen() tarafından açılmış bir dosyayı gösteren geçerli bir tanıtıcı olmalıdır.
-
konum -
Göstericinin götürüleceği konum.
-
nereye -
Olası
nereyedeğerleri:SEEK_SET- Gösterici, tamkonumuncu bayta yerleştirilir.SEEK_CUR- Gösterici, mevcut konum artıkonumuncu bayta yerleştirilir.
nereyedeğiştirgesi belirtilmezseSEEK_SETbelirtilmiş gibi işlem yapılır.
Dönen Değerler
Başarı durumunda 0, aksi takdirde -1 döner. Dosya sonunun sonrasına yapılan bir konumlama bir hata olarak değerlendirilmez.
Örnekler
Örnek 1 - gzseek() örneği
<?php
$gz = gzopen('birdosya.gz', 'r');
gzseek($gz,2);
echo gzgetc($gz);
gzclose($gz);
?>
Ayrıca Bakınız
- gztell() - Gzipli dosya tanıtıcısının okuma/yazma konumunu döndürür
- gzrewind() - Gzipli dosya göstericisini dosya başlangıcına taşır
PHP/4.3.9
contrary to the notes, gzseek() returns -1 if I try to seek past the end of the file. here is a function that will return the last seekable position, and put the file pointer there.
/** sets the file pointer at the end of the file
* and returns the number of bytes in the file.
*/
function gzend($fh)
{
$d = 1<<14;
$eof = $d;
while ( gzseek($fh, $eof) == 0 ) $eof += $d;
while ( $d > 1 )
{
$d >>= 1;
$eof += $d * (gzseek($fh, $eof)? -1 : 1);
}
return $eof;
}
