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

Function newDecoder

par1/decoder.go:66–103  ·  view source on GitHub ↗
(fileIO fileIO, delegate DecoderDelegate, indexFile string)

Source from the content-addressed store, hash-verified

64}
65
66func newDecoder(fileIO fileIO, delegate DecoderDelegate, indexFile string) (*Decoder, error) {
67 indexVolume, err := func() (volume, error) {
68 bytes, err := fileIO.ReadFile(indexFile)
69 if err != nil {
70 return volume{}, err
71 }
72
73 indexVolume, err := readVolume(bytes)
74 if err != nil {
75 return volume{}, err
76 }
77
78 if indexVolume.header.VolumeNumber != 0 {
79 // TODO: Relax this check.
80 return volume{}, errors.New("expected volume number 0 for index volume")
81 }
82 return indexVolume, nil
83 }()
84 delegate.OnVolumeFileLoad(0, indexFile, indexVolume.header.SetHash, indexVolume.setHash, len(indexVolume.data), err)
85 if err != nil {
86 return nil, err
87 }
88
89 delegate.OnHeaderLoad(indexVolume.header.String())
90 for i, entry := range indexVolume.entries {
91 delegate.OnFileEntryLoad(i+1, len(indexVolume.entries), entry.filename, entry.header.String())
92 }
93 // The comment could be in any encoding, so just pass it
94 // through as bytes.
95 delegate.OnCommentLoad(indexVolume.data)
96
97 return &Decoder{
98 fileIO, delegate,
99 indexFile, indexVolume,
100 nil,
101 0, nil,
102 }, nil
103}
104
105// NewDecoder reads the given index file, which usually has a .PAR
106// extension.

Callers 6

NewDecoderFunction · 0.70
repairFunction · 0.70
testCreateFunction · 0.70
verifyFunction · 0.70
testWriteParityFunction · 0.70
newDecoderForTestFunction · 0.70

Calls 7

readVolumeFunction · 0.85
ReadFileMethod · 0.65
OnVolumeFileLoadMethod · 0.65
OnHeaderLoadMethod · 0.65
OnFileEntryLoadMethod · 0.65
OnCommentLoadMethod · 0.65
StringMethod · 0.45

Tested by 3

testCreateFunction · 0.56
testWriteParityFunction · 0.56
newDecoderForTestFunction · 0.56