diff --git a/legendary/models/chunk.py b/legendary/models/chunk.py index b3bed1d..7229be4 100644 --- a/legendary/models/chunk.py +++ b/legendary/models/chunk.py @@ -111,8 +111,11 @@ class Chunk: return _chunk - def write(self, compress=True): - bio = BytesIO() + def write(self, fp=None, compress=True): + if not fp: + bio = BytesIO() + else: + bio = fp self.uncompressed_size = self.compressed_size = len(self.data) if compress or self.compressed: @@ -139,4 +142,5 @@ class Chunk: # finally, add the data bio.write(self._data) - return bio.getvalue() + if not fp: + return bio.getvalue() diff --git a/legendary/models/manifest.py b/legendary/models/manifest.py index bfa5d9b..54fe2c4 100644 --- a/legendary/models/manifest.py +++ b/legendary/models/manifest.py @@ -135,8 +135,9 @@ class Manifest: return _manifest - def write(self, compress=True): + def write(self, fp=None, compress=True): body_bio = BytesIO() + self.meta.write(body_bio) self.chunk_data_list.write(body_bio) self.file_manifest_list.write(body_bio) @@ -151,7 +152,11 @@ class Manifest: self.data = zlib.compress(self.data) self.size_compressed = len(self.data) - bio = BytesIO() + if not fp: + bio = BytesIO() + else: + bio = fp + bio.write(struct.pack('