Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions zipfly/zipfly.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def __init__(self,
storesize = 0,
filesystem = 'fs',
arcname = 'n',
encode = 'utf-8',):
encode = 'utf-8',
zip_cls = zipfile.ZipFile,
pwd = None,
**kwargs):

"""
@param store size : int : size of all files
Expand Down Expand Up @@ -106,6 +109,13 @@ def __init__(self,
self.compresslevel = compresslevel
self.storesize = storesize
self.encode = encode
self.zip_cls = zip_cls
self.zip_cls_kwargs = kwargs
self.pwd = pwd
try:
self.zipinfo_cls = self.zip_cls.zipinfo_cls
except AttributeError:
self.zipinfo_cls = zipfile.ZipInfo
self.ezs = int('0x8e', 16) # empty zip size in bytes

def set_comment(self, comment):
Expand Down Expand Up @@ -199,11 +209,16 @@ def generator(self):
stream = ZipflyStream(self.chunksize)

def writer():
with zipfile.ZipFile(
with self.zip_cls(
stream,
mode = self.mode,
compression = self.compression,
allowZip64 = self.allowZip64,) as zf:
compresslevel = self.compresslevel,
allowZip64 = self.allowZip64,
**self.zip_cls_kwargs) as zf:

if self.pwd:
zf.setpassword(self.pwd)

for path in self.paths:

Expand All @@ -222,10 +237,13 @@ def writer():
# arcname will be default path
path[self.arcname] = path[self.filesystem]

z_info = zipfile.ZipInfo.from_file(
z_info = self.zipinfo_cls.from_file(
path[self.filesystem],
path[self.arcname]
)
z_info.compress_type = self.compression
if self.compresslevel is not None:
z_info._compresslevel = self.compresslevel

with open( path[self.filesystem], 'rb' ) as e:
# Read from filesystem:
Expand Down