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

Method Read

pkg/backends/store_backend.go:109–134  ·  view source on GitHub ↗

Read 实现 BackendProtocol.Read

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

Source from the content-addressed store, hash-verified

107
108// Read 实现 BackendProtocol.Read
109func (b *StoreBackend) Read(ctx context.Context, path string, offset, limit int) (string, error) {
110 // 从 Store 加载文件数据
111 data, err := b.loadFileData(ctx, path)
112 if err != nil {
113 return "", err
114 }
115
116 totalLines := len(data.Lines)
117
118 // 处理 offset
119 if offset < 0 {
120 offset = 0
121 }
122 if offset >= totalLines {
123 return "", nil
124 }
125
126 // 处理 limit
127 endLine := totalLines
128 if limit > 0 {
129 endLine = min(offset+limit, totalLines)
130 }
131
132 selectedLines := data.Lines[offset:endLine]
133 return strings.Join(selectedLines, "\n"), nil
134}
135
136// Write 实现 BackendProtocol.Write
137func (b *StoreBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) {

Callers

nothing calls this directly

Calls 3

loadFileDataMethod · 0.95
minFunction · 0.50
JoinMethod · 0.45

Tested by

no test coverage detected