lzw.BitUnpacker

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

# Class BitUnpacker

source code

    object --+
             |
            BitUnpacker

An adaptive-width bit unpacker, intended to decode streams written by BitPacker into integer codepoints. Like BitPacker, knows about code size changes and control codes.

Instance Methods
__init__(self, initial_code_size) initial_code_size is the starting size of the codebook associated with the to-be-unpacked stream. | source code
unpack(self, bytesource) Given an iterator of bytes, returns an iterator of integer code points. | 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, initial_code_size) (Constructor) | source code
initial_code_size is the starting size of the codebook associated with the to-be-unpacked stream. Overrides: object.__init__

### unpack(self, bytesource) | source code
Given an iterator of bytes, returns an iterator of integer code points. Auto-magically adjusts point width when it sees an almost-overflow in the input stream, or an LZW CLEAR_CODE or END_OF_INFO_CODE Trailing bits at the end of the given iterator, after the last codepoint, will be dropped on the floor. At the end of the iteration, or when an END_OF_INFO_CODE seen the unpacker will ignore the bits after the code until it reaches the next aligned byte. END_OF_INFO_CODE will *not* stop the generator, just reset the alignment and the width
    >>> import lzw
    >>> unpk = lzw.BitUnpacker(initial_code_size=258)
    >>> [ i for i in unpk.unpack([ chr(0), chr(0xC0), chr(0x40) ]) ]
    [1, 257]