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

Method Read

pkg/backends/state.go:114–141  ·  view source on GitHub ↗

Read 实现 BackendProtocol.Read

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

Source from the content-addressed store, hash-verified

112
113// Read 实现 BackendProtocol.Read
114func (b *StateBackend) Read(ctx context.Context, path string, offset, limit int) (string, error) {
115 b.mu.RLock()
116 defer b.mu.RUnlock()
117
118 data, exists := b.files[path]
119 if !exists {
120 return "", fmt.Errorf("file not found: %s", path)
121 }
122
123 totalLines := len(data.Lines)
124
125 // 处理 offset
126 if offset < 0 {
127 offset = 0
128 }
129 if offset >= totalLines {
130 return "", nil
131 }
132
133 // 处理 limit
134 endLine := totalLines
135 if limit > 0 {
136 endLine = min(offset+limit, totalLines)
137 }
138
139 selectedLines := data.Lines[offset:endLine]
140 return strings.Join(selectedLines, "\n"), nil
141}
142
143// Write 实现 BackendProtocol.Write
144func (b *StateBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) {

Callers 4

TestStateBackendFunction · 0.95

Calls 2

minFunction · 0.50
JoinMethod · 0.45

Tested by 4

TestStateBackendFunction · 0.76