diff --git a/integration/client/transfer_test.go b/integration/client/transfer_test.go index fa3d9f822..86ffa2006 100644 --- a/integration/client/transfer_test.go +++ b/integration/client/transfer_test.go @@ -45,7 +45,7 @@ func TestTransferEcho(t *testing.T) { func newImportExportEcho(ctx context.Context, client *containerd.Client, expected []byte) func(*testing.T) { return func(t *testing.T) { testBuf := newWaitBuffer() - err := client.Transfer(ctx, archive.NewImageImportStream(bytes.NewReader(expected), "application/octet-stream"), archive.NewImageExportStream(testBuf)) + err := client.Transfer(ctx, archive.NewImageImportStream(bytes.NewReader(expected), "application/octet-stream"), archive.NewImageExportStream(testBuf, "application/octet-stream")) if err != nil { t.Fatal(err) } diff --git a/pkg/transfer/archive/exporter.go b/pkg/transfer/archive/exporter.go index 18d928b92..1833e7f77 100644 --- a/pkg/transfer/archive/exporter.go +++ b/pkg/transfer/archive/exporter.go @@ -34,20 +34,22 @@ func init() { plugins.Register(&transfertypes.ImageImportStream{}, &ImageImportStream{}) } -// NewImageImportStream returns a image importer via tar stream -// TODO: Add import options -func NewImageExportStream(stream io.WriteCloser) *ImageExportStream { +// NewImageExportStream returns a image importer via tar stream +// TODO: Add export options +func NewImageExportStream(stream io.WriteCloser, mediaType string) *ImageExportStream { return &ImageExportStream{ - stream: stream, + stream: stream, + mediaType: mediaType, } } type ImageExportStream struct { - stream io.WriteCloser + stream io.WriteCloser + mediaType string } -func (iis *ImageExportStream) ExportStream(context.Context) (io.WriteCloser, error) { - return iis.stream, nil +func (iis *ImageExportStream) ExportStream(context.Context) (io.WriteCloser, string, error) { + return iis.stream, iis.mediaType, nil } func (iis *ImageExportStream) MarshalAny(ctx context.Context, sm streaming.StreamCreator) (typeurl.Any, error) { @@ -66,7 +68,8 @@ func (iis *ImageExportStream) MarshalAny(ctx context.Context, sm streaming.Strea }() s := &transfertypes.ImageExportStream{ - Stream: sid, + Stream: sid, + MediaType: iis.mediaType, } return typeurl.MarshalAny(s) @@ -85,6 +88,7 @@ func (iis *ImageExportStream) UnmarshalAny(ctx context.Context, sm streaming.Str } iis.stream = tstreaming.WriteByteStream(ctx, stream) + iis.mediaType = s.MediaType return nil } diff --git a/pkg/transfer/archive/importer.go b/pkg/transfer/archive/importer.go index 4c37ec7cf..75effa1f9 100644 --- a/pkg/transfer/archive/importer.go +++ b/pkg/transfer/archive/importer.go @@ -54,8 +54,8 @@ type ImageImportStream struct { forceCompress bool } -func (iis *ImageImportStream) ImportStream(context.Context) (io.Reader, error) { - return iis.stream, nil +func (iis *ImageImportStream) ImportStream(context.Context) (io.Reader, string, error) { + return iis.stream, iis.mediaType, nil } func (iis *ImageImportStream) Import(ctx context.Context, store content.Store) (ocispec.Descriptor, error) { diff --git a/pkg/transfer/local/transfer.go b/pkg/transfer/local/transfer.go index 05cd29615..ca360cde0 100644 --- a/pkg/transfer/local/transfer.go +++ b/pkg/transfer/local/transfer.go @@ -108,7 +108,7 @@ func (ts *localTransferService) echo(ctx context.Context, i transfer.ImageImport if err != nil { return err } - wc, err := e.ExportStream(ctx) + wc, _, err := e.ExportStream(ctx) if err != nil { return err } diff --git a/pkg/transfer/transfer.go b/pkg/transfer/transfer.go index 971f7f145..71c6ee3d6 100644 --- a/pkg/transfer/transfer.go +++ b/pkg/transfer/transfer.go @@ -81,7 +81,7 @@ type ImageImportStreamer interface { } type ImageExportStreamer interface { - ExportStream(context.Context) (io.WriteCloser, error) + ExportStream(context.Context) (io.WriteCloser, string, error) } type ImageUnpacker interface {