opentmd

文件 I/O 模块

概述

文件 I/O 模块位于 internal/fileio/,提供安全的文件读取能力,支持大文件截断。

核心函数

Read(path string, maxBytes int) (string, error)

Write(path, content string) error

Edit(path, oldStr, newStr string) (string, error)

辅助

函数 行为
Exists(path) bool os.Stat 成功即存在
IsReadable(path) error 必须存在、非目录且可 Open

安全边界

文件 I/O 本身不做路径沙箱:路径解析、工作区外审批与敏感路径拦截在 internal/pathutil + internal/permission 中完成;工具层只负责读写字节。

使用示例

content, err := fileio.Read("./main.go", 32*1024)
if err != nil {
    // 处理错误
}
// content 可能带 truncation 标记

集成

read_file / write_file / edit_file 由 internal/tool 调用;大输出外存与分页由 internal/tool/artifact.go 处理,不在 fileio 中做头尾截断。