Merge pull request #41759 from giuseppe/zstd-compression
compression: add support for the zstd algorithm
This commit is contained in:
commit
6014c1e29d
|
@ -276,7 +276,8 @@ RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \
|
||||||
vim-common \
|
vim-common \
|
||||||
xfsprogs \
|
xfsprogs \
|
||||||
xz-utils \
|
xz-utils \
|
||||||
zip
|
zip \
|
||||||
|
zstd
|
||||||
|
|
||||||
|
|
||||||
# Switch to use iptables instead of nftables (to match the CI hosts)
|
# Switch to use iptables instead of nftables (to match the CI hosts)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/pools"
|
"github.com/docker/docker/pkg/pools"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
|
"github.com/klauspost/compress/zstd"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
exec "golang.org/x/sys/execabs"
|
exec "golang.org/x/sys/execabs"
|
||||||
)
|
)
|
||||||
|
@ -83,6 +84,8 @@ const (
|
||||||
Gzip
|
Gzip
|
||||||
// Xz is xz compression algorithm.
|
// Xz is xz compression algorithm.
|
||||||
Xz
|
Xz
|
||||||
|
// Zstd is zstd compression algorithm.
|
||||||
|
Zstd
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -127,6 +130,7 @@ func DetectCompression(source []byte) Compression {
|
||||||
Bzip2: {0x42, 0x5A, 0x68},
|
Bzip2: {0x42, 0x5A, 0x68},
|
||||||
Gzip: {0x1F, 0x8B, 0x08},
|
Gzip: {0x1F, 0x8B, 0x08},
|
||||||
Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
|
Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
|
||||||
|
Zstd: {0x28, 0xb5, 0x2f, 0xfd},
|
||||||
} {
|
} {
|
||||||
if bytes.HasPrefix(source, m) {
|
if bytes.HasPrefix(source, m) {
|
||||||
return compression
|
return compression
|
||||||
|
@ -215,6 +219,13 @@ func DecompressStream(archive io.Reader) (io.ReadCloser, error) {
|
||||||
}
|
}
|
||||||
readBufWrapper := p.NewReadCloserWrapper(buf, xzReader)
|
readBufWrapper := p.NewReadCloserWrapper(buf, xzReader)
|
||||||
return wrapReadCloser(readBufWrapper, cancel), nil
|
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:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension())
|
return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension())
|
||||||
}
|
}
|
||||||
|
@ -341,6 +352,8 @@ func (compression *Compression) Extension() string {
|
||||||
return "tar.gz"
|
return "tar.gz"
|
||||||
case Xz:
|
case Xz:
|
||||||
return "tar.xz"
|
return "tar.xz"
|
||||||
|
case Zstd:
|
||||||
|
return "tar.zst"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,13 @@ func TestDecompressStreamXz(t *testing.T) {
|
||||||
testDecompressStream(t, "xz", "xz -f")
|
testDecompressStream(t, "xz", "xz -f")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecompressStreamZstd(t *testing.T) {
|
||||||
|
if _, err := exec.LookPath("zstd"); err != nil {
|
||||||
|
t.Skip("zstd not installed")
|
||||||
|
}
|
||||||
|
testDecompressStream(t, "zst", "zstd -f")
|
||||||
|
}
|
||||||
|
|
||||||
func TestCompressStreamXzUnsupported(t *testing.T) {
|
func TestCompressStreamXzUnsupported(t *testing.T) {
|
||||||
dest, err := os.Create(tmp + "dest")
|
dest, err := os.Create(tmp + "dest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -210,6 +217,13 @@ func TestExtensionXz(t *testing.T) {
|
||||||
t.Fatalf("The extension of a xz archive should be 'tar.xz'")
|
t.Fatalf("The extension of a xz archive should be 'tar.xz'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestExtensionZstd(t *testing.T) {
|
||||||
|
compression := Zstd
|
||||||
|
output := compression.Extension()
|
||||||
|
if output != "tar.zst" {
|
||||||
|
t.Fatalf("The extension of a zstd archive should be 'tar.zst'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCmdStreamLargeStderr(t *testing.T) {
|
func TestCmdStreamLargeStderr(t *testing.T) {
|
||||||
cmd := exec.Command("sh", "-c", "dd if=/dev/zero bs=1k count=1000 of=/dev/stderr; echo hello")
|
cmd := exec.Command("sh", "-c", "dd if=/dev/zero bs=1k count=1000 of=/dev/stderr; echo hello")
|
||||||
|
|
Loading…
Reference in New Issue