MCPcopy Create free account
hub / github.com/ethstorage/es-node / ReadSample

Method ReadSample

ethstorage/data_file.go:175–189  ·  view source on GitHub ↗

Read raw chunk data from the storage file.

(sampleIdx uint64)

Source from the content-addressed store, hash-verified

173
174// Read raw chunk data from the storage file.
175func (df *DataFile) ReadSample(sampleIdx uint64) (common.Hash, error) {
176 if !df.ContainsSample(sampleIdx) {
177 return common.Hash{}, fmt.Errorf("sample not found")
178 }
179 sampleSize := 1 << SampleSizeBits
180 md := make([]byte, sampleSize)
181 n, err := df.file.ReadAt(md, HEADER_SIZE+int64(sampleIdx<<SampleSizeBits)-int64(df.chunkIdxStart*df.chunkSize))
182 if err != nil {
183 return common.Hash{}, err
184 }
185 if n != sampleSize {
186 return common.Hash{}, fmt.Errorf("not full read")
187 }
188 return common.BytesToHash(md), nil
189}
190
191// Write the chunk bytes to the file.
192func (df *DataFile) Write(chunkIdx uint64, b []byte) error {

Callers

nothing calls this directly

Calls 1

ContainsSampleMethod · 0.95

Tested by

no test coverage detected