Charles Kabui
read zip files
810a7a1
raw
history blame
No virus
469 Bytes
import io
import zipfile
def read_zip_file(archive_path: str, file_path: str):
"""
Read a file from a zip archive.
Args:
archive_path (str): The path to the zip archive.
file_path (str): The path to the file inside the archive.
Returns:
io.BytesIO: The file as a BytesIO object.
"""
with zipfile.ZipFile(archive_path) as zip_file:
file = zip_file.read(file_path)
return io.BytesIO(file) if file else file