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