summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/bz2_codec.py
blob: 22b32e27ba94933a129aeb68f745d9318ab5de11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
""" Python 'bz2_codec' Codec - bz2 compression encoding

    Unlike most of the other codecs which target Unicode, this codec
    will return Python string objects for both encode and decode.

    Adapted by Raymond Hettinger from zlib_codec.py which was written
    by Marc-Andre Lemburg (mal@lemburg.com).

"""
import codecs
import bz2

def encode(input, errors='strict'):
    assert errors == 'strict'
    output = bz2.compress(input)
    return (output, len(input))

def decode(input, errors='strict'):
    assert errors == 'strict'
    output = bz2.decompress(input)
    return (output, len(input))

### encodings module API

def getregentry():

    return (encode, decode, codecs.StreamReader, codecs.StreamWriter)