File handling for API.

This commit is contained in:
Mikael CAPELLE
2024-12-10 15:38:00 +01:00
parent 3c544c559b
commit 46558672e8
18 changed files with 288 additions and 160 deletions

View File

@@ -0,0 +1,18 @@
import logging
from pathlib import Path
from typing import Final
class SimpleFileHandler:
def __init__(self, logger: logging.Logger, folder: Path):
self.logger: Final = logger
self.folder: Final = folder
def create(self, filename: str, content: bytes, text: bool = False):
if text:
for line in content.decode("utf-8").splitlines():
self.logger.info(line)
else:
self.folder.mkdir(exist_ok=True)
with open(self.folder.joinpath(filename), "wb") as fp:
fp.write(content)