MCPcopy Create free account
hub / github.com/astercloud/aster / Read

Method Read

pkg/backends/filesystem.go:68–95  ·  view source on GitHub ↗

Read 实现 BackendProtocol.Read

(ctx context.Context, path string, offset, limit int)

Source from the content-addressed store, hash-verified

66
67// Read 实现 BackendProtocol.Read
68func (b *FilesystemBackend) Read(ctx context.Context, path string, offset, limit int) (string, error) {
69 // 使用 SandboxFS 读取文件
70 content, err := b.fs.Read(ctx, path)
71 if err != nil {
72 return "", err
73 }
74
75 // 分割成行
76 lines := strings.Split(content, "\n")
77 totalLines := len(lines)
78
79 // 处理 offset
80 if offset < 0 {
81 offset = 0
82 }
83 if offset >= totalLines {
84 return "", nil
85 }
86
87 // 处理 limit
88 endLine := totalLines
89 if limit > 0 {
90 endLine = min(offset+limit, totalLines)
91 }
92
93 selectedLines := lines[offset:endLine]
94 return strings.Join(selectedLines, "\n"), nil
95}
96
97// Write 实现 BackendProtocol.Write
98func (b *FilesystemBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) {

Callers

nothing calls this directly

Calls 3

ReadMethod · 0.65
minFunction · 0.50
JoinMethod · 0.45

Tested by

no test coverage detected