Spaces:
Sleeping
Sleeping
Update helpers.py
Browse files- helpers.py +9 -8
helpers.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
|
| 3 |
-
def save_as_zip(bundle):
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
return
|
|
|
|
| 1 |
+
import zipfile
|
| 2 |
+
import io
|
| 3 |
|
| 4 |
+
def save_as_zip(bundle: dict) -> bytes:
|
| 5 |
+
zip_buffer = io.BytesIO()
|
| 6 |
+
with zipfile.ZipFile(zip_buffer, "w") as zipf:
|
| 7 |
+
for filename, content in bundle.get("files", {}).items():
|
| 8 |
+
zipf.writestr(filename, content)
|
| 9 |
+
zip_buffer.seek(0)
|
| 10 |
+
return zip_buffer.read()
|