Пример #1
0
func findManifest(r io.Reader) ([]byte, error) {
	arch, err := tarhelper.DetectArchiveCompression(r)
	if err != nil {
		return nil, err
	}

	for {
		header, err := arch.Next()
		if err == io.EOF {
			return nil, fmt.Errorf("failed to locate manifest file")
		}
		if err != nil {
			return nil, err
		}

		if filepath.Clean(header.Name) != "manifest" {
			continue
		}

		b, err := ioutil.ReadAll(arch)
		if err != nil {
			return nil, err
		}
		return b, nil
	}
}
Пример #2
0
// findManifest retrieves the manifest from the provided reader and unmarshals
// it.
func findManifest(r io.Reader) (*schema.ImageManifest, error) {
	arch, err := tarhelper.DetectArchiveCompression(r)
	if err != nil {
		return nil, err
	}

	for {
		header, err := arch.Next()
		if err == io.EOF {
			return nil, fmt.Errorf("failed to locate manifest file")
		}
		if err != nil {
			return nil, err
		}

		if filepath.Clean(header.Name) != "manifest" {
			continue
		}

		var manifest *schema.ImageManifest
		if err := json.NewDecoder(arch).Decode(&manifest); err != nil {
			return nil, err
		}
		return manifest, nil
	}
}