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:
parent
4bc28f4e6b
commit
4dbbe4f51a
1 changed files with 8 additions and 4 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue