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

Method Read

ethstorage/data_file.go:156–172  ·  view source on GitHub ↗

Read raw chunk data from the storage file.

(chunkIdx uint64, len int)

Source from the content-addressed store, hash-verified

154
155// Read raw chunk data from the storage file.
156func (df *DataFile) Read(chunkIdx uint64, len int) ([]byte, error) {
157 if !df.Contains(chunkIdx) {
158 return nil, fmt.Errorf("chunk not found")
159 }
160 if len > int(df.chunkSize) {
161 return nil, fmt.Errorf("read too large")
162 }
163 md := make([]byte, len)
164 n, err := df.file.ReadAt(md, HEADER_SIZE+int64(chunkIdx-df.chunkIdxStart)*int64(df.chunkSize))
165 if err != nil {
166 return nil, err
167 }
168 if n != len {
169 return nil, fmt.Errorf("not full read")
170 }
171 return md, nil
172}
173
174// Read raw chunk data from the storage file.
175func (df *DataFile) ReadSample(sampleIdx uint64) (common.Hash, error) {

Callers 1

runChunkReadFunction · 0.95

Calls 1

ContainsMethod · 0.95

Tested by

no test coverage detected