Rev3865, Fix ZipStream seek support
This commit is contained in:
parent
9b274415e0
commit
c165d21d95
2 changed files with 21 additions and 5 deletions
|
@ -2,11 +2,11 @@ import cStringIO as StringIO
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
|
||||||
class ZipStream(file):
|
class ZipStream(file):
|
||||||
def __init__(self, dir_path):
|
def __init__(self, dir_path):
|
||||||
self.dir_path = dir_path
|
self.dir_path = dir_path
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
self.buff_pos = 0
|
||||||
self.zf = zipfile.ZipFile(self, 'w', zipfile.ZIP_DEFLATED, allowZip64=True)
|
self.zf = zipfile.ZipFile(self, 'w', zipfile.ZIP_DEFLATED, allowZip64=True)
|
||||||
self.buff = StringIO.StringIO()
|
self.buff = StringIO.StringIO()
|
||||||
self.file_list = self.getFileList()
|
self.file_list = self.getFileList()
|
||||||
|
@ -27,6 +27,8 @@ class ZipStream(file):
|
||||||
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)
|
||||||
|
self.buff_pos += len(back)
|
||||||
return back
|
return back
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
@ -36,8 +38,22 @@ class ZipStream(file):
|
||||||
def tell(self):
|
def tell(self):
|
||||||
return self.pos
|
return self.pos
|
||||||
|
|
||||||
def seek(self, pos, type):
|
def seek(self, pos, whence=0):
|
||||||
pass
|
if pos >= self.buff_pos:
|
||||||
|
self.buff.seek(pos - self.buff_pos, whence)
|
||||||
|
self.pos = pos
|
||||||
|
|
||||||
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()
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.6.5"
|
self.version = "0.6.5"
|
||||||
self.rev = 3864
|
self.rev = 3865
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.pending_changes = {}
|
self.pending_changes = {}
|
||||||
|
|
Loading…
Reference in a new issue