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;
}
gzseek
(PHP 4, PHP 5)
gzseek — Busca en el archivo gz apuntado
Descripción
Establece el indicador de posición del archivo para el apuntador de archivo. Equivalente a ejecutar (en C) gzseek(zp, offset, SEEK_SET).
Si el archivo es abierto para lectura, esta función es emulada pero puede ser extremadamente lenta. Si el archivo es abierto para escritura, solo se soportan b´squedas hacia adelante; gzseek() entonces comprime una secuencia de ceros hasta la nueva posición.
Lista de parámetros
- zp
-
El apuntador de archivo gz. Debe ser válido, y debe apuntar a un archivo exitosamente abierto por gzopen().
- offset
-
La posición a buscar.
Valores retornados
En caso de éxito, regresa 0; de otro modo, regresa -1. Note que si se pasa del fin del archivo no es considerado un error.
Ejemplos
Example #1 Ejemplo de gzseek()
<?php
$gz = gzopen('somefile.gz', 'r');
gzseek($gz,2);
echo gzgetc($gz);
gzclose($gz);
?>
gzseek
12-Apr-2005 08:47
