github.com/docker-library/go-dockerlibrary@v0.0.0-20200821205225-669fbe5c1d52/manifest/parse.go (about) 1 package manifest 2 3 import ( 4 "bytes" 5 "io" 6 ) 7 8 // try parsing as a 2822 manifest, but fallback to line-based if that fails 9 func Parse(reader io.Reader) (*Manifest2822, error) { 10 buf := &bytes.Buffer{} 11 12 // try parsing as 2822, but also copy back into a new buffer so that if it fails, we can re-parse as line-based 13 manifest, err2822 := Parse2822(io.TeeReader(reader, buf)) 14 if err2822 != nil { 15 manifest, err := ParseLineBased(buf) 16 if err != nil { 17 // if we fail parsing line-based, eat the error and return the 2822 parsing error instead 18 // https://github.com/docker-library/bashbrew/issues/16 19 return nil, err2822 20 } 21 return manifest, nil 22 } 23 24 return manifest, nil 25 }