Skip to content

Instantly share code, notes, and snippets.

@bomzheg
Last active March 27, 2023 21:19
Show Gist options
  • Save bomzheg/9813c2626f621a13b620b01a98157942 to your computer and use it in GitHub Desktop.
Save bomzheg/9813c2626f621a13b620b01a98157942 to your computer and use it in GitHub Desktop.
from typing import BinaryIO
from zipfile import Path as ZipPath
def load_results(zip_file: BinaryIO):
zip_path = ZipPath(zip_file)
for unpacked_file in zip_path.iterdir():
if not unpacked_file.is_file():
continue
if unpacked_file.name == "results.json":
with unpacked_file.open("r", encoding="utf8") as results_file:
print(type(results_file.read()))
continue
if unpacked_file.name == "image.jpg":
with unpacked_file.open("rb") as image:
print(type(image.read()))
if __name__ == '__main__':
with open("example.zip", "rb") as f:
load_results(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment