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

Method fillFileIntegrityInfos

par2/decoder.go:361–386  ·  view source on GitHub ↗
(checksumToLocation checksumShardLocationMap, fileIntegrityInfos []fileIntegrityInfo, fileIDIndices map[fileID]int, i int, info decoderInputFileInfo)

Source from the content-addressed store, hash-verified

359}
360
361func (d *Decoder) fillFileIntegrityInfos(checksumToLocation checksumShardLocationMap, fileIntegrityInfos []fileIntegrityInfo, fileIDIndices map[fileID]int, i int, info decoderInputFileInfo) (int, int, int, error) {
362 path := d.getFilePath(info)
363 data, err := d.fileIO.ReadFile(path)
364 if os.IsNotExist(err) {
365 fileIntegrityInfos[i].missing = true
366 return 0, 0, 0, nil
367 } else if err != nil {
368 return len(data), 0, 0, err
369 }
370
371 hits, misses := fillShardInfos(d.sliceByteCount, data, checksumToLocation, info.fileID, fileIntegrityInfos, fileIDIndices)
372
373 hashMismatch := sixteenKHash(data) != info.sixteenKHash || md5.Sum(data) != info.hash
374 fileIntegrityInfos[i].hashMismatch = hashMismatch
375 if hashMismatch {
376 d.delegate.OnDetectDataFileHashMismatch(info.fileID, path)
377 }
378
379 hasWrongByteCount := len(data) != info.byteCount
380 fileIntegrityInfos[i].hasWrongByteCount = hasWrongByteCount
381 if hasWrongByteCount {
382 d.delegate.OnDetectDataFileWrongByteCount(info.fileID, path)
383 }
384
385 return len(data), hits, misses, nil
386}
387
388// LoadFileData loads existing file data into memory.
389func (d *Decoder) LoadFileData() error {

Callers 1

LoadFileDataMethod · 0.95

Calls 6

getFilePathMethod · 0.95
fillShardInfosFunction · 0.85
sixteenKHashFunction · 0.70
ReadFileMethod · 0.65

Tested by

no test coverage detected