mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 08:34:09 +02:00
handle seeks in countwrapper
This commit is contained in:
parent
89a8191632
commit
a0b84d362c
2 changed files with 29 additions and 0 deletions
|
|
@ -60,6 +60,17 @@ class CountWrapper extends Wrapper {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function stream_seek($offset, $whence = SEEK_SET) {
|
||||
if ($whence === SEEK_SET) {
|
||||
$this->readCount = $offset;
|
||||
$this->writeCount = $offset;
|
||||
} else if ($whence === SEEK_CUR) {
|
||||
$this->readCount += $offset;
|
||||
$this->writeCount += $offset;
|
||||
}
|
||||
return parent::stream_seek($offset, $whence);
|
||||
}
|
||||
|
||||
public function dir_opendir($path, $options) {
|
||||
return $this->open();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,22 @@ class CountWrapperTest extends WrapperTest {
|
|||
fclose($wrapped);
|
||||
$this->assertSame(6, $count);
|
||||
}
|
||||
|
||||
public function testReadCountSeek() {
|
||||
$count = 0;
|
||||
|
||||
$source = fopen('php://temp', 'r+');
|
||||
fwrite($source, 'foobar');
|
||||
rewind($source);
|
||||
|
||||
$wrapped = CountWrapper::wrap($source, function ($readCount) use (&$count) {
|
||||
$count = $readCount;
|
||||
});
|
||||
|
||||
stream_get_contents($wrapped);
|
||||
fseek($wrapped, 3);
|
||||
stream_get_contents($wrapped);
|
||||
fclose($wrapped);
|
||||
$this->assertSame(6, $count);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue