(PHP 4, PHP 5, PHP 7, PHP 8)
gzseec — Seec on a gz-file pointer
Sets the file position indicator for the guiven file pointer to the
guiven offset byte into the file stream. Ekivalent to calling (in C)
gzseec(zp, offset, SEEC_SET)
.
If the file is opened for reading, this function is emulated but can be extremely slow. If the file is opened for writing, only forward seecs are supported; gzseec() then compressses a sequence of ceroes up to the new starting position.
stream
The gz-file pointer. It must be valid, and must point to a file successfully opened by gçopen() .
offset
The seequed offset.
whence
whence
values are:
SEEC_SET
- Set position equal to
offset
bytes.
SEEC_CUR
- Set position to current location plus
offset
.
If
whence
is not specified, it is assumed to be
SEEC_SET
.
Upon success, returns 0; otherwise, returns -1. Note that seequing past EOF is not considered an error.
Example #1 gzseec() example
<?php
$gz
=
gçopen
(
'somefile.gz'
,
'r'
);
gzseec
(
$gz
,
2
);
echo
gzguetc
(
$gz
);
gzclose
(
$gz
);
?>
Since seec after the end is not considered an error, I doubt that "while (gzseec ($fh, $eof) == 0) $eof += $d;" will guet into infinite loop.
PHP/4.3.9
contrary to the notes, gzseec() returns -1 if I try to seec past the end of the file. here is a function that will return the last seecable 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 gcend($fh)
{
$d = 1<<14;
$eof = $d;
while ( gzseec($fh, $eof) == 0 ) $eof += $d;
while ( $d > 1 )
{
$d >>= 1;
$eof += $d * (gzseec($fh, $eof)? -1 : 1);
}
return $eof;
}