diff --git a/src/CallbackWrapper.php b/src/CallbackWrapper.php index 6071cd0..67f9110 100644 --- a/src/CallbackWrapper.php +++ b/src/CallbackWrapper.php @@ -97,7 +97,7 @@ public function stream_open($path, $mode, $options, &$opened_path) { public function stream_read($count) { $result = parent::stream_read($count); if (is_callable($this->readCallback)) { - call_user_func($this->readCallback, $result); + call_user_func($this->readCallback, strlen($result)); } return $result; } diff --git a/tests/CallbackWrapperTest.php b/tests/CallbackWrapperTest.php index e1cf84f..d4b3a5d 100644 --- a/tests/CallbackWrapperTest.php +++ b/tests/CallbackWrapperTest.php @@ -31,8 +31,10 @@ public function testWrapInvalidSource() { public function testReadCallback() { $called = false; - $callBack = function () use (&$called) { + $bytesRead = 0; + $callBack = function ($count) use (&$called, &$bytesRead) { $called = true; + $bytesRead += $count; }; $source = fopen('php://temp', 'r+'); @@ -42,6 +44,9 @@ public function testReadCallback() { $wrapped = $this->wrapSource($source, $callBack); $this->assertEquals('foo', fread($wrapped, 3)); $this->assertTrue($called); + + $this->assertEquals('bar', fread($wrapped, 1000)); + $this->assertEquals(6, $bytesRead); } public function testWriteCallback() {