chore(file_operators): use utf-8 as default encoding
This commit is contained in:
parent
94e2ab7c86
commit
7e3609f19f
@ -42,17 +42,20 @@ class FileOperator(Protocol):
|
|||||||
class LocalFileOperator(FileOperator):
|
class LocalFileOperator(FileOperator):
|
||||||
"""File operations implementation for local filesystem."""
|
"""File operations implementation for local filesystem."""
|
||||||
|
|
||||||
|
def __init__(self, encoding: str = "utf-8"):
|
||||||
|
self.encoding = encoding
|
||||||
|
|
||||||
async def read_file(self, path: PathLike) -> str:
|
async def read_file(self, path: PathLike) -> str:
|
||||||
"""Read content from a local file."""
|
"""Read content from a local file."""
|
||||||
try:
|
try:
|
||||||
return Path(path).read_text()
|
return Path(path).read_text(encoding=self.encoding)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ToolError(f"Failed to read {path}: {str(e)}") from None
|
raise ToolError(f"Failed to read {path}: {str(e)}") from None
|
||||||
|
|
||||||
async def write_file(self, path: PathLike, content: str) -> None:
|
async def write_file(self, path: PathLike, content: str) -> None:
|
||||||
"""Write content to a local file."""
|
"""Write content to a local file."""
|
||||||
try:
|
try:
|
||||||
Path(path).write_text(content)
|
Path(path).write_text(content, encoding=self.encoding)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ToolError(f"Failed to write to {path}: {str(e)}") from None
|
raise ToolError(f"Failed to write to {path}: {str(e)}") from None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user