-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdtgzip.py
More file actions
39 lines (33 loc) · 1.21 KB
/
dtgzip.py
File metadata and controls
39 lines (33 loc) · 1.21 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from dtoperation import DTOperation
from StringIO import StringIO
from gzip import GzipFile
class DTGZip(DTOperation):
'''Contains GZip Compression/Decompression Handlers'''
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'):
'''Launch GZip compression and decompression'''
if dt_mode == 'dec':
compressed_data = StringIO()
decompressed_data = StringIO()
compressed_data.write(dt_input)
compressed_data.seek(0)
decompressed_file = GzipFile(fileobj=compressed_data, mode='rb')
decompressed_data.write(decompressed_file.read())
decompressed_file.close()
return decompressed_data.getvalue()
else:
compressed_data = StringIO()
compressed_file = GzipFile(fileobj=compressed_data, mode='wb')
compressed_file.write(str(dt_input))
compressed_file.close()
return compressed_data.getvalue()