fs

package
v1.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package fs 定义 ext 层共享的最小文件系统接口:filetools、offload、 skill、localsession 等中间件依赖此抽象,便于注入内存 FS(测试) 或本地实现(生产)。一个接口,四个方法,仅此而已。

Local 是 FileSystem 的本地磁盘实现,所有路径被限制在 Root 内 (类似 chroot),路径穿越(如 ../)会被拒绝。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Name  string `json:"name"`
	Size  int64  `json:"size"`
	IsDir bool   `json:"is_dir"`
}

Entry 是目录项。

type FileSystem

type FileSystem interface {
	Read(ctx context.Context, path string) ([]byte, error)
	Write(ctx context.Context, path string, data []byte) error
	List(ctx context.Context, dir string) ([]Entry, error)
	// Edit 在单个文件内做查找替换(全部命中都替换),返回替换次数;
	// oldText 不存在时返回错误(防止调用方误以为修改成功)。
	Edit(ctx context.Context, path, oldText, newText string) (int, error)
}

FileSystem 是唯一的文件系统接口。路径使用正斜杠风格, 由实现负责与具体平台路径互转及安全约束。

type Local

type Local struct{ Root string }

Local 以 Root 为沙箱根目录。

func NewLocal

func NewLocal(root string) Local

NewLocal 创建以 root 为边界的本地文件系统。

func (Local) Edit

func (l Local) Edit(ctx context.Context, path, oldText, newText string) (int, error)

Edit 查找替换:全部命中都替换,返回次数。

func (Local) List

func (l Local) List(_ context.Context, dir string) ([]Entry, error)

func (Local) Read

func (l Local) Read(_ context.Context, path string) ([]byte, error)

func (Local) Write

func (l Local) Write(_ context.Context, path string, data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL