|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-07-14 13:18 UTC] jbondc at openmv dot com
Description:
------------
May not be a bug but a documentation issue
With a file, fseek() to an offset that doesn't exist results in NULL bytes added.
Using a memory stream, fseek() just fails.
Which one is the expected behavior? Also for streamWrapper::stream_seek()
Test script:
---------------
$sp = fopen("php://memory", 'w+');
fseek($sp, 1024); // fails why?
echo fwrite($sp, "abc"); // 3
fseek($sp, 1024); //
echo fread($sp, 3); // NULL..
$sp = fopen("/tmp/foo", 'w+');
fseek($sp, 1024);
echo fwrite($sp, "abc"); // 3
fseek($sp, 1024);
echo fread($sp, 3); // abc
Expected result:
----------------
3abc3abc
Actual result:
--------------
33abc
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
Thanks, saw the changes in fseek.xml What about adding streamWrapper::hasFeature(/* int */$featureId) const STREAM_FEAT_FWDSEEK = 1; const STREAM_FEAT_OTHER = 2; //... $stream = new File_Stream('/tmp/foo'); $stream->isSupported(STREAM_FEAT_FWDSEEK); // true fseek($stream, 1024); // NULL bytes added $stream = new Memory_Stream('/tmp/foo'); $stream->isSupported(STREAM_FEAT_FWDSEEK); // false fseek($stream, 1024); // false The goal is to have a consistent api to write to a binary stream. I can give it some more thought, other stream 'features'.