cpython/Lib/encodings/bz2_codec.py

28 lines
721 B
Python
Raw Normal View History

2003-09-23 20:21:01 +00:00
""" 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.
2003-09-24 03:57:36 +00:00
Adapted by Raymond Hettinger from zlib_codec.py which was written
2003-09-23 20:21:01 +00:00
by Marc-Andre Lemburg (mal@lemburg.com).
"""
import codecs
2003-12-01 10:41:02 +00:00
import bz2
2003-09-23 20:21:01 +00:00
2003-12-01 10:41:02 +00:00
def encode(input, errors='strict'):
2003-09-23 20:21:01 +00:00
assert errors == 'strict'
output = bz2.compress(input)
return (output, len(input))
2003-12-01 10:41:02 +00:00
def decode(input, errors='strict'):
2003-09-23 20:21:01 +00:00
assert errors == 'strict'
output = bz2.decompress(input)
return (output, len(input))
### encodings module API
def getregentry():
2003-12-01 10:41:02 +00:00
return (encode, decode, codecs.StreamReader, codecs.StreamWriter)