Skip to content

Commit

Permalink
feat: write_zip now uses zip streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlbauer committed Jan 27, 2025
1 parent bf1b990 commit 3634e4b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions rocrate/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,10 @@ def write(self, base_path):

def write_zip(self, out_path):
out_path = Path(out_path)
if out_path.suffix == ".zip":
out_path = out_path.parent / out_path.stem
tmp_dir = tempfile.mkdtemp(prefix="rocrate_")
try:
self.write(tmp_dir)
archive = shutil.make_archive(out_path, "zip", tmp_dir)
finally:
shutil.rmtree(tmp_dir)
return archive
with open(out_path, "wb") as f:
for chunk in self.stream_zip(out_path=out_path):
f.write(chunk)
return out_path

def stream_zip(self, chunk_size=8192, out_path=None):
""" Create a stream of bytes representing the RO-Crate as a ZIP file.
Expand Down

0 comments on commit 3634e4b

Please sign in to comment.