blob: 22b32e27ba94933a129aeb68f745d9318ab5de11 [file] [log] [blame]
Raymond Hettinger9a80c5d2003-09-23 20:21:01 +00001""" Python 'bz2_codec' Codec - bz2 compression encoding
2
3 Unlike most of the other codecs which target Unicode, this codec
4 will return Python string objects for both encode and decode.
5
Raymond Hettinger9edae342003-09-24 03:57:36 +00006 Adapted by Raymond Hettinger from zlib_codec.py which was written
Raymond Hettinger9a80c5d2003-09-23 20:21:01 +00007 by Marc-Andre Lemburg (mal@lemburg.com).
8
9"""
10import codecs
Raymond Hettingera4551702003-12-01 10:41:02 +000011import bz2
Raymond Hettinger9a80c5d2003-09-23 20:21:01 +000012
Raymond Hettingera4551702003-12-01 10:41:02 +000013def encode(input, errors='strict'):
Raymond Hettinger9a80c5d2003-09-23 20:21:01 +000014 assert errors == 'strict'
15 output = bz2.compress(input)
16 return (output, len(input))
17
Raymond Hettingera4551702003-12-01 10:41:02 +000018def decode(input, errors='strict'):
Raymond Hettinger9a80c5d2003-09-23 20:21:01 +000019 assert errors == 'strict'
20 output = bz2.decompress(input)
21 return (output, len(input))
22
Raymond Hettinger9a80c5d2003-09-23 20:21:01 +000023### encodings module API
24
25def getregentry():
26
Raymond Hettingera4551702003-12-01 10:41:02 +000027 return (encode, decode, codecs.StreamReader, codecs.StreamWriter)