-
Notifications
You must be signed in to change notification settings - Fork 3
/
dtzlib.py
34 lines (27 loc) · 900 Bytes
/
dtzlib.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from zlib import decompress, compress, error
from dtoperation import DTOperation
class DTZlib(DTOperation):
'''ZLib compression/decompression'''
def needs_key(self):
''''''
return False
def needs_second_key(self):
''''''
return False
def needs_IV(self):
''''''
return False
def transform(self, dt_input, dt_key1=None, dt_key2=None, dt_iv=None, dt_mode='dec'):
'''Return encoded/decoded zlib content.'''
# TODO: Compress/Decompress in blocks
if dt_mode == 'enc':
return compress(str(dt_input))
elif dt_mode == 'dec':
try:
return decompress(str(dt_input))
except error:
# Try again without Error CRC checks
return decompress(str(dt_input), -15)
return None