@@ -304,7 +304,9 @@ public static function streamOpen(string $path)
304304 */
305305 public static function streamWrite ($ stream , string $ content , string $ path = '' ): void
306306 {
307- if (($ result = @fwrite ($ stream , $ content )) === false || ($ result < strlen ($ content ))) {
307+ self ::assertWritableStream ($ stream );
308+
309+ if (($ result = fwrite ($ stream , $ content )) === false || ($ result < strlen ($ content ))) {
308310 throw new IOException ('The file " ' . $ path . '" could not be written to. Check your disk space and file permissions. ' );
309311 }
310312 }
@@ -317,6 +319,8 @@ public static function streamWrite($stream, string $content, string $path = ''):
317319 */
318320 public static function streamRead ($ stream , int $ length = 1024 ): string
319321 {
322+ self ::assertReadableStream ($ stream );
323+
320324 return (string )fread ($ stream , $ length );
321325 }
322326
@@ -327,6 +331,8 @@ public static function streamRead($stream, int $length = 1024): string
327331 */
328332 public static function streamReadln ($ stream ): string
329333 {
334+ self ::assertReadableStream ($ stream );
335+
330336 return trim ((string )fgets ($ stream ));
331337 }
332338
@@ -339,6 +345,8 @@ public static function streamReadln($stream): string
339345 */
340346 public static function streamReadAll ($ stream , int $ length = -1 , int $ offset = -1 ): string
341347 {
348+ self ::assertReadableStream ($ stream );
349+
342350 return (string )stream_get_contents ($ stream , $ length , $ offset );
343351 }
344352
0 commit comments