ByteStream
ByteStream
¶
A stream of bytes with get and peek operations. Used during deserialization
from_bytes
classmethod
¶
from_bytes(bytes_: bytes) -> Self
Construct a ByteStream from bytes
Parameters:
-
bytes_(bytes) –The bytes
Returns:
-
Self–A
ByteStreaminstance
from_file
classmethod
¶
from_file(filepath: str) -> Self
Construct a ByteStream from a file.
Parameters:
-
filepath(str) –The file to read
Returns:
-
Self–A
ByteStreaminstance
get
¶
get(n: int) -> bytes
Get bytes from the stream and seek forward
Parameters:
-
n(int) –The number of bytes to get
Raises:
-
OsError–Attempting to request more bytes than the stream has left
Returns:
-
bytes–A
bytesstring of the specified length
is_empty
¶
is_empty() -> bool
Checks if this stream has been fully consumed
Returns:
-
bool–Trueif the stream has no more bytes to return, elseFalse
peek
¶
peek(n: int) -> bytes
Get bytes from the stream without seeking forward
Parameters:
-
n(int) –The number of bytes to get
Raises:
-
OsError–Attempting to request more bytes than the stream has left
Returns:
-
bytes–A
bytesstring of the specified length
remaining
¶
remaining() -> bytes
Get all the remaining bytes from the stream and seek to the end
Returns:
-
bytes–A
bytesstring consisting of all the bytes remaining in the stream. May beb""if the stream is -
bytes–empty