Support custom compressor for walking differ

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
ktock
2021-07-14 15:52:04 +09:00
parent 34fb8d8967
commit b483177ee2
2 changed files with 41 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ package diff
import (
"context"
"io"
"github.com/containerd/containerd/mount"
"github.com/gogo/protobuf/types"
@@ -37,6 +38,12 @@ type Config struct {
// Labels are the labels to apply to the generated content
Labels map[string]string
// Compressor is a function to compress the diff stream
// instead of the default gzip compressor. Differ passes
// the MediaType of the target diff content to the compressor.
// When using this config, MediaType must be specified as well.
Compressor func(dest io.Writer, mediaType string) (io.WriteCloser, error)
}
// Opt is used to configure a diff operation
@@ -71,6 +78,14 @@ type Applier interface {
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount, opts ...ApplyOpt) (ocispec.Descriptor, error)
}
// WithCompressor sets the function to be used to compress the diff stream.
func WithCompressor(f func(dest io.Writer, mediaType string) (io.WriteCloser, error)) Opt {
return func(c *Config) error {
c.Compressor = f
return nil
}
}
// WithMediaType sets the media type to use for creating the diff, without
// specifying the differ will choose a default.
func WithMediaType(m string) Opt {