/
ReadHandle.php
48 lines (38 loc) 路 1.27 KB
/
ReadHandle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace Psl\File;
use Psl;
use Psl\Filesystem;
use Psl\IO;
final class ReadHandle extends Internal\AbstractHandleWrapper implements ReadHandleInterface
{
use IO\ReadHandleConvenienceMethodsTrait;
private ReadHandleInterface $readHandle;
/**
* @param resource|object $stream
*
* @throws IO\Exception\BlockingException If unable to set the stream to non-blocking mode.
* @throws Psl\Exception\InvariantViolationException If $path does not point to a file, or is not readable.
*/
public function __construct(string $path)
{
Psl\invariant(Filesystem\is_file($path), 'File "%s" is not a file.', $path);
Psl\invariant(Filesystem\is_readable($path), 'File "%s" is not readable.', $path);
$this->readHandle = Internal\open($path, 'r', read: true, write: false);
parent::__construct($this->readHandle);
}
/**
* {@inheritDoc}
*/
public function readImmediately(?int $max_bytes = null): string
{
return $this->readHandle->readImmediately($max_bytes);
}
/**
* {@inheritDoc}
*/
public function read(?int $max_bytes = null, ?int $timeout_ms = null): string
{
return $this->readHandle->read($max_bytes, $timeout_ms);
}
}