func ExtractImagesFromTarReader(tarReader *tar.Reader, imageFilenames map[string]struct{}) (map[string]image.Image, error) {

	lenImageFilenames := len(imageFilenames)
	out := make(map[string]image.Image)

	for {
		header, err := tarReader.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			return nil, err
		}

		if _, isWanted := imageFilenames[header.Name]; isWanted && header.Typeflag == tar.TypeReg {
			imageBytes, err := ioutil.ReadAll(tarReader)
			if err != nil {
				return nil, err
			}

			br := bytes.NewReader(imageBytes)
			newImg, err := DecodeImageFromReader(br)
			if err != nil {
				return nil, err
			}
			out[header.Name] = newImg

			if len(out) == lenImageFilenames {
				break
			}
		}
	}

	if len(out) != lenImageFilenames {
		return out, fmt.Errorf("ExtractImagesFromTarGz: found %d images but expected %d", len(out), lenImageFilenames)
	}

	return out, nil
}
// ExtractImagesFromTarReader consumes a .tar reader, loops over all files until
// it finds all images with the specified names, and returns those images in a
// named map. If it fails to find all requested files, it still returns the
// files it found, but also returns an error.
ExtractImagesFromTarReader consumes a .tar reader, loops over all files until
it finds all images with the specified names, and returns those images in a
named map. If it fails to find all requested files, it still returns the
files it found, but also returns an error.
// ExtractImagesFromTarReader consumes a . tar reader loops over all files until // it finds all images with the specified names and returns those images in a // named map . If it fails to find all requested files it still returns the // files it found but also returns an error .
func ExtractImagesFromTarReader(tarReader *tar.Reader, imageFilenames map[string]struct{}) (map[string]image.Image, error) {
	lenImageFilenames := len(imageFilenames)
	out := make(map[string]image.Image)
	for {
		header, err := tarReader.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			return nil, err
		}
		if _, isWanted := imageFilenames[header.Name]; isWanted && header.Typeflag == tar.TypeReg {
			imageBytes, err := ioutil.ReadAll(tarReader)
			if err != nil {
				return nil, err
			}
			br := bytes.NewReader(imageBytes)
			newImg, err := DecodeImageFromReader(br)
			if err != nil {
				return nil, err
			}
			out[header.Name] = newImg
			if len(out) == lenImageFilenames {
				break
			}
		}
	}
	if len(out) != lenImageFilenames {
		return out, fmt.Errorf("ExtractImagesFromTarGz: found %d images but expected %d", len(out), lenImageFilenames)
	}
	return out, nil
}
func ExtractImagesFromTarReader ( tarReader * tar . Reader , imageFilenames map [ string ] struct { } ) ( map [ string ] image . Image , error ) { lenImageFilenames := len ( imageFilenames ) out := make ( map [ string ] image . Image ) for { header , err := tarReader . Next ( ) if err == io . EOF { break } else if err != nil { return nil , err } if _ , isWanted := imageFilenames [ header . Name ] ; isWanted && header . Typeflag == tar . TypeReg { imageBytes , err := ioutil . ReadAll ( tarReader ) if err != nil { return nil , err } br := bytes . NewReader ( imageBytes ) newImg , err := DecodeImageFromReader ( br ) if err != nil { return nil , err } out [ header . Name ] = newImg if len ( out ) == lenImageFilenames { break } } } if len ( out ) != lenImageFilenames { return out , fmt . Errorf ( " " , len ( out ) , lenImageFilenames ) } return out , nil }
ExtractImagesFromTarReader consumes a .tar reader, loops over all files until
it finds all images with the specified names, and returns those images in a
named map.
ExtractImagesFromTarReader consumes a . tar reader loops over all files until it finds all images with the specified names and returns those images in a named map .