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

search for in the

gztell> <gzrewind
Last updated: Fri, 06 Nov 2009

view this page in

gzseek

(PHP 4, PHP 5)

gzseekgz ファイルポインタの位置を移動する

説明

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

与えられたファイルポインタが指すファイルのファイル位置記述子を、 ファイルストリーム上の与えられた offset バイトにセットします。 gzseek(zp, offset, SEEK_SET) を (C 言語において) コールするのと同じです。

ファイルが読み込み用にオープンされた場合、この関数は、 エミュレーションされますが、極端に遅くなる可能性があります。 ファイルを書き込み用にオープンした場合、 前方への移動のみがサポートされます。この場合、gzseek() は、新しい開始位置までゼロの並びのデータを圧縮します。

パラメータ

zp

gz ファイルポインタを指定します。これは有効なファイルポインタであり、 かつ、gzopen() によりオープンできたファイルを指している必要があります。

offset

移動するオフセットを指定します。

whence

whence の値は次のいずれかです。

  • SEEK_SET - offset バイト目に設定します。
  • SEEK_CUR - 現在位置から offset ぶん進んだ位置に設定します。

whence を省略した場合は SEEK_SET とみなします。

返り値

成功した場合、0を返します。それ以外の場合は、-1を返します。 移動がEOFを超える場合にもエラーは発生しないことに注意してください。

例1 gzseek() の例

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

参考

  • gztell() - gz ファイルポインタの読み込み/書き込み位置を返します
  • gzrewind() - gz ファイルポインタの示す位置を元に戻す



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