-
Notifications
You must be signed in to change notification settings - Fork 1.4k
compression: add zstd:chunked compression type #6528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JakeCooper
wants to merge
1
commit into
moby:master
Choose a base branch
from
JakeCooper:zstd-chunked-compression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package compression | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
|
|
||
| "github.com/containerd/containerd/v2/core/content" | ||
| "github.com/containerd/containerd/v2/core/images" | ||
| chunkedcompressor "github.com/containers/storage/pkg/chunked/compressor" | ||
| ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
| ) | ||
|
|
||
| func (c zstdChunkedType) Compress(ctx context.Context, comp Config) (compressorFunc Compressor, finalize Finalizer) { | ||
| return func(dest io.Writer, _ string) (io.WriteCloser, error) { | ||
| level := 3 | ||
| if comp.Level != nil { | ||
| level = *comp.Level | ||
| } | ||
| return chunkedcompressor.ZstdCompressor(dest, nil, &level) | ||
| }, nil | ||
| } | ||
|
|
||
| func (c zstdChunkedType) Decompress(ctx context.Context, cs content.Store, desc ocispecs.Descriptor) (io.ReadCloser, error) { | ||
| // zstd:chunked is a valid zstd stream — standard decompression works. | ||
| return decompress(ctx, cs, desc) | ||
| } | ||
|
|
||
| func (c zstdChunkedType) NeedsConversion(ctx context.Context, cs content.Store, desc ocispecs.Descriptor) (bool, error) { | ||
| if !images.IsLayerType(desc.MediaType) { | ||
| return false, nil | ||
| } | ||
| ct, err := FromMediaType(desc.MediaType) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| // zstd:chunked uses the same media type as zstd, so if the layer is | ||
| // already zstd we skip conversion. The chunked structure is an | ||
| // optimization; re-encoding an existing zstd layer would require | ||
| // full decompression and recompression. | ||
| if ct == Zstd { | ||
| return false, nil | ||
| } | ||
| return true, nil | ||
| } | ||
|
|
||
| func (c zstdChunkedType) NeedsComputeDiffBySelf(comp Config) bool { | ||
| return true | ||
| } | ||
|
|
||
| func (c zstdChunkedType) OnlySupportOCITypes() bool { | ||
| return false | ||
| } | ||
|
|
||
| func (c zstdChunkedType) MediaType() string { | ||
| // zstd:chunked uses the same OCI media type as zstd — the chunked | ||
| // structure is transparent to registries and runtimes that don't | ||
| // understand it. They simply decompress it as a regular zstd blob. | ||
| return ocispecs.MediaTypeImageLayerZstd | ||
| } | ||
|
|
||
| func (c zstdChunkedType) String() string { | ||
| return "zstd:chunked" | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like we consume an unrelated package just for zstd compression for a module not directly aimed at compression. If anything I think it should be either vendored here with tests or use a proper module. Also
github.com/containers/storageis deprecated and has moved to https://github.com/containers/container-libs/tree/main/storage.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also vendor is not updated in your PR (
go mod vendor).