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, 20 Jun 2008

view this page in

gzseek

(PHP 4, PHP 5)

gzseek — Déplace le pointeur de lecture

Description

int gzseek ( resource $zp , int $offset )

gzseek() place le pointeur de lecture du fichier zp à la position offset , comptée en octets depuis le début du fichier. C'est l'équivalent de la fonction gzseek(zp, offset, SEEK_SET), du langage C.

Si le fichier est ouvert en lecture, cette fonction est alors émulée, et se révèle extrêmement lente. Si le fichier est ouvert en écriture, seuls les déplacements vers l'avant sont supportés : gzseek() compresse alors une série de zéros jusqu'à la nouvelle position.

Liste de paramètres

zp

Le pointeur de fichier gz. Il doit être valide et doit pointer vers un fichier ouvert avec succès grâce à la fonction gzopen().

offset

La position désirée.

Valeurs de retour

0 en cas de réussite, -1 sinon. Notez que placer le pointeur au delà de la fin du fichier n'est pas considéré comme une erreur.

Exemples

Exemple #1 Exemple avec gzseek()

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

Voir aussi



add a note add a note User Contributed Notes
gzseek
dperham at wgate dot com
12-Apr-2005 08: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, 20 Jun 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites