From 253552413231e1bb78581ddf5bc6588c1ba3405e Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 19 Feb 2022 21:59:47 +0100 Subject: [PATCH] debug: Add support for compressed blobs --- cmd/restic/cmd_debug.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index d144c751f..4c856c8ac 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -15,6 +15,7 @@ import ( "sort" "time" + "github.com/klauspost/compress/zstd" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" @@ -309,6 +310,10 @@ func decryptUnsigned(ctx context.Context, k *crypto.Key, buf []byte) []byte { } func loadBlobs(ctx context.Context, repo restic.Repository, pack restic.ID, list []restic.Blob) error { + dec, err := zstd.NewReader(nil) + if err != nil { + panic(err) + } be := repo.Backend() h := restic.Handle{ Name: pack.String(), @@ -353,6 +358,16 @@ func loadBlobs(ctx context.Context, repo restic.Repository, pack restic.ID, list } } + if blob.IsCompressed() { + decompressed, err := dec.DecodeAll(plaintext, nil) + if err != nil { + Printf(" failed to decompress blob %v\n", blob.ID) + } + if decompressed != nil { + plaintext = decompressed + } + } + id := restic.Hash(plaintext) var prefix string if !id.Equal(blob.ID) {