Skip to content

Commit

Permalink
zstd: Check ignoreChecksum option once
Browse files Browse the repository at this point in the history
Decoder.nextBlock no longer calls the checksum finalizer if not
necessary.
  • Loading branch information
greatroar committed Nov 23, 2022
1 parent 4af4108 commit eb034a2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions zstd/decoder.go
Expand Up @@ -459,7 +459,11 @@ func (d *Decoder) nextBlock(blocking bool) (ok bool) {
println("got", len(d.current.b), "bytes, error:", d.current.err, "data crc:", tmp)
}

if !d.o.ignoreChecksum && len(next.b) > 0 {
if d.o.ignoreChecksum {
return true
}

if len(next.b) > 0 {
n, err := d.current.crc.Write(next.b)
if err == nil {
if n != len(next.b) {
Expand All @@ -471,7 +475,7 @@ func (d *Decoder) nextBlock(blocking bool) (ok bool) {
got := d.current.crc.Sum64()
var tmp [4]byte
binary.LittleEndian.PutUint32(tmp[:], uint32(got))
if !d.o.ignoreChecksum && !bytes.Equal(tmp[:], next.d.checkCRC) {
if !bytes.Equal(tmp[:], next.d.checkCRC) {
if debugDecoder {
println("CRC Check Failed:", tmp[:], " (got) !=", next.d.checkCRC, "(on stream)")
}
Expand Down

0 comments on commit eb034a2

Please sign in to comment.