Files
snake-python/server/Files.py
T
daniel156161 6e74b5fb57
Build and Push Docker Container / build-and-push (push) Successful in 1m35s
change from sync to async and from flask to quart
2026-01-06 13:36:43 +01:00

25 lines
597 B
Python

import aiofiles.os
import aiofiles
import os
async def read_file(path: str, callback=None):
if not await aiofiles.os.path.exists(path):
return None
async with aiofiles.open(path, "r") as f:
if callback:
return await callback(f)
return await f.read()
async def save_file(path: str, data, callback=None, *args, **kwargs):
dir_path = os.path.dirname(path)
if dir_path:
await aiofiles.os.makedirs(dir_path, exist_ok=True)
async with aiofiles.open(path, "w") as f:
if callback:
await callback(data, f, *args, **kwargs)
else:
await f.write(data)