Skip to main content

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.

Metadata

Release files for BitIO2 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BitIO2 1.1.0
File Size Uploaded
BitIO2-1.1.0.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BitIO2 1.1.0
File Interpreter ABI Platform
BitIO2-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.6 kB

Release files / BitIO2-1.1.0.tar.gz

Download URL BitIO2-1.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8c360b8a5dfcd1716d5b05d2b25b6eaea9b7254768636965ce15bb12be6df2b7
BLAKE2b-256 checksum
How to use checksums
812586b4e26f8be116077e2a1dbde181bfc2e0f544f0f0bd9deed1980452e2db
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / BitIO2-1.1.0-py3-none-any.whl

Download URL BitIO2-1.1.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0a7bc4d42f302c2ac39dbef5f80f8c0629a6b2ca057b9f4e788453e3ffb6f2e
BLAKE2b-256 checksum
How to use checksums
db888f357c294ad7b469e3713aebfc238a80fa9415de975d4b37ce079d274505
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page