Fix broken zip file generation
This commit is contained in:
parent
0f8b220f59
commit
efb7b147af
1 changed files with 15 additions and 1 deletions
|
@ -2,7 +2,6 @@ import io
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
|
||||||
class ZipStream(object):
|
class ZipStream(object):
|
||||||
def __init__(self, dir_path):
|
def __init__(self, dir_path):
|
||||||
self.dir_path = dir_path
|
self.dir_path = dir_path
|
||||||
|
@ -27,6 +26,7 @@ class ZipStream(object):
|
||||||
self.buff.seek(0)
|
self.buff.seek(0)
|
||||||
back = self.buff.read()
|
back = self.buff.read()
|
||||||
self.buff.truncate(0)
|
self.buff.truncate(0)
|
||||||
|
self.buff.seek(0)
|
||||||
return back
|
return back
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
@ -37,7 +37,21 @@ class ZipStream(object):
|
||||||
return self.pos
|
return self.pos
|
||||||
|
|
||||||
def seek(self, pos, whence=0):
|
def seek(self, pos, whence=0):
|
||||||
|
self.buff.seek(pos, whence)
|
||||||
|
self.pos = pos
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
zs = ZipStream(".")
|
||||||
|
out = open("out.zip", "wb")
|
||||||
|
while 1:
|
||||||
|
data = zs.read()
|
||||||
|
print("Write %s" % len(data))
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
out.write(data)
|
||||||
|
out.close()
|
||||||
|
|
Loading…
Reference in a new issue