lzw.ByteEncoder

Package lzw :: Class ByteEncoder |
[frames] | no frames]

# Class ByteEncoder

source code

    object --+
             |
            ByteEncoder

Takes a stream of uncompressed bytes and produces a stream of compressed bytes, usable by ByteDecoder. Combines an Encoder with a BitPacker.

    >>> import lzw
    >>>
    >>> enc = lzw.ByteEncoder(12)
    >>> bigstr = b"gabba gabba yo gabba gabba gabba yo gabba gabba gabba yo gabba gabba gabba yo"
    >>> encoding = enc.encodetobytes(bigstr)
    >>> encoded = b"".join( b for b in encoding )
    >>> encoded
    '3\x98LF#\x08\x82\x05\x04\x83\x1eM\xf0x\x1c\x16\x1b\t\x88C\xe1q(4"\x1f\x17\x85C#1X\xec.\x00'
    >>>
    >>> dec = lzw.ByteDecoder()
    >>> decoding = dec.decodefrombytes(encoded)
    >>> decoded = b"".join(decoding)
    >>> decoded == bigstr
    True

Instance Methods
__init__(self, max_width=12) max_width is the maximum width in bits we want to see in the output stream of codepoints. | source code
encodetobytes(self, bytesource) Returns an iterator of bytes, adjusting our packed width between minwidth and maxwidth when it detects an overflow is about to occur. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, max_width=12) (Constructor) | source code
max_width is the maximum width in bits we want to see in the output stream of codepoints. Overrides: object.__init__

### encodetobytes(self, bytesource) | source code
Returns an iterator of bytes, adjusting our packed width between minwidth and maxwidth when it detects an overflow is about to occur. Dual of ByteDecoder.decodefrombytes.