Merged
Merged
Conversation
| a `Promise` which resolves with the stream data buffer. | ||
| The `buffer(ReadableStreamInterface $stream, int $maxLength = 0)` function can be used to create | ||
| a `Promise` which resolves with the stream data buffer. With an optional maximum length argument | ||
| which defaults to no limit. |
| var_dump(json_decode($contents)); | ||
| }, function ($error) { | ||
| // Reaching here when the stream buffer goes above the max size. | ||
| // (In this example that is 1024 bytes.) |
|
|
||
| $promise = new Promise\Promise(function ($resolve, $reject) use ($stream, &$buffer) { | ||
| $promise = new Promise\Promise(function ($resolve, $reject) use ($stream, $deferred, &$buffer) { | ||
| $deferred->promise()->done($resolve, $reject); |
| $buffer .= $data; | ||
| if ($maxLength > 0 && strlen($buffer) > $maxLength) { | ||
| $deferred->reject(new \RuntimeException('Buffer exceeded maximum length')); | ||
| } |
| if ($maxLength !== null && strlen($buffer) > (int)$maxLength) { | ||
| $deferred->reject(new \RuntimeException('Buffer exceeded maximum length')); | ||
| } | ||
| }; |
| $bufferer = function ($data) use (&$buffer, &$bufferer, $stream, $deferred, $maxLength) { | ||
| $buffer .= $data; | ||
| if ($maxLength !== null && isset($buffer[$maxLength])) { | ||
| $deferred->reject(new \RuntimeException('Buffer exceeded maximum length')); |
| * Creates a `Promise` which resolves with the stream data buffer | ||
| * | ||
| * @param ReadableStreamInterface $stream | ||
| * @param int $maxLength |
| $bufferer = function ($data) use (&$buffer, $deferred, $maxLength) { | ||
| $buffer .= $data; | ||
| if ($maxLength !== null && isset($buffer[$maxLength])) { | ||
| $deferred->reject(new \RuntimeException('Buffer exceeded maximum length')); |
|
|
||
| public function testMaximumSize() | ||
| { | ||
| $this->setExpectedException('\RuntimeException', 'Buffer exceeded maximum length'); |
andig
mentioned this pull request
Merged
| $bufferer = function ($data) use (&$buffer, $deferred, $maxLength) { | ||
| $buffer .= $data; | ||
| if ($maxLength !== null && isset($buffer[$maxLength])) { | ||
| $deferred->reject(new \OverflowException('Buffer exceeded maximum length')); |
clue approved these changes Oct 17, 2017
jsor approved these changes Oct 17, 2017