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

Class Decoder

source code

object --+
         |
        Decoder

Uncompresses a stream of lzw code points, as created by Encoder. Given a list of integer code points, with all unpacking foolishness complete, turns that list of codepoints into a list of uncompressed bytes. See BitUnpacker for what this doesn't do.

Instance Methods
 
__init__(self)
Creates a new Decoder.
source code
 
code_size(self)
Returns the current size of the Decoder's code book, that is, it's mapping of codepoints to byte strings.
source code
 
decode(self, codepoints)
Given an iterable of integer codepoints, yields the corresponding bytes, one at a time, as byte strings of length 1.
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)
(Constructor)

source code 

Creates a new Decoder. Decoders should not be reused for different streams.

Overrides: object.__init__

code_size(self)

source code 

Returns the current size of the Decoder's code book, that is, it's mapping of codepoints to byte strings. The return value of this method will change as the decode encounters more encoded input, or control codes.

decode(self, codepoints)

source code 

Given an iterable of integer codepoints, yields the corresponding bytes, one at a time, as byte strings of length 1. Retains the state of the codebook from call to call, so if you have another stream, you'll likely need another decoder!

Decoders will NOT handle END_OF_INFO_CODE (rather, they will handle the code by throwing an exception); END_OF_INFO should be handled by the upstream codepoint generator (see BitUnpacker, for example)

>>> import lzw
>>> dec = lzw.Decoder()
>>> ''.join(dec.decode([103, 97, 98, 98, 97, 32, 258, 260, 262, 121, 111, 263, 259, 261, 256]))
'gabba gabba yo gabba'