From 80c68755679540e25f11262f7f036a9ec33c5b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E7=BE=BFELS?= <71250018+EillesWan@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=A0=E4=B9=9F=E8=AE=B8=EF=BC=8C?= =?UTF-8?q?=E5=A4=A7=E5=AE=B6=E7=9A=84=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E9=83=BD=E6=98=AF*nix=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update file.py --- src/utils/io/file.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils/io/file.py b/src/utils/io/file.py index c25a9c7d..0766dbe1 100644 --- a/src/utils/io/file.py +++ b/src/utils/io/file.py @@ -1,10 +1,12 @@ import aiofiles +from pathlib import Path async def write_file( - file_path: str, + file_path: str | Path, content: str | bytes, - mode: str = "w" + mode: str = "w", + **kws, ): """ 写入文件 @@ -13,11 +15,15 @@ async def write_file( file_path: 文件路径 content: 内容 """ - async with aiofiles.open(file_path, mode) as f: + async with aiofiles.open(file_path, mode, **kws) as f: await f.write(content) -async def read_file(file_path: str, mode: str = "r") -> str: +async def read_file( + file_path: str | Path, + mode: str = "r", + **kws, +) -> str: """ 读取文件 Args: @@ -25,5 +31,5 @@ async def read_file(file_path: str, mode: str = "r") -> str: mode: 读取模式 Returns: """ - async with aiofiles.open(file_path, mode) as f: + async with aiofiles.open(file_path, mode, **kws) as f: return await f.read()