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.
gzseek
(PHP 4, PHP 5)
gzseek — جستجو بر اشارهگر gz-file
Description
تعیین موقعیت فایل برای اشارهگر فایل داده شده به بایت آفست داده شده در جریان فایل . برابر با فراخوانی (در C) gzseek(zp, offset, SEEK_SET).
اگر فایل برای خواندن باز شده باشد این تابع فراخوانی میشود اما ممکن است بسیار آهسته باشد. اگر فایل برای نوشتن باز شده باشد فقط جستجو رو به جلو پشتیبانی میشود; سپس gzseek() توالی صفرها را تا موقعیت شروع جدید قرار میدهد.
Parameters
- zp
-
اشارهگر gz-file. باید صحیح باشد و به فایل باز شده موفق توسط gzopen() اشاره کند.
- offset
-
آفست جستجو شده.
- whence
-
مقادیر whence هستند:
- SEEK_SET - تعیین موقعیت برابر با offset bytes.
- SEEK_CUR - تعیین موقعیت برابر با موقعیت فعلی به اضافه offset.
اگر whence تعیین نشده باشد برابر با SEEK_SET در نظر گرفته میشود.
Return Values
در صورت موفقیت بازگرداندن 0; در غیر این صورت بازگرداندن -1. توجه کنید جستجو پس از EOF خطا نیست.
Examples
Example #1 مثال gzseek()
<?php
$gz = gzopen('somefile.gz', 'r');
gzseek($gz,2);
echo gzgetc($gz);
gzclose($gz);
?>
See Also
- gztell() - بررسی اشارهگر gz-file موقعیت خواندن/نوشتن
- gzrewind() - برگرداندن موقعیت اشارهگر gz-file به ابتدا
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;
}
