Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jleclanche/binreader
BinaryReader for Python
https://github.com/jleclanche/binreader
binary bytes parsing
Last synced: about 1 month ago
JSON representation
BinaryReader for Python
- Host: GitHub
- URL: https://github.com/jleclanche/binreader
- Owner: jleclanche
- License: mit
- Created: 2018-10-15T02:13:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-22T02:21:29.000Z (over 5 years ago)
- Last Synced: 2024-09-14T01:30:57.996Z (2 months ago)
- Topics: binary, bytes, parsing
- Language: Python
- Homepage: https://pypi.org/project/binreader/
- Size: 4.88 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# binreader - BinaryReader for Python
A BinaryReader class for Python 3.6+.
## Usage
### binreader.BinaryReader
Instanciate a BinaryReader class:
```py
from binreader import BinaryReaderwith open("example.bin", "rb") as f:
reader = BinaryReader(f)
print(reader.read_int()) # Reads an int32, returns a Python int
```The following read methods are available:
- `read_bool()` -> `bool`
- `read_byte()` -> `int`
- `read_ubyte()` -> `int`
- `read_int16()` -> `int`
- `read_uint16()` -> `int`
- `read_int32()` -> `int`
- `read_uint32()` -> `int`
- `read_int64()` -> `int`
- `read_uint64()` -> `int`
- `read_int()` -> `int` (alias of `read_int32()`)
- `read_uint()` -> `int` (alias of `read_uint32()`)
- `read_float()` -> `float`
- `read_double()` -> `float`The following string read methods are available:
- `read_cstring()` -> `bytes`: Reads a null-terminated string.
- `read_string(size: int=None)` -> `str`: Reads and decodes a string of size `size`. If `size` is `None`, expects a null terminator.The following utility methods are available:
- `align()`: Seeks forward to align the buffer's handle position on a multiple of 4 bytes.
- `read(*args)`: Calls `read(*args)` on the buffer.
- `seek(*args)`: Calls `seek(*args)` on the buffer.
- `tell()`: Returns the buffer's handle position.
- `read_struct(format)`: Read a struct from the buffer, returning a tuple of that struct.
Size is automatically calculated. Endianness defaults to the reader's endianness, but may be overridden.## License
This project is licensed under the MIT license. The full license text is
available in the LICENSE file.