diff --git a/.circleci/config.yml b/.circleci/config.yml index 9a0d53d..f341c3c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -89,15 +89,6 @@ jobs: - run: 'unzip mr.zip' - run: 'go build -tags external_libzstd' - run: 'PAYLOAD=`pwd`/mr GODEBUG=efence=1 go test -tags external_libzstd -v' - "golang-zstd-legacy-support": - docker: - - image: circleci/golang:latest - steps: - - checkout - - run: 'wget https://github.com/DataDog/zstd/files/2246767/mr.zip' - - run: 'unzip mr.zip' - - run: 'CGO_CFLAGS="-DZSTD_LEGACY_SUPPORT=1" go build' - - run: 'PAYLOAD=`pwd`/mr CGO_CFLAGS="-DZSTD_LEGACY_SUPPORT=1" go test -v' "golang-i386": docker: - image: 32bit/ubuntu:16.04 @@ -118,4 +109,3 @@ workflows: - "golang-efence" - "golang-efence-external-libzstd" - "golang-i386" - - "golang-zstd-legacy-support" diff --git a/zstd.go b/zstd.go index cfa7ed6..d4c7398 100644 --- a/zstd.go +++ b/zstd.go @@ -1,6 +1,11 @@ package zstd /* +// support decoding of "legacy" zstd payloads from versions [0.4, 0.8], matching the +// default configuration of the zstd command line tool: +// https://github.com/facebook/zstd/blob/dev/programs/README.md +#cgo CFLAGS: -DZSTD_LEGACY_SUPPORT=4 + #include "zstd.h" */ import "C" diff --git a/zstd_test.go b/zstd_test.go index e5bb2d2..399b69a 100644 --- a/zstd_test.go +++ b/zstd_test.go @@ -6,6 +6,8 @@ import ( "fmt" "io/ioutil" "os" + "strconv" + "strings" "testing" ) @@ -259,6 +261,29 @@ func TestRealPayload(t *testing.T) { } } +func TestLegacy(t *testing.T) { + // payloads compressed with zstd v0.5 + // needs ZSTD_LEGACY_SUPPORT=5 or less + testCases := []struct { + input string + expected string + }{ + {"%\xb5/\xfd\x00@\x00\x1bcompressed with legacy zstd\xc0\x00\x00", "compressed with legacy zstd"}, + {"%\xb5/\xfd\x00\x00\x00A\x11\x007\x14\xb0\xb5\x01@\x1aR\xb6iI7[FH\x022u\xe0O-\x18\xe3G\x9e2\xab\xd9\xea\xca7؊\xee\x884\xbf\xe7\xdc\xe4@\xe1-\x9e\xac\xf0\xf2\x86\x0f\xf1r\xbb7\b\x81Z\x01\x00\x01\x00\xdf`\xfe\xc0\x00\x00", "compressed with legacy zstd"}, + } + for i, testCase := range testCases { + t.Run(strconv.Itoa(i), func(t *testing.T) { + out, err := Decompress(nil, []byte(testCase.input)) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(out), testCase.expected) { + t.Errorf("expected to find %#v; output=%#v", testCase.expected, string(out)) + } + }) + } +} + func BenchmarkCompression(b *testing.B) { if raw == nil { b.Fatal(ErrNoPayloadEnv)