Skip to content

Commit

Permalink
Merge pull request #88 from EillesWan/main
Browse files Browse the repository at this point in the history
🌠也许,大家的测试环境都是*nix?
  • Loading branch information
snowykami authored Oct 22, 2024
2 parents ab89cd1 + 80c6875 commit 796fc6f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utils/io/file.py
Original file line number Diff line number Diff line change
@@ -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,
):
"""
写入文件
Expand All @@ -13,17 +15,21 @@ 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:
file_path: 文件路径
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()

0 comments on commit 796fc6f

Please sign in to comment.