-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDuplexStream.php
More file actions
48 lines (40 loc) · 1.17 KB
/
DuplexStream.php
File metadata and controls
48 lines (40 loc) · 1.17 KB
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
namespace React\Filesystem\Stream;
use Evenement\EventEmitter;
use React\Filesystem\AdapterInterface;
use React\Stream\DuplexStreamInterface;
class DuplexStream extends EventEmitter implements DuplexStreamInterface, GenericStreamInterface
{
use ReadableStreamTrait;
use WritableStreamTrait;
use GenericStreamTrait;
/**
* @param string $path
* @param mixed $fileDescriptor
* @param AdapterInterface $filesystem
*/
public function __construct($path, $fileDescriptor, AdapterInterface $filesystem)
{
$this->path = $path;
$this->setFilesystem($filesystem);
$this->fileDescriptor = $fileDescriptor;
}
protected function readChunk()
{
if ($this->pause) {
return;
}
$this->resolveSize()->then(function () {
$this->performRead($this->calculateChunkSize());
});
}
protected function resolveSize()
{
if ($this->readCursor < $this->size) {
return \React\Promise\resolve();
}
return $this->getFilesystem()->stat($this->path)->then(function ($stat) {
$this->size = $stat['size'];
});
}
}