diff options
Diffstat (limited to 'formats/idxfile/encoder.go')
-rw-r--r-- | formats/idxfile/encoder.go | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/formats/idxfile/encoder.go b/formats/idxfile/encoder.go index 6a61137..e9b0338 100644 --- a/formats/idxfile/encoder.go +++ b/formats/idxfile/encoder.go @@ -65,25 +65,24 @@ func (e *Encoder) encodeFanout(idx *Idxfile) (int, error) { } func (e *Encoder) encodeHashes(idx *Idxfile) (int, error) { - return e.encodeEntryField(idx, true) -} + sz := 0 + for _, ent := range idx.Entries { + i, err := e.Write(ent.Hash[:]) + sz += i -func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) { - return e.encodeEntryField(idx, false) + if err != nil { + return sz, err + } + } + + return sz, nil } -func (e *Encoder) encodeEntryField(idx *Idxfile, isHash bool) (int, error) { +func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) { sz := 0 for _, ent := range idx.Entries { - var data []byte - if isHash { - data = ent.Hash[:] - } else { - data = ent.CRC32[:] - } - - i, err := e.Write(data) - sz += i + err := binary.Write(e, binary.BigEndian, ent.CRC32) + sz += 4 if err != nil { return sz, err |