Browse Source

image: stream img JSON & Decode in LoadImage

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
unclejack 10 years ago
parent
commit
4dbbe4f51a
1 changed files with 7 additions and 3 deletions
  1. 7 3
      image/image.go

+ 7 - 3
image/image.go

@@ -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 {