Skip to content

Commit 992207e

Browse files
committed
update some for file filter
1 parent a10d650 commit 992207e

File tree

3 files changed

+186
-28
lines changed

3 files changed

+186
-28
lines changed

src/File.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use function is_string;
3232
use function stream_get_contents;
3333
use function stream_get_meta_data;
34+
use function stream_set_blocking;
3435
use function strlen;
3536
use function trim;
3637

@@ -351,14 +352,35 @@ public static function streamFgets($stream, ?int $length = null): string
351352
return trim((string)fgets($stream, $length));
352353
}
353354

355+
/**
356+
* @param resource $stream
357+
* @param bool $blocking
358+
*
359+
* @return string
360+
*/
361+
public static function streamReadAll($stream, bool $blocking = true): string
362+
{
363+
self::assertReadableStream($stream);
364+
365+
if ($blocking) {
366+
return (string)stream_get_contents($stream);
367+
}
368+
369+
// non-blocking read
370+
if (stream_set_blocking($stream, false)) {
371+
return (string)stream_get_contents($stream);
372+
}
373+
return '';
374+
}
375+
354376
/**
355377
* @param resource $stream
356378
* @param int $length
357379
* @param int $offset
358380
*
359381
* @return string
360382
*/
361-
public static function streamReadAll($stream, int $length = -1, int $offset = -1): string
383+
public static function streamGetContents($stream, int $length = -1, int $offset = -1): string
362384
{
363385
self::assertReadableStream($stream);
364386

0 commit comments

Comments
 (0)