Anna Schumaker
7ff1a3d60c
And include a function to help extract embedded cover.jpg files. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
22 lines
601 B
Python
22 lines
601 B
Python
# 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
|