RE_UPLOAD-REBUILD-RESTART
Browse files- utils/read_zip_file.py +15 -0
utils/read_zip_file.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import zipfile
|
| 3 |
+
|
| 4 |
+
def read_zip_file(archive_path: str, file_path: str):
|
| 5 |
+
"""
|
| 6 |
+
Read a file from a zip archive.
|
| 7 |
+
Args:
|
| 8 |
+
archive_path (str): The path to the zip archive.
|
| 9 |
+
file_path (str): The path to the file inside the archive.
|
| 10 |
+
Returns:
|
| 11 |
+
io.BytesIO: The file as a BytesIO object.
|
| 12 |
+
"""
|
| 13 |
+
with zipfile.ZipFile(archive_path) as zip_file:
|
| 14 |
+
file = zip_file.read(file_path)
|
| 15 |
+
return io.BytesIO(file) if file else file
|