File handling for API.
This commit is contained in:
18
src/holt59/aoc/utils/files.py
Normal file
18
src/holt59/aoc/utils/files.py
Normal 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)
|
Reference in New Issue
Block a user