wiithon.binary.reader module
A reader that can read from a stream or bytes.
Used by everything in wiithon since it checks the validity of readed bytes
- class wiithon.binary.reader.BinaryReader(stream, encoding='utf-8')[source]
Bases:
objectA reader that can read from a stream or bytes.
Bytes are converted to a stream
- stream
Stream to read for operations
- encoding
Encoding used by default for reading string
- classmethod from_bytes(data)[source]
Converted bytes to stream so BinaryReader can read it.
- Parameters:
data (
bytes) – Bytes to convert.- Return type:
- Returns:
A BinaryReader with a stream to read of
- tell()[source]
Get the current stream cursor position
- Return type:
- Returns:
The current stream cursor position within the stream
- u8()[source]
Read a single unsigned byte from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
The byte read from the stream
- u16()[source]
Read two unsigned bytes from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
Integer reads from the stream
- u32()[source]
Read four unsigned bytes from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
Integer reads from the stream
- u64()[source]
Read eight unsigned bytes from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
The from the stream
- s8()[source]
Read a single signed byte from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
The number read from the stream
- s16()[source]
Read two signed bytes from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
Integer reads from the stream
- s32()[source]
Read four signed bytes from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
Integer reads from the stream
- s64()[source]
Read eight signed bytes from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
Integer reads from the stream
- float()[source]
Read a float number from the stream in big-endian at the current stream position. The cursor is placed after the read byte
- Return type:
- Returns:
Float reads from the stream
- u32_shifted()[source]
Reads an unsigned 32 bits number then left shifted 2 times.
Some file formats use this.
- Return type:
- Returns:
The number left shifted 2 times from the stream