import os
from tempfile import TemporaryDirectory, mktemp
from zipfile import ZipFile


class Zip:
    dir: TemporaryDirectory[str]

    def __init__(self):
        self.dir = TemporaryDirectory()

    @property
    def dirname(self):
        return self.dir.name

    def pack(self):
        tmp_zip = mktemp(suffix='.zip')
        with ZipFile(tmp_zip, 'w') as zip_object:
            for folder_name, sub_folders, file_names in os.walk(self.dir.name):
                for filename in file_names:
                    file_path = os.path.join(folder_name, filename)
                    zip_object.write(file_path, os.path.basename(file_path))
        return tmp_zip
