Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -38,14 +38,18 @@ type Image struct {
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
func LoadImage(root string) (*Image, error) {
|
| 41 |
- // Load the json data |
|
| 42 |
- jsonData, err := ioutil.ReadFile(jsonPath(root)) |
|
| 41 |
+ // Open the JSON file to decode by streaming |
|
| 42 |
+ jsonSource, err := os.Open(jsonPath(root)) |
|
| 43 | 43 |
if err != nil {
|
| 44 | 44 |
return nil, err |
| 45 | 45 |
} |
| 46 |
+ defer jsonSource.Close() |
|
| 47 |
+ |
|
| 46 | 48 |
img := &Image{}
|
| 49 |
+ dec := json.NewDecoder(jsonSource) |
|
| 47 | 50 |
|
| 48 |
- if err := json.Unmarshal(jsonData, img); err != nil {
|
|
| 51 |
+ // Decode the JSON data |
|
| 52 |
+ if err := dec.Decode(img); err != nil {
|
|
| 49 | 53 |
return nil, err |
| 50 | 54 |
} |
| 51 | 55 |
if err := utils.ValidateID(img.ID); err != nil {
|