1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

image: stream img JSON & Decode in LoadImage

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack 2014-11-04 15:45:46 +02:00
parent 4bc28f4e6b
commit 4dbbe4f51a

View file

@ -38,14 +38,18 @@ type Image struct {
}
func LoadImage(root string) (*Image, error) {
// Load the json data
jsonData, err := ioutil.ReadFile(jsonPath(root))
// Open the JSON file to decode by streaming
jsonSource, err := os.Open(jsonPath(root))
if err != nil {
return nil, err
}
img := &Image{}
defer jsonSource.Close()
if err := json.Unmarshal(jsonData, img); err != nil {
img := &Image{}
dec := json.NewDecoder(jsonSource)
// Decode the JSON data
if err := dec.Decode(img); err != nil {
return nil, err
}
if err := utils.ValidateID(img.ID); err != nil {