gzseek

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

gzseekUbica el apuntador a un archivo gz

Descripción

gzseek(resource $zp, int $offset, int $whence = SEEK_SET): int

Establece el indicador de posición para el apuntador al archivo dado en el desplazamiento de bytes fijado en el flujo del archivo. Es equivalente a llamar (en C) a gzseek(zp, offset, SEEK_SET).

Si el archivo está abierto para lectura, ésta función es emulada pero puede ser extremadamente lenta. Si el archivo está abierto para escritura, sólo está soportada la búsqueda hacia adelante; entonces gzseek() comprime una secuencia de ceros hasta la nueva posición de inicio.

Parámetros

zp

El apuntador al archivo gz. Debe ser válido y debe apuntar a un archivo abierto exitosamente por gzopen().

offset

El desplazamiento buscado.

whence

Los valores de whence son:

  • SEEK_SET - Establece la posición igual al offset de bytes.
  • SEEK_CUR - Establece la posición en la posición actual más el offset.

Si whence no se especifica, se asume que es SEEK_SET.

Valores devueltos

En caso de éxito, retorna 0; en caso contrario, devuelve -1. Notese que buscar pasado el EOF no es considerado un error.

Ejemplos

Ejemplo #1 Ejamplo de gzseek()

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

Ver también

  • gztell() - Indica la posición de lectura/escritura del apuntador al archivo gz
  • gzrewind() - Reinicia la posición del apuntador a un archivo 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