Add media type to export stream
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
52341a2343
commit
0762a3a759
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
mediaType: mediaType,
|
||||
}
|
||||
}
|
||||
|
||||
type ImageExportStream struct {
|
||||
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) {
|
||||
@ -67,6 +69,7 @@ func (iis *ImageExportStream) MarshalAny(ctx context.Context, sm streaming.Strea
|
||||
|
||||
s := &transfertypes.ImageExportStream{
|
||||
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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user