Re: streams seek and feof()
| From: | Wez Furlong | Date: | Sun, 01 Jan 2006 03:17:06 +0000 |
| Subject: | Re: streams seek and feof() | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-3371@lists.php.net to get a copy of this message | ||
A seek will always clear the EOF indicator.
The EOF indicator only means "I tried to read, but there was no more data".
This can be a transient condition for network streams.
You need to attempt a read after a seek in order to force the EOF flag
to be set (provided that you're at the EOF when you read).
--Wez.
On 12/31/05, Greg Beaver <cellog@php.net> wrote:
> Hi all,
>
> I am trying to figure out how streams seek/eof is supposed to work for
> pecl/phar, and have run up against a roadblock. Basically, the
> userspace implementation in pear/PHP_Archive will return true for feof()
> if you seek to the end of a file internal to a phar. pecl/phar will
> not, and I actually don't see any way to make it do so.
>
> Currently, the seek function can either return 0 or something else, and
> if you return 0, stream->eof is automatically set to 0 no matter what
> (inside main/streams/streams.c). if you return -1, then stream_seek
> returns -1, which tells PHP that the seek failed. This in turn sets the
> internal file pointer to bool(false)
>
> In other words,
>
> fseek($fp, filesize('phar://blah.phar/test.php'));
> var_dump(feof($fp), ftell($fp));
> returns
>
> bool(true)
> int "43"
>
> for the userspace stream, and
>
> bool(false)
> int "43"
>
> for the extension, whereas seeking to filesize + 1 sets both to false in
> the pecl/phar, and set to true/44 in the userspace implementation.
>
> This is unacceptable, to say the least. How can I tell it that we are
> at the end of the stream *and* return a successful seek??
>
> Thanks,
> Greg
>
> --
> PECL development discussion Mailing List (http://pecl.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>