From 0358f77823ffa3ca74ce389d95d713a755cce7d6 Mon Sep 17 00:00:00 2001 From: vicanso Date: Sun, 5 Mar 2023 14:08:11 +0800 Subject: [PATCH] chore: update snappy package --- .github/workflows/test.yml | 2 +- go.mod | 5 ++--- go.sum | 9 ++++----- snappy.go | 16 ++++++++++++++-- snappy_test.go | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 184c966..f4aceb6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: go-version: ${{ matrix.go }} - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Get dependencies run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin latest diff --git a/go.mod b/go.mod index 0f2643d..ab349ce 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/vicanso/elton-compress go 1.17 require ( - github.com/golang/snappy v0.0.4 - github.com/klauspost/compress v1.15.15 + github.com/klauspost/compress v1.16.0 github.com/pierrec/lz4 v2.6.1+incompatible - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.8.2 github.com/vicanso/elton v1.10.0 ) diff --git a/go.sum b/go.sum index 7a36a88..5205d8b 100644 --- a/go.sum +++ b/go.sum @@ -6,12 +6,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= -github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= +github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= +github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -30,8 +28,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/snappy.go b/snappy.go index 975b4c5..a2df8fd 100644 --- a/snappy.go +++ b/snappy.go @@ -26,7 +26,8 @@ import ( "bytes" "io" - "github.com/golang/snappy" + "github.com/klauspost/compress/s2" + "github.com/klauspost/compress/snappy" "github.com/vicanso/elton" "github.com/vicanso/elton/middleware" ) @@ -63,7 +64,18 @@ func (s *SnappyCompressor) Accept(c *elton.Context, bodySize int) (acceptable bo // Compress snappy compress func (s *SnappyCompressor) Compress(buf []byte, levels ...int) (*bytes.Buffer, error) { var dst []byte - data := snappy.Encode(dst, buf) + fn := snappy.Encode + if len(levels) != 0 { + switch levels[0] { + case 1: + fn = s2.EncodeSnappy + case 2: + fn = s2.EncodeSnappyBetter + case 3: + fn = s2.EncodeSnappyBest + } + } + data := fn(dst, buf) return bytes.NewBuffer(data), nil } diff --git a/snappy_test.go b/snappy_test.go index af10546..551b8ad 100644 --- a/snappy_test.go +++ b/snappy_test.go @@ -29,7 +29,7 @@ import ( "net/http/httptest" "testing" - "github.com/golang/snappy" + "github.com/klauspost/compress/snappy" "github.com/stretchr/testify/assert" "github.com/vicanso/elton" )