MCPcopy Create free account
hub / github.com/akalin/gopar / LoadFileData

Method LoadFileData

par1/decoder.go:129–178  ·  view source on GitHub ↗

LoadFileData loads existing file data into memory.

()

Source from the content-addressed store, hash-verified

127
128// LoadFileData loads existing file data into memory.
129func (d *Decoder) LoadFileData() error {
130 fileData := make([][]byte, 0, len(d.indexVolume.entries))
131
132 for i, entry := range d.indexVolume.entries {
133 if !entry.header.Status.savedInVolumeSet() {
134 continue
135 }
136
137 path, err := d.getFilePath(entry)
138 if err != nil {
139 return err
140 }
141
142 data, corrupt, err := func() ([]byte, bool, error) {
143 data, err := d.fileIO.ReadFile(path)
144 if os.IsNotExist(err) {
145 return nil, true, err
146 } else if err != nil {
147 return nil, false, err
148 } else if sixteenKHash(data) != entry.header.SixteenKHash {
149 return nil, true, errors.New("hash mismatch (16k)")
150 } else if md5.Sum(data) != entry.header.Hash {
151 return nil, true, errors.New("hash mismatch")
152 }
153 return data, false, nil
154 }()
155 d.delegate.OnDataFileLoad(i+1, len(d.indexVolume.entries), path, len(data), corrupt, err)
156 if corrupt {
157 fileData = append(fileData, nil)
158 continue
159 } else if err != nil {
160 return err
161 }
162
163 // We use nil to mark missing entries, but ReadFile
164 // might return nil, so convert that to a non-nil
165 // empty slice.
166 if data == nil {
167 data = make([]byte, 0)
168 }
169 fileData = append(fileData, data)
170 }
171
172 if len(fileData) == 0 {
173 return errors.New("no file data found")
174 }
175
176 d.fileData = fileData
177 return nil
178}
179
180func (d *Decoder) volumePath(volumeNumber uint64) string {
181 if volumeNumber == 0 {

Callers 11

repairFunction · 0.45
testCreateFunction · 0.45
verifyFunction · 0.45
createFunction · 0.45
TestEncodeParityFunction · 0.45
testWriteParityFunction · 0.45
testFileCountsFunction · 0.45
testVerifyAllDataFunction · 0.45
TestBadFilenameFunction · 0.45
TestSetHashMismatchFunction · 0.45
testDecoderRepairFunction · 0.45

Calls 5

getFilePathMethod · 0.95
savedInVolumeSetMethod · 0.80
sixteenKHashFunction · 0.70
ReadFileMethod · 0.65
OnDataFileLoadMethod · 0.65

Tested by 8

testCreateFunction · 0.36
TestEncodeParityFunction · 0.36
testWriteParityFunction · 0.36
testFileCountsFunction · 0.36
testVerifyAllDataFunction · 0.36
TestBadFilenameFunction · 0.36
TestSetHashMismatchFunction · 0.36
testDecoderRepairFunction · 0.36