class-basebytereadstream.php
1 week ago
class-deflatereadstream.php
1 week ago
class-filereadstream.php
1 week ago
class-inflatereadstream.php
1 week ago
class-limitedbytereadstream.php
1 week ago
class-transformedreadstream.php
1 week ago
interface-bytereadstream.php
1 week ago
interface-bytereadstream.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WordPress\ByteStream\ReadStream; |
| 4 | |
| 5 | /** |
| 6 | * Interface for streaming, seekable byte readers. |
| 7 | * |
| 8 | * Implementations of this interface can be used to read data from |
| 9 | * various sources, such as files, strings, network sockets, zip files, |
| 10 | * parsers, etc. |
| 11 | */ |
| 12 | interface ByteReadStream { |
| 13 | |
| 14 | const PULL_NO_MORE_THAN = '#pull-no-more-than'; |
| 15 | const PULL_EXACTLY = '#pull-exactly'; |
| 16 | |
| 17 | /** |
| 18 | * Get the total length of the data stream. |
| 19 | * |
| 20 | * @return int|null The length of the data stream, or null if the length is unknown. |
| 21 | */ |
| 22 | public function length(): ?int; |
| 23 | |
| 24 | /** |
| 25 | * Get the current position in the data stream. |
| 26 | * |
| 27 | * @return int The current byte offset in the data stream. |
| 28 | */ |
| 29 | public function tell(): int; |
| 30 | |
| 31 | /** |
| 32 | * Seek to a specific position in the data stream. |
| 33 | * |
| 34 | * @param int $offset The byte offset to seek to. |
| 35 | * |
| 36 | * @return void |
| 37 | * @throws ByteStreamException If the offset is invalid. |
| 38 | */ |
| 39 | public function seek( int $offset ): void; |
| 40 | |
| 41 | /** |
| 42 | * Check if the end of the data stream has been reached. |
| 43 | * At this point, next_bytes() will always return false until |
| 44 | * seek() is called. |
| 45 | * |
| 46 | * @return bool Whether the end of the data stream has been reached. |
| 47 | */ |
| 48 | public function reached_end_of_data(): bool; |
| 49 | |
| 50 | /** |
| 51 | * Read the next chunk of bytes from the data stream. |
| 52 | * |
| 53 | * @return int how many bytes were pulled |
| 54 | */ |
| 55 | public function pull( ?int $n, string $mode = self::PULL_NO_MORE_THAN ): int; |
| 56 | |
| 57 | /** |
| 58 | * Get the next $n bytes without advancing the pointer. |
| 59 | * |
| 60 | * @return string The bytes read. |
| 61 | */ |
| 62 | public function peek( int $n ): string; |
| 63 | |
| 64 | /** |
| 65 | * Returns $n bytes and advances the pointer. |
| 66 | * |
| 67 | * @param int $n |
| 68 | * |
| 69 | * @return string |
| 70 | */ |
| 71 | public function consume( int $n ): string; |
| 72 | |
| 73 | /** |
| 74 | * Returns all remaining bytes in the stream. |
| 75 | * |
| 76 | * @return string |
| 77 | */ |
| 78 | public function consume_all(): string; |
| 79 | |
| 80 | /** |
| 81 | * Close the data stream. |
| 82 | * |
| 83 | * @return void |
| 84 | */ |
| 85 | public function close_reading(): void; |
| 86 | } |
| 87 |