-
Notifications
You must be signed in to change notification settings - Fork 44
/
lzma.py
40 lines (27 loc) · 910 Bytes
/
lzma.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import absolute_import
# lzma only available in Python >= 3.3
try:
import lzma
except ImportError:
lzma = None
from io import BytesIO
import logging
from .codec import Codec
log = logging.getLogger(__name__)
class Lzma(Codec):
"""Implementation of :class:`.Codec` for lzma compression.
Needs Python >= 3.3.
"""
def __init__(self):
if lzma is None:
log.warning('LZMA codec not supported. It is only supported '
'in Python>=3.3. Not compressing streams.')
super(Lzma, self).__init__()
def compress(self, stream):
if lzma is None:
return Codec.compress(self, stream)
return BytesIO(lzma.compress(stream.read()))
def decompress(self, stream):
if lzma is None:
return Codec.decompress(self, stream)
return BytesIO(lzma.decompress(stream.read()))