Skip to content

Commit

Permalink
Fix chunk size issue in ResourceOutputStream, fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed May 29, 2017
1 parent e6750aa commit ea135f2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ResourceOutputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ResourceOutputStream implements OutputStream {
private $chunkSize;

/**
* @param $stream Stream resource.
* @param resource $stream Stream resource.
* @param int|null $chunkSize Chunk size per `fwrite()` operation.
*/
public function __construct($stream, int $chunkSize = null) {
Expand Down Expand Up @@ -155,7 +155,12 @@ private function send(string $data, bool $end = false): Promise {
}

// Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.
$written = @\fwrite($this->resource, $data, $this->chunkSize);
// Use conditional, because PHP doesn't like getting null passed.
if ($this->chunkSize) {
$written = @\fwrite($this->resource, $data, $this->chunkSize);
} else {
$written = @\fwrite($this->resource, $data);
}

if ($written === false) {
$message = "Failed to write to stream";
Expand Down

0 comments on commit ea135f2

Please sign in to comment.