func MultiWrite(tagToImage map[name.Tag]v1.Image, w io.Writer) error {
	tf := tar.NewWriter(w)
	defer tf.Close()
	imageToTags := dedupTagToImage(tagToImage)
	var td tarDescriptor
	for img, tags := range imageToTags {
		cfgName, err := img.ConfigName()
		if err != nil {
			return err
		}
		cfgBlob, err := img.RawConfigFile()
		if err != nil {
			return err
		}
		if err := writeTarEntry(tf, cfgName.String(), bytes.NewReader(cfgBlob), int64(len(cfgBlob))); err != nil {
			return err
		}
		layers, err := img.Layers()
		if err != nil {
			return err
		}
		layerFiles := make([]string, len(layers))
		for i, l := range layers {
			d, err := l.Digest()
			if err != nil {
				return err
			}
			hex := d.Hex
			layerFiles[i] = fmt.Sprintf("%s.tar.gz", hex)
			r, err := l.Compressed()
			if err != nil {
				return err
			}
			blobSize, err := l.Size()
			if err != nil {
				return err
			}
			if err := writeTarEntry(tf, layerFiles[i], r, blobSize); err != nil {
				return err
			}
		}
		sitd := singleImageTarDescriptor{
			Config:   cfgName.String(),
			RepoTags: tags,
			Layers:   layerFiles,
		}
		td = append(td, sitd)
	}
	tdBytes, err := json.Marshal(td)
	if err != nil {
		return err
	}
	return writeTarEntry(tf, "manifest.json", bytes.NewReader(tdBytes), int64(len(tdBytes)))
}
MultiWrite writes the contents of each image to the provided reader, in the compressed format.
The contents are written in the following format:
One manifest.json file at the top level containing information about several images.
One file for each layer, named after the layer's SHA.
One file for the config blob, named after its SHA.
package tarball
import (
	"archive/tar"
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"github.com/google/go-containerregistry/pkg/name"
	v1 "github.com/google/go-containerregistry/pkg/v1"
)
func WriteToFile(p string, tag name.Tag, img v1.Image) error {
	w, err := os.Create(p)
	if err != nil {
		return err
	}
	defer w.Close()
	return Write(tag, img, w)
}
func MultiWriteToFile(p string, tagToImage map[name.Tag]v1.Image) error {
	w, err := os.Create(p)
	if err != nil {
		return err
	}
	defer w.Close()
	return MultiWrite(tagToImage, w)
}
func Write(tag name.Tag, img v1.Image, w io.Writer) error {
	return MultiWrite(map[name.Tag]v1.Image{tag: img}, w)
}