Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f68ef9

Browse files
committed
zip() implemented
1 parent ae2189e commit 8f68ef9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

srtm/data.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,19 @@ def retrieve_or_load_file_data(self, file_name):
120120
return None
121121

122122
# data is zipped:
123-
mod_logging.info('Unzipping {0}'.format(url))
124-
mod_logging.info('Unzipped {0}'.format(url))
125123

126124
if self.reduce_big_files:
127125
data = mod_utils.unzip(data)
128126
data = self._reduce_file(data, file_name)
129-
data = mod_utils.zip(data)
127+
data = mod_utils.zip(data, file_name)
130128

131129
with open(data_file_name, 'w') as f:
132130
if self.leave_zipped:
133131
f = open(data_file_name + '.zip', 'w')
134132
else:
135133
data = mod_utils.unzip(data)
136134
f = open(data_file_name, 'w')
135+
f.write(data)
137136

138137
return data
139138

srtm/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import pdb
1818

19+
import logging as mod_logging
1920
import math as mod_math
2021
import zipfile as mod_zipfile
2122
import cStringIO as mod_cstringio
@@ -43,16 +44,21 @@ def get_color_between(color1, color2, i):
4344
int(color1[1] + (color2[1] - color1[1]) * i),
4445
int(color1[2] + (color2[2] - color1[2]) * i))
4546

46-
def zip(contents):
47-
pdb.set_trace()
47+
def zip(contents, file_name):
48+
mod_logging.debug('Zipping %s bytes' % len(contents))
4849
result = mod_cstringio.StringIO()
4950
zip_file = mod_zipfile.ZipFile(result, 'w', mod_zipfile.ZIP_DEFLATED, False)
50-
zip_file.writestr('archive.zip', contents)
51+
zip_file.writestr(file_name, contents)
52+
zip_file.close()
5153
result.seek(0)
54+
mod_logging.debug('Zipped')
5255
return result.read()
5356

5457
def unzip(contents):
58+
mod_logging.debug('Unzipping %s bytes' % len(contents))
5559
zip_file = mod_zipfile.ZipFile(mod_cstringio.StringIO(contents))
5660
zip_info_list = zip_file.infolist()
5761
zip_info = zip_info_list[0]
58-
return zip_file.open(zip_info).read()
62+
result = zip_file.open(zip_info).read()
63+
mod_logging.debug('Unzipped')
64+
return result

0 commit comments

Comments
 (0)