Skip to content

Commit

Permalink
compression: add support for the zstd algorithm
Browse files Browse the repository at this point in the history
zstd is a compression algorithm that has a very fast decoder, while
providing also good compression ratios.  The fast decoder makes it
suitable for container images, as decompressing the tarballs is a very
expensive operation.

opencontainers/image-spec#788 added support
for zstd to the OCI image specs.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Dec 8, 2020
1 parent eeddea2 commit 34dfd5d
Show file tree
Hide file tree
Showing 65 changed files with 17,354 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/archive/archive.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/system"
"github.com/klauspost/compress/zstd"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -84,6 +85,8 @@ const (
Gzip
// Xz is xz compression algorithm.
Xz
// Zstd is zstd compression algorithm.
Zstd
)

const (
Expand Down Expand Up @@ -128,6 +131,7 @@ func DetectCompression(source []byte) Compression {
Bzip2: {0x42, 0x5A, 0x68},
Gzip: {0x1F, 0x8B, 0x08},
Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
Zstd: {0x28, 0xb5, 0x2f, 0xfd},
} {
if len(source) < len(m) {
logrus.Debug("Len too short")
Expand Down Expand Up @@ -225,6 +229,14 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
}
readBufWrapper := p.NewReadCloserWrapper(buf, xzReader)
return wrapReadCloser(readBufWrapper, cancel), nil
case Zstd:
zstdReader, err := zstd.NewReader(buf)
if err != nil {
return nil, err
}
readBufWrapper := p.NewReadCloserWrapper(buf, zstdReader)
return readBufWrapper, nil

default:
return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension())
}
Expand Down
3 changes: 3 additions & 0 deletions vendor.conf
Expand Up @@ -179,6 +179,9 @@ github.com/docker/go-metrics b619b3592b65de4f087d9f16863a
github.com/opencontainers/selinux 25504e34a9826d481f6e2903963ecaa881749124 # v1.6.0
github.com/willf/bitset 559910e8471e48d76d9e5a1ba15842dee77ad45d # v1.1.11

# zstd
github.com/klauspost/compress ff4a4acf3be7ac7b0b1c3381000e0216eb9e956f # v1.11.3


# archive/tar
# rm -rf vendor/archive
Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/klauspost/compress/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

339 changes: 339 additions & 0 deletions vendor/github.com/klauspost/compress/README.md

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions vendor/github.com/klauspost/compress/fse/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 122 additions & 0 deletions vendor/github.com/klauspost/compress/fse/bitreader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34dfd5d

Please sign in to comment.