A library for manipulating files via bits
Project description
What is BitIO?
A library that exports a BitIO class to read and write bits on streams.
>>> from io import BytesIO
>>> from bitio import BitIO
>>> stream = BytesIO()
>>>
>>> wrapped = BitIO(stream)
>>> wrapped.write('00')
0
>>> wrapped.write('10000')
0
>>> wrapped.write([True] * 9)
2
>>> wrapped.close()
>>> stream.getvalue()
b'!\xff'
>>>
>>> stream.seek(0)
0
>>> wrapped = BitIO(stream)
>>> wrapped.read(4)
bitarray('0010')
>>> wrapped.read(6)
bitarray('000111')
>>> wrapped.read()
bitarray('111111')
Installing BitIO
Either
$ git clone https://github.com/gaming32/BitIO.git
$ cd BitIO
$ python setup.py install
or
$ pip install BitIO2
Documentation
bitio.BitIO
bitio.BitIO(stream:io.RawIOBase)
Wraps an io stream and allows bitarray read and write to that stream. However, it can only read or write. A new one must be created to do the other function.
bitio.BitIO.readable
bitio.BitIO.readable() -> bool
Returns True
if this stream is readable (will always be False
if a write has occured on it).
bitio.BitIO.writable
bitio.BitIO.writable() -> bool
Returns True
if this stream is writable (will always be False
if a read has occured on it).
bitio.BitIO.seekable
bitio.BitIO.seekable() -> bool
Returns True
if this stream is seekable (will always be False
).
bitio.BitIO.seek
bitio.BitIO.seek(where, whence=0) -> int
Raises io.UnsupportedOperation('seek')
.
bitio.BitIO.tell
bitio.BitIO.tell() -> int
Raises io.UnsupportedOperation('tell')
.
bitio.BitIO.flush
bitio.BitIO.flush(flush_wrapped_stream=True)
Flushes the buffer to the wrapped stream (this should never have to happen).
If flush_wrapped_stream
is True
, this also calls self._stream.flush()
.
bitio.BitIO.write
bitio.BitIO.write(bits:Sequence[bool]) -> int
Returns the number of BYTES written.
bitio.BitIO.read
bitio.BitIO.read(c=-1) -> bitarray
Reads c
bits from the wrapped stream.
If c
is ommitted or negative, reads all bits from the wrapped stream.
bitio.BitIO.close
bitio.BitIO.close()
Calls self.flush(flush_wrapped_stream=False)
.
bitio.BitIO._stream
The wrapped stream.
bitio.BitIO._buffer
The bits that are waiting to be flushed to the wrapped stream. The length of this object should always be less than eight. If it isn't, call bitio.BitIO.flush(False)
.
bitio.BitIO._readable
Used for the return value of bitio.BitIO.readable
. If the value is None
, self._stream.readable()
is returned. Otherwise, self._readable
is returned.
bitio.BitIO._writable
Used for the return value of bitio.BitIO.writable
. If the value is None
, self._stream.writable()
is returned. Otherwise, self._writable
is returned.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file BitIO2-1.1.0.tar.gz
.
File metadata
- Download URL: BitIO2-1.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c360b8a5dfcd1716d5b05d2b25b6eaea9b7254768636965ce15bb12be6df2b7 |
|
MD5 | 594cc3671061a8f7714dd3fb5887a278 |
|
BLAKE2b-256 | 812586b4e26f8be116077e2a1dbde181bfc2e0f544f0f0bd9deed1980452e2db |
File details
Details for the file BitIO2-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: BitIO2-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0a7bc4d42f302c2ac39dbef5f80f8c0629a6b2ca057b9f4e788453e3ffb6f2e |
|
MD5 | 3938fe4c14da1c6aecdec764d7def592 |
|
BLAKE2b-256 | db888f357c294ad7b469e3713aebfc238a80fa9415de975d4b37ce079d274505 |