@@ 216-229 (lines=14) @@ | ||
213 | * @return int Returns the number of bytes written to the stream. |
|
214 | * @throws RuntimeException on failure. |
|
215 | */ |
|
216 | public function write($string) |
|
217 | { |
|
218 | if (! $this->stream) { |
|
219 | throw new RuntimeException('No resource available; cannot write'); |
|
220 | } |
|
221 | if (! $this->isWritable()) { |
|
222 | throw new RuntimeException('Stream is not writable'); |
|
223 | } |
|
224 | $result = fwrite($this->stream, $string); |
|
225 | if (false === $result) { |
|
226 | throw new RuntimeException('Error writing to stream'); |
|
227 | } |
|
228 | return $result; |
|
229 | } |
|
230 | ||
231 | /** |
|
232 | * Returns whether or not the stream is readable. |
|
@@ 256-269 (lines=14) @@ | ||
253 | * if no bytes are available. |
|
254 | * @throws RuntimeException if an error occurs. |
|
255 | */ |
|
256 | public function read($length) |
|
257 | { |
|
258 | if (! $this->stream) { |
|
259 | throw new RuntimeException('No resource available; cannot read'); |
|
260 | } |
|
261 | if (! $this->isReadable()) { |
|
262 | throw new RuntimeException('Stream is not readable'); |
|
263 | } |
|
264 | $result = fread($this->stream, $length); |
|
265 | if (false === $result) { |
|
266 | throw new RuntimeException('Error reading stream'); |
|
267 | } |
|
268 | return $result; |
|
269 | } |
|
270 | ||
271 | /** |
|
272 | * Returns the remaining contents in a string |