Add CRC Checksum checks on reading values back

This commit is contained in:
James Mills 2019-03-16 12:16:23 +10:00
parent 120e854444
commit e9c858d43f
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

@ -2,6 +2,7 @@ package bitcask
import (
"fmt"
"hash/crc32"
"io"
"io/ioutil"
"os"
@ -61,6 +62,11 @@ func (b *Bitcask) Get(key string) ([]byte, error) {
return nil, err
}
crc := crc32.ChecksumIEEE(e.Value)
if crc != e.CRC {
return nil, fmt.Errorf("error: crc checksum falied %s %d != %d", key, e.CRC, crc)
}
return e.Value, nil
}