lzw.Encoder

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

# Class Encoder

source code

    object --+
             |
            Encoder

Given an iterator of bytes, returns an iterator of integer codepoints, suitable for use by Decoder. The core of the "compression" side of lzw compression/decompression.

Instance Methods
__init__(self, max_code_size=4096) When the encoding codebook grows larger than max_code_size, the Encoder will clear its codebook and emit a CLEAR_CODE | source code
code_size(self) Returns a count of the known codes, including codes that are implicit in the data but have not yet been produced by the iterator. | source code
flush(self) Yields any buffered codepoints, followed by a CLEAR_CODE, and clears the codebook as a side effect. | source code
encode(self, bytesource) Given an iterator over bytes, yields the corresponding stream of codepoints. | 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_code_size=4096) (Constructor) | source code
When the encoding codebook grows larger than max_code_size, the Encoder will clear its codebook and emit a CLEAR_CODE Overrides: object.__init__

### encode(self, bytesource) | source code
Given an iterator over bytes, yields the corresponding stream of codepoints. Will clear the codes at the end of the stream.
    >>> import lzw
    >>> enc = lzw.Encoder()
    >>> [ cp for cp in enc.encode("gabba gabba yo gabba") ]
    [103, 97, 98, 98, 97, 32, 258, 260, 262, 121, 111, 263, 259, 261, 256]