PHP 8.3.4 Released!

gzseek

(PHP 4, PHP 5, PHP 7, PHP 8)

gzseekGzipli dosya göstericisini konumlar

Açıklama

gzseek(resource $dt, int $konum, int $nereye = SEEK_SET): int

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.

Bağımsız Değişkenler

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ı nereye değerleri:

  • SEEK_SET - Gösterici, tam konumuncu bayta yerleştirilir.
  • SEEK_CUR - Gösterici, mevcut konum artı konumuncu bayta yerleştirilir.

nereye bağımsız değişkeni belirtilmezse SEEK_SET belirtilmiş 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

add a note

User Contributed Notes 2 notes

up
0
liuhaifeng at example dot com
11 years ago
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.
up
0
dperham at wgate dot com
18 years ago
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;
}
To Top