Skip to content

Commit

Permalink
image: stream img JSON & Decode in LoadImage
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <[email protected]> (github: unclejack)
  • Loading branch information
unclejack committed Nov 4, 2014
1 parent 4bc28f4 commit 4dbbe4f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
defer jsonSource.Close()

img := &Image{}
dec := json.NewDecoder(jsonSource)

if err := json.Unmarshal(jsonData, img); err != nil {
// Decode the JSON data
if err := dec.Decode(img); err != nil {
return nil, err
}
if err := utils.ValidateID(img.ID); err != nil {
Expand Down

0 comments on commit 4dbbe4f

Please sign in to comment.