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) {
|
func newImportExportEcho(ctx context.Context, client *containerd.Client, expected []byte) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
testBuf := newWaitBuffer()
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -34,20 +34,22 @@ func init() {
|
|||||||
plugins.Register(&transfertypes.ImageImportStream{}, &ImageImportStream{})
|
plugins.Register(&transfertypes.ImageImportStream{}, &ImageImportStream{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageImportStream returns a image importer via tar stream
|
// NewImageExportStream returns a image importer via tar stream
|
||||||
// TODO: Add import options
|
// TODO: Add export options
|
||||||
func NewImageExportStream(stream io.WriteCloser) *ImageExportStream {
|
func NewImageExportStream(stream io.WriteCloser, mediaType string) *ImageExportStream {
|
||||||
return &ImageExportStream{
|
return &ImageExportStream{
|
||||||
stream: stream,
|
stream: stream,
|
||||||
|
mediaType: mediaType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageExportStream struct {
|
type ImageExportStream struct {
|
||||||
stream io.WriteCloser
|
stream io.WriteCloser
|
||||||
|
mediaType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iis *ImageExportStream) ExportStream(context.Context) (io.WriteCloser, error) {
|
func (iis *ImageExportStream) ExportStream(context.Context) (io.WriteCloser, string, error) {
|
||||||
return iis.stream, nil
|
return iis.stream, iis.mediaType, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iis *ImageExportStream) MarshalAny(ctx context.Context, sm streaming.StreamCreator) (typeurl.Any, error) {
|
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{
|
s := &transfertypes.ImageExportStream{
|
||||||
Stream: sid,
|
Stream: sid,
|
||||||
|
MediaType: iis.mediaType,
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeurl.MarshalAny(s)
|
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.stream = tstreaming.WriteByteStream(ctx, stream)
|
||||||
|
iis.mediaType = s.MediaType
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ type ImageImportStream struct {
|
|||||||
forceCompress bool
|
forceCompress bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iis *ImageImportStream) ImportStream(context.Context) (io.Reader, error) {
|
func (iis *ImageImportStream) ImportStream(context.Context) (io.Reader, string, error) {
|
||||||
return iis.stream, nil
|
return iis.stream, iis.mediaType, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iis *ImageImportStream) Import(ctx context.Context, store content.Store) (ocispec.Descriptor, error) {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
wc, err := e.ExportStream(ctx)
|
wc, _, err := e.ExportStream(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ type ImageImportStreamer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ImageExportStreamer interface {
|
type ImageExportStreamer interface {
|
||||||
ExportStream(context.Context) (io.WriteCloser, error)
|
ExportStream(context.Context) (io.WriteCloser, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageUnpacker interface {
|
type ImageUnpacker interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user