# Copyright 2022 (c) Anna Schumaker. """Special handling for temporary directories.""" import tempfile import pathlib from . import gsetup TMP_DIR = pathlib.Path(tempfile.gettempdir()) / gsetup.APPLICATION_ID TMP_DIR.mkdir(exist_ok=True) def cover_jpg(data: bytes | None = None) -> pathlib.Path: """Get the path to the temporary cover.jpg file. If 'data' is provided, then the file will be created with the contents initialized to 'data'. """ cover = TMP_DIR / "cover.jpg" if data is not None: with cover.open("wb") as f: f.write(data) return cover