BZ2Codec

Inheritance diagram of BZ2Codec
class BZ2Codec[source]

A codec able to encode/decode to/from BZ2 format. It uses the bz2 module

Example:

>>> from taurus.core.util.codecs import CodecFactory

>>> # first encode something
>>> data = 100 * "Hello world\n"
>>> cf = CodecFactory()
>>> codec = cf.getCodec('bz2')
>>> format, encoded_data = codec.encode(("", data))
>>> print(len(data), len(encoded_data))
1200, 68
>>> format, decoded_data = codec.decode((format, encoded_data))
>>> print(decoded_data[20])
'Hello world\nHello wo'

Import from taurus.core.util.codecs as:

from taurus.core.util.codecs import BZ2Codec
decode(data, *args, **kwargs)[source]

decodes the given data from bz2 bytes.

Parameters:

data (sequence[str, obj]) – a sequence of two elements where the first item is the encoding format of the second item object

Returns:

a sequence of two elements where the first item is the encoding format of the second item object

Return type:

sequence[str, obj]

encode(data, *args, **kwargs)[source]

encodes the given data to bz2 bytes. The given data must be bytes

Parameters:

data (sequence[str, obj]) – a sequence of two elements where the first item is the encoding format of the second item object

Returns:

a sequence of two elements where the first item is the encoding format of the second item object

Return type:

sequence[str, obj]