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.
(PHP 4, PHP 5, PHP 7, PHP 8)
gzseek — Move o ponteiro de um arquivo-gz
$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.
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.
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.
Exemplo #1 Exemplo da gzseek()
<?php
$gz = gzopen('somefile.gz', 'r');
gzseek($gz,2);
echo gzgetc($gz);
gzclose($gz);
?>
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.
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;
}