MCPcopy Index your code
hub / github.com/akalin/gopar / LoadFileData

Method LoadFileData

par2/decoder.go:389–455  ·  view source on GitHub ↗

LoadFileData loads existing file data into memory.

()

Source from the content-addressed store, hash-verified

387
388// LoadFileData loads existing file data into memory.
389func (d *Decoder) LoadFileData() error {
390 checksumToLocation := makeChecksumShardLocationMap(d.sliceByteCount, d.recoverySet)
391
392 fileIntegrityInfos := make([]fileIntegrityInfo, len(d.recoverySet))
393 fileIDIndices := make(map[fileID]int)
394 for i, info := range d.recoverySet {
395 fileIntegrityInfos[i] = fileIntegrityInfo{
396 fileID: info.fileID,
397 shardInfos: make([]shardIntegrityInfo, len(info.checksumPairs)),
398 }
399 fileIDIndices[info.fileID] = i
400 }
401
402 for i, info := range d.recoverySet {
403 path := d.getFilePath(info)
404 byteCount, hits, misses, err := d.fillFileIntegrityInfos(checksumToLocation, fileIntegrityInfos, fileIDIndices, i, info)
405 d.delegate.OnDataFileLoad(i+1, len(d.recoverySet), path, byteCount, hits, misses, err)
406 if err != nil {
407 return err
408 }
409
410 if byteCount != info.byteCount {
411 var startByteOffset, endByteOffset int
412 if byteCount < info.byteCount {
413 startByteOffset = byteCount
414 endByteOffset = info.byteCount
415 } else {
416 startByteOffset = info.byteCount
417 endByteOffset = byteCount
418 }
419 d.delegate.OnDetectCorruptDataChunk(info.fileID, path, startByteOffset, endByteOffset)
420 }
421 }
422
423 for i, info := range d.recoverySet {
424 integrityInfo := fileIntegrityInfos[i]
425 corruptStartByteOffset := -1
426 corruptEndByteOffset := -1
427 for j, shardInfo := range integrityInfo.shardInfos {
428 startByteOffset := j * d.sliceByteCount
429 endByteOffset := startByteOffset + d.sliceByteCount
430 if endByteOffset > info.byteCount {
431 endByteOffset = info.byteCount
432 }
433 if shardInfo.ok(shardLocation{info.fileID, startByteOffset}) {
434 if corruptStartByteOffset != -1 {
435 d.delegate.OnDetectCorruptDataChunk(info.fileID, d.getFilePath(info), corruptStartByteOffset, corruptEndByteOffset)
436 corruptStartByteOffset = -1
437 corruptEndByteOffset = -1
438 }
439 } else {
440 if corruptStartByteOffset == -1 {
441 corruptStartByteOffset = startByteOffset
442 }
443 corruptEndByteOffset = endByteOffset
444 }
445 }
446

Callers 13

repairFunction · 0.45
testCreateFunction · 0.45
verifyFunction · 0.45
createFunction · 0.45
TestEncodeParityFunction · 0.45
testWriteParityFunction · 0.45
testShardCountsFunction · 0.45
testDecoderVerifyFunction · 0.45
TestSetIDMismatchFunction · 0.45
testDecoderRepairFunction · 0.45
TestRepairAddedBytesFunction · 0.45
TestRepairRemovedBytesFunction · 0.45

Calls 6

getFilePathMethod · 0.95
OnDataFileLoadMethod · 0.65
okMethod · 0.45

Tested by 10

testCreateFunction · 0.36
TestEncodeParityFunction · 0.36
testWriteParityFunction · 0.36
testShardCountsFunction · 0.36
testDecoderVerifyFunction · 0.36
TestSetIDMismatchFunction · 0.36
testDecoderRepairFunction · 0.36
TestRepairAddedBytesFunction · 0.36
TestRepairRemovedBytesFunction · 0.36
TestRepairSwappedFilesFunction · 0.36