From feb0ff31704752d29a9e5373bf167678e7814db4 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Sat, 27 Jul 2024 23:32:34 +0200 Subject: [PATCH] feat: add support for zstd decoding --- api/unpack/index.go | 7 +++++++ default.nix | 2 +- go.mod | 1 + go.sum | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api/unpack/index.go b/api/unpack/index.go index 8beec6c..a22fc7e 100644 --- a/api/unpack/index.go +++ b/api/unpack/index.go @@ -16,6 +16,7 @@ import ( "github.com/numtide/nar-serve/pkg/narinfo" "github.com/ulikunitz/xz" + "github.com/klauspost/compress/zstd" ) // MountPath is where this handler is supposed to be mounted @@ -81,6 +82,12 @@ func Handler(w http.ResponseWriter, req *http.Request) { } case "bzip2": r = bzip2.NewReader(r) + case "zstd": + r, err = zstd.NewReader(r) + if err != nil { + http.Error(w, err.Error(), 500) + return + } default: http.Error(w, fmt.Sprintf("compression %s not handled", narinfo.Compression), 500) return diff --git a/default.nix b/default.nix index 85e7613..eb17099 100644 --- a/default.nix +++ b/default.nix @@ -7,7 +7,7 @@ rec { pname = "nar-serve"; version = "latest"; src = nixpkgs.lib.cleanSource ./.; - vendorHash = "sha256-KZ7dOwx52+2ljfedAMUR1FRv3kAO7Kl4y6wvjJeWdKc="; + vendorHash = "sha256-IfXhuVwZf43FcQQ+i77aJHWG0auHBaHnKgTQJKa0L/M="; doCheck = false; }; diff --git a/go.mod b/go.mod index e486040..543635a 100644 --- a/go.mod +++ b/go.mod @@ -29,6 +29,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect diff --git a/go.sum b/go.sum index 860af39..fcaf208 100644 --- a/go.sum +++ b/go.sum @@ -72,6 +72,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=