1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace WyriHaximus\React\Stream\Hash; |
4
|
|
|
|
5
|
|
|
use Evenement\EventEmitter; |
6
|
|
|
use React\Stream\ReadableStreamInterface; |
7
|
|
|
use React\Stream\Util; |
8
|
|
|
use React\Stream\WritableStreamInterface; |
9
|
|
|
|
10
|
|
|
final class ReadableStreamHash extends EventEmitter implements ReadableStreamInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var WritableStreamInterface |
14
|
|
|
*/ |
15
|
|
|
private $stream; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var resource |
19
|
|
|
*/ |
20
|
|
|
private $context; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param ReadableStreamInterface $stream |
24
|
|
|
* @param string $algo |
25
|
|
|
* @param int $options |
26
|
|
|
* @param string $key |
27
|
|
|
*/ |
28
|
184 |
|
public function __construct(ReadableStreamInterface $stream, string $algo, int $options = 0, string $key = '') |
29
|
|
|
{ |
30
|
184 |
|
$this->stream = $stream; |
|
|
|
|
31
|
184 |
|
$this->context = hash_init($algo, $options, $key); |
32
|
|
|
$this->stream->on('data', function ($data) { |
33
|
184 |
|
hash_update($this->context, $data); |
34
|
184 |
|
$this->emit('data', [$data]); |
35
|
184 |
|
}); |
36
|
184 |
|
$this->stream->once('close', function () use ($algo) { |
37
|
184 |
|
$this->emit('close'); |
38
|
184 |
|
$this->emit('hash', [ |
39
|
184 |
|
hash_final($this->context), |
40
|
184 |
|
$algo, |
41
|
|
|
]); |
42
|
184 |
|
}); |
43
|
184 |
|
Util::forwardEvents($stream, $this, ['error', 'end']); |
44
|
184 |
|
} |
45
|
|
|
|
46
|
184 |
|
public function isReadable() |
47
|
|
|
{ |
48
|
184 |
|
return $this->stream->isReadable(); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function pause() |
52
|
|
|
{ |
53
|
|
|
return $this->stream->pause(); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function resume() |
57
|
|
|
{ |
58
|
|
|
return $this->stream->resume(); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function pipe(WritableStreamInterface $dest, array $options = []) |
62
|
|
|
{ |
63
|
|
|
return $this->stream->pipe($dest, $options); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function close() |
67
|
|
|
{ |
68
|
|
|
$this->stream->close(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..