gzseek

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

gzseekMove o ponteiro de um arquivo-gz

Descrição

gzseek ( resource $zp , int $offset ) : int

Define a posição do indicador do dado ponteiro de arquivo para a dada posição do byte dentro do arquivo. Equivalente a chamar (em C) gzseek(zp, offset, SEEK_SET).

Se o arquivo esta aberto para leitura, esta função é emulada mas pode ser extremamente lenta. Se o arquivo estiver aberto para escrita, apenas mudanças para a frente são suportadas; gzseek() então comprime uma sequencia de zeros até a nova posição de início.

Parâmetros

zp

O ponteiro de arquivo gz. Ele precisa ser válido, e apontar para um arquivo aberto com sucesso por gzopen().

offset

A posição desejada.

Valor Retornado

Em caso de sucesso, retorna 0; senão retorna -1. Note que mover a posição alem do fim do arquivo não é considerado um erro. past EOF is not considered an error.

Exemplos

Exemplo #1 Exemplo da gzseek()

<?php
$gz 
gzopen('somefile.gz''r');
gzseek($gz,2);
echo 
gzgetc($gz);
gzclose($gz);
?>

Veja Também

  • gztell() - Indica a posição de leitura/gravação em um ponteiro para arquivo-gz
  • gzrewind() - Retorna ao início a posição de um ponteiro para um arquivo-gz

add a note 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
19 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