WyriHaximus · GitHub

Merged

Merged

Conversation

@WyriHaximus

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'));
}

jsor

if ($maxLength !== null && strlen($buffer) > (int)$maxLength) {
$deferred->reject(new \RuntimeException('Buffer exceeded maximum length'));
}
};

@WyriHaximus

kelunik

$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'));

@WyriHaximus

Closed

clue

* 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');

@WyriHaximus

@WyriHaximus

@andig andig mentioned this pull request

Oct 13, 2017

Merged

clue

$bufferer = function ($data) use (&$buffer, $deferred, $maxLength) {
$buffer .= $data;
if ($maxLength !== null && isset($buffer[$maxLength])) {
$deferred->reject(new \OverflowException('Buffer exceeded maximum length'));

@clue

clue

clue approved these changes Oct 17, 2017

jsor

jsor approved these changes Oct 17, 2017

@jsor

Read the original on github.com ↗