Bit packer and depacker. Encodes and decodes sequences of integers with known bit-widths (and sequences of symbols equivalent to integers under some mapping).
Sub Byte stores data without wasting bits, while preserving its structure, without requiring compression or decompression. Simple bit packing is used, supporting using less than a byte of storage for <=7 bit fields, crossing byte boundaries if necessary.
A bit width for each symbol is required. The bit width sequence (a simple codec) can be associated with the encoded data as meta data. The decoder can be passed the total number of symbols to decode (e.g. whether a null byte (0b00000000), is 8 1-bit zeros, 4 2-bit zeros, 2 u4 zeros or a single u8 zero).
Alternatively, more dynamic codecs can be supported by passing null for the number of symbols to the decoder. Axtra custom code must then be written by the user, to determine when iteration ceases. This can be used e.g. to encode the actual bit widths first (in some other fixed bit widths), to encode the number of symbols or cycles, and to implement any other codec that determines bit widths, and termination of iteration, according to the user's code.
Data validation (e.g. checksums or hashes) must be done by the user, but an extra field can easily be appended to a bit width cycle.
Calculate a cache of data in Python.
uv pip install sub_byte
Decode a cache of data in Javascript, even in browser.
npm i sub_byte
This library is not needed for data storage. Neither Sub_byte nor anything else, will reduce the disk space used. If the size of the un-encoded data set is less 4kB for example (or the page size of the file system on which the data will be stored, e.g. ext4, NTFS, APFS) then it is already below the minimum file size for that file system.
Up to 8 u1s (bits), up to 4 u2s, or up to 2 u3s or u4s per byte. Each developer must create their own implementation and tests. Interoperability between different private implementations is untestable.
Encodes max symbol per byte. Variable byte encoding - uses continuation bits.
- Exploits statistical distributions (e.g. "E" being more common in English text than "Q") and patterns.
- Unstructured until the end user unzips the archive.
Configured npm module for Typescript.
Support dynamic codecs (null/None number of elements to decode).
mypy --python-executable=path/to/venv/where/deps/installed/python.exe src/sub_byte
Activate venv where deps installed
pyright src/sub_byte/factories.py
npm run typecheck
npm run eslint
npm run prettier
npm run prettier:write
Bump version in package.json to x.y.z
npm run prepublish
npm pack
Double check contents of sub_byte-x.y.z.tgz
npm publish
Sign in (currently requires being the author).