| @@ 121-154 (lines=34) @@ | ||
| 118 | * @override |
|
| 119 | * @inheritDoc |
|
| 120 | */ |
|
| 121 | public function read($length = null) |
|
| 122 | { |
|
| 123 | if (!$this->readable) |
|
| 124 | { |
|
| 125 | return $this->throwAndEmitException( |
|
| 126 | new ReadException('Stream is no longer readable.') |
|
| 127 | ); |
|
| 128 | } |
|
| 129 | ||
| 130 | if ($length === null) |
|
| 131 | { |
|
| 132 | $length = $this->bufferSize; |
|
| 133 | } |
|
| 134 | ||
| 135 | $ret = fread($this->resource, $length); |
|
| 136 | ||
| 137 | if ($ret === false) |
|
| 138 | { |
|
| 139 | return $this->throwAndEmitException( |
|
| 140 | new ReadException('Cannot read stream.') |
|
| 141 | ); |
|
| 142 | } |
|
| 143 | else if ($ret !== '') |
|
| 144 | { |
|
| 145 | $this->emit('data', [ $this, $ret ]); |
|
| 146 | ||
| 147 | if (strlen($ret) < $length) |
|
| 148 | { |
|
| 149 | $this->emit('end', [ $this ]); |
|
| 150 | } |
|
| 151 | } |
|
| 152 | ||
| 153 | return $ret; |
|
| 154 | } |
|
| 155 | ||
| 156 | /** |
|
| 157 | * @override |
|
| @@ 76-109 (lines=34) @@ | ||
| 73 | * @override |
|
| 74 | * @inheritDoc |
|
| 75 | */ |
|
| 76 | public function read($length = null) |
|
| 77 | { |
|
| 78 | if (!$this->readable) |
|
| 79 | { |
|
| 80 | return $this->throwAndEmitException( |
|
| 81 | new ReadException('Stream is no longer readable.') |
|
| 82 | ); |
|
| 83 | } |
|
| 84 | ||
| 85 | if ($length === null) |
|
| 86 | { |
|
| 87 | $length = $this->bufferSize; |
|
| 88 | } |
|
| 89 | ||
| 90 | $ret = fread($this->resource, $length); |
|
| 91 | ||
| 92 | if ($ret === false) |
|
| 93 | { |
|
| 94 | return $this->throwAndEmitException( |
|
| 95 | new ReadException('Cannot read stream.') |
|
| 96 | ); |
|
| 97 | } |
|
| 98 | else if ($ret !== '') |
|
| 99 | { |
|
| 100 | $this->emit('data', [ $this, $ret ]); |
|
| 101 | ||
| 102 | if (strlen($ret) < $length) |
|
| 103 | { |
|
| 104 | $this->emit('end', [ $this ]); |
|
| 105 | } |
|
| 106 | } |
|
| 107 | ||
| 108 | return $ret; |
|
| 109 | } |
|
| 110 | ||
| 111 | /** |
|
| 112 | * @override |
|