Read 实现 BackendProtocol.Read
(ctx context.Context, path string, offset, limit int)
| 107 | |
| 108 | // Read 实现 BackendProtocol.Read |
| 109 | func (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 |
| 137 | func (b *StoreBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) { |
nothing calls this directly
no test coverage detected