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 — gz ファイルポインタの位置を移動する
与えられたファイルポインタが指すファイルのファイル位置記述子を、
ファイルストリーム上の与えられた
offset バイトにセットします。
gzseek(zp, offset, SEEK_SET)
を
(C 言語において) コールするのと同じです。
ファイルが読み込み用にオープンされた場合、この関数は、 エミュレーションされますが、極端に遅くなる可能性があります。 ファイルを書き込み用にオープンした場合、 前方への移動のみがサポートされます。この場合、gzseek() は、新しい開始位置までゼロの並びのデータを圧縮します。
成功した場合、0を返します。それ以外の場合は、-1を返します。 移動がEOFを超える場合にもエラーは発生しないことに注意してください。
例1 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.9contrary 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;}