Skip to content

Commit 6bb4fe9

Browse files
committed
Always read size of chunksize if in MemoryStream
1 parent c381e95 commit 6bb4fe9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spec/Encoding/MemoryStream.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class MemoryStream implements StreamInterface
1010

1111
private $size = 0;
1212

13-
public function __construct($body = "", $chunkSize = null)
13+
private $chunkSize;
14+
15+
public function __construct($body = "", $chunkSize = 8192)
1416
{
1517
$this->size = strlen($body);
1618
$this->resource = fopen('php://memory', 'rw+');
@@ -22,6 +24,8 @@ public function __construct($body = "", $chunkSize = null)
2224

2325
fwrite($this->resource, $body);
2426
fseek($this->resource, 0);
27+
28+
$this->chunkSize = $chunkSize;
2529
}
2630

2731
public function __toString()
@@ -89,7 +93,7 @@ public function isReadable()
8993

9094
public function read($length)
9195
{
92-
return fread($this->resource, $length);
96+
return fread($this->resource, min($this->chunkSize, $length));
9397
}
9498

9599
public function getContents()

0 commit comments

Comments
 (0)