diff --git a/v2/Event.go b/v2/Event.go index 42be3918..5ff048ad 100644 --- a/v2/Event.go +++ b/v2/Event.go @@ -32,8 +32,8 @@ const ( EVT_AFTER_HEADER_DECODING = 8 // Compression header decoding ends EVT_HASH_NONE = 0 - EVT_HASH_32BITS = 1 - EVT_HASH_64BITS = 2 + EVT_HASH_32BITS = 32 + EVT_HASH_64BITS = 64 ) // Event a compression/decompression event diff --git a/v2/io/CompressedStream.go b/v2/io/CompressedStream.go index 855790ba..d0208cde 100644 --- a/v2/io/CompressedStream.go +++ b/v2/io/CompressedStream.go @@ -130,7 +130,8 @@ type encodingTaskResult struct { // Use headerless == false to create a bitstream without a header. The decompressor // must know all the compression parameters to be able to decompress the bitstream. // The headerless mode is only useful in very specific scenarios. -func NewWriter(os io.WriteCloser, transform, entropy string, blockSize, jobs uint, checksum bool, fileSize int64, headerless bool) (*Writer, error) { +// checksum must be 0, 32 or 64 +func NewWriter(os io.WriteCloser, transform, entropy string, blockSize, jobs uint, checksum uint, fileSize int64, headerless bool) (*Writer, error) { ctx := make(map[string]any) ctx["entropy"] = entropy ctx["transform"] = transform @@ -1791,7 +1792,7 @@ func (this *decodingTask) decode(res *decodingTaskResult) { res.err = &IOError{msg: errMsg, code: kanzi.ERR_CRC_CHECK} return } - } else if this.hasher32 != nil { + } else if this.hasher64 != nil { checksum2 := this.hasher64.Hash(data[0:decoded]) if checksum2 != checksum1 { diff --git a/v2/io/CompressedStream_test.go b/v2/io/CompressedStream_test.go index f66e3912..d184f630 100644 --- a/v2/io/CompressedStream_test.go +++ b/v2/io/CompressedStream_test.go @@ -115,7 +115,7 @@ func compress(block []byte, entropy, transform string) int { } // Create a Writer - w, err2 := NewWriter(output, transform, entropy, blockSize, jobs, true, 0, false) + w, err2 := NewWriter(output, transform, entropy, blockSize, jobs, 32, 0, false) if err2 != nil { fmt.Printf("%v\n", err2) @@ -186,7 +186,7 @@ func compressAfterWriteClose(block []byte) int { copy(buf, block) bs := internal.NewBufferStream() - os, err := NewWriter(bs, "NONE", "HUFFMAN", uint(len(block)), 1, false, 0, false) + os, err := NewWriter(bs, "NONE", "HUFFMAN", uint(len(block)), 1, 0, 0, false) if err != nil { fmt.Printf("%v\n", err) @@ -219,7 +219,7 @@ func compressAfterReadClose(block []byte) int { fmt.Println("Test - read after close") bs := internal.NewBufferStream() - os, err := NewWriter(bs, "NONE", "NONE", uint(len(block)), 1, false, 0, false) + os, err := NewWriter(bs, "NONE", "NONE", uint(len(block)), 1, 0, 0, false) if err != nil { fmt.Printf("%v\n", err)