MCPcopy
hub / github.com/wavetermdev/waveterm / WriteAt

Method WriteAt

pkg/filestore/blockstore.go:240–262  ·  view source on GitHub ↗
(ctx context.Context, zoneId string, name string, offset int64, data []byte)

Source from the content-addressed store, hash-verified

238}
239
240func (s *FileStore) WriteAt(ctx context.Context, zoneId string, name string, offset int64, data []byte) error {
241 if offset < 0 {
242 return fmt.Errorf("offset must be non-negative")
243 }
244 return withLock(s, zoneId, name, func(entry *CacheEntry) error {
245 err := entry.loadFileIntoCache(ctx)
246 if err != nil {
247 return err
248 }
249 file := entry.File
250 if offset > file.Size {
251 return fmt.Errorf("offset is past the end of the file")
252 }
253 partMap := file.computePartMap(offset, int64(len(data)))
254 incompleteParts := incompletePartsFromMap(partMap)
255 err = entry.loadDataPartsIntoCache(ctx, incompleteParts)
256 if err != nil {
257 return err
258 }
259 entry.writeAt(offset, data, false)
260 return nil
261 })
262}
263
264func (s *FileStore) AppendData(ctx context.Context, zoneId string, name string, data []byte) error {
265 return withLock(s, zoneId, name, func(entry *CacheEntry) error {

Callers 4

TestWriteAtFunction · 0.80
TestCircularWritesFunction · 0.80
TestMultiPartFunction · 0.80

Calls 6

withLockFunction · 0.85
incompletePartsFromMapFunction · 0.85
loadFileIntoCacheMethod · 0.80
computePartMapMethod · 0.80
writeAtMethod · 0.80

Tested by 3

TestWriteAtFunction · 0.64
TestCircularWritesFunction · 0.64
TestMultiPartFunction · 0.64