Skip to content

Add a way to enable checksums #43

@bobrik

Description

@bobrik

What did you do?

I compressed an empty file with zstd:

$ touch empty

$ zstd empty
empty                :1300.00%   (     0 =>     13 bytes, empty.zst)

Then I compressed an empty slice in Go:

package main

import (
	"log"

	"github.com/DataDog/zstd"
)

func main() {
	input := []byte{}

	output, err := zstd.CompressLevel(nil, input, 0)
	if err != nil {
		log.Fatalf("Error compressing: %s", err)
	}

	log.Printf("input      [len = %d]: %#v", len(input), input)
	log.Printf("compressed [len = %d]: %#v", len(output), output)
}

What did you expect to see?

Both outputs are the same.

What did you see instead?

13 bytes in zstd cli output:

$ ls -la empty*
-rw-r--r--  1 bobrik  wheel   0 Oct  1 11:07 empty
-rw-r--r--  1 bobrik  wheel  13 Oct  1 11:07 empty.zst

$ cat empty.zst | hexdump -C
00000000  28 b5 2f fd 24 00 01 00  00 99 e9 d8 51           |(./.$.......Q|
0000000d

9 bytes in Go output:

$ go run zstd.go
2018/10/01 11:09:09 input      [len = 0]: []byte{}
2018/10/01 11:09:09 compressed [len = 9]: []byte{0x28, 0xb5, 0x2f, 0xfd, 0x20, 0x0, 0x1, 0x0, 0x0}

Last 4 bytes are missing, which means no optional checksum:

Checksums are great and I think there should be a way to enable them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions