MCPcopy Index your code
hub / github.com/OpenListTeam/OpenList / WriteAt

Method WriteAt

internal/hybrid_cache/file.go:127–164  ·  view source on GitHub ↗
(p []byte, off int64)

Source from the content-addressed store, hash-verified

125}
126
127func (m *MultiFileStore) WriteAt(p []byte, off int64) (n int, err error) {
128 if len(p) == 0 {
129 return 0, nil
130 }
131 if off < 0 || off >= m.size {
132 return 0, io.ErrShortWrite
133 }
134
135 for _, b := range m.blocks {
136 if off >= b.size {
137 off -= b.size
138 continue
139 }
140
141 canWrite := min(len(p)-n, int(b.size-off))
142 if canWrite <= 0 {
143 break
144 }
145
146 nn, fileErr := b.file.WriteAt(p[n:n+canWrite], off)
147 if end := off + int64(nn); end > b.written {
148 b.written = end
149 }
150 n += nn
151 if fileErr != nil {
152 return n, fileErr
153 }
154 if nn < canWrite {
155 return n, io.ErrShortWrite
156 }
157 if n == len(p) {
158 return n, nil
159 }
160 off = 0
161 }
162
163 return n, io.ErrShortWrite
164}
165
166func NewFileStore(blockSize int64) (BackingStore, error) {
167 f, err := os.CreateTemp(conf.Conf.TempDir, "file-*")

Callers 1

TestMultiFileCacheFunction · 0.95

Calls 1

minFunction · 0.85

Tested by 1

TestMultiFileCacheFunction · 0.76