PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

gztell> <gzrewind
Last updated: Fri, 22 Aug 2008

view this page in

gzseek

(PHP 4, PHP 5)

gzseekMove o ponteiro de um arquivo-gz

Descrição

int gzseek ( resource $zp , int $offset )

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



add a note add a note User Contributed Notes
gzseek
dperham at wgate dot com
12-Apr-2005 05:47
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;
}

gztell> <gzrewind
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites