Skip to content

Commit

Permalink
chore: remove memory buffer class in favor of BytesIO
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlbauer committed Jan 22, 2025
1 parent 77eee32 commit 08eeb02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
23 changes: 0 additions & 23 deletions rocrate/memory_buffer.py

This file was deleted.

9 changes: 5 additions & 4 deletions rocrate/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import warnings

from collections import OrderedDict
from io import BytesIO
from pathlib import Path
from urllib.parse import urljoin

from .memory_buffer import MemoryBuffer
from .model import (
ComputationalWorkflow,
ComputerLanguage,
Expand Down Expand Up @@ -482,10 +482,9 @@ def write_zip(self, out_path):

def stream_zip(self):
""" Create a stream of bytes representing the RO-Crate as a ZIP file. """
buffer = MemoryBuffer()
buffer = BytesIO()
with zipfile.ZipFile(buffer, mode='w', compression=zipfile.ZIP_DEFLATED) as archive:
entities = self.data_entities + self.default_entities
for writeable_entity in entities: #self.data_entities + self.default_entities:
for writeable_entity in self.data_entities + self.default_entities:
current_file_path, current_out_file = None, None
for path, chunk in writeable_entity.stream():
if path != current_file_path:
Expand All @@ -494,9 +493,11 @@ def stream_zip(self):
current_file_path = path
current_out_file = archive.open(path, mode='w')
current_out_file.write(chunk)
buffer.seek(0)
yield buffer.read()
if current_out_file:
current_out_file.close()
buffer.seek(0)
yield buffer.read()
buffer.close()

Expand Down

0 comments on commit 08eeb02

Please sign in to comment.