aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Stream/StreamInterface.php
blob: 0655d22ba45dd500e42160e1c6033f007918e197 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

declare(strict_types=1);

namespace Nsfisis\Waddiwasi\Stream;

interface StreamInterface
{
    /**
     * Reads $bytes bytes from the stream.
     *
     * @param positive-int $bytes
     *
     * @return non-empty-string
     *   A binary string of $bytes bytes.
     *
     * @throws UnexpectedEofException
     *   Thrown if the stream does not have enough bytes to read.
     *
     * @phpstan-impure
     */
    public function read(int $bytes): string;

    /**
     * Reads a single byte from the stream.
     *
     * @return int<0, 255>
     *   An 8-bit unsigned integer read from the stream.
     *
     * @throws UnexpectedEofException
     *   Thrown if the stream have reached the end.
     *
     * @phpstan-impure
     */
    public function readByte(): int;

    /**
     * Reads a single byte from the stream without advancing the position.
     *
     * @return int<0, 255>
     *   An 8-bit unsigned integer read from the stream.
     *
     * @throws UnexpectedEofException
     *   Thrown if the stream have reached the end.
     *
     * @phpstan-impure
     */
    public function peekByte(): int;

    /**
     * Seeks $bytes bytes from the current position.
     *
     * @param positive-int $bytes
     *
     * @throws UnexpectedEofException
     *   Thrown if the stream does not have enough bytes to seek.
     *
     * @phpstan-impure
     */
    public function seek(int $bytes): void;

    /**
     * Returns the current position in the stream.
     *
     * @return 0|positive-int
     *
     * @phpstan-impure
     */
    public function tell(): int;

    /**
     * Returns whether the stream has reached the end.
     *
     * @phpstan-impure
     */
    public function eof(): bool;
}