Signed-off-by: David Calavera <david.calavera@gmail.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+package lib |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "io" |
|
| 4 |
+ "net/url" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+// ImageSave retrieves one or more images from the docker host as a io.ReadCloser. |
|
| 8 |
+// It's up to the caller to store the images and close the stream. |
|
| 9 |
+func (cli *Client) ImageSave(imageIDs []string) (io.ReadCloser, error) {
|
|
| 10 |
+ query := url.Values{
|
|
| 11 |
+ "names": imageIDs, |
|
| 12 |
+ } |
|
| 13 |
+ |
|
| 14 |
+ resp, err := cli.GET("/images/get", query, nil)
|
|
| 15 |
+ if err != nil {
|
|
| 16 |
+ return nil, err |
|
| 17 |
+ } |
|
| 18 |
+ return resp.body, nil |
|
| 19 |
+} |
| ... | ... |
@@ -2,7 +2,7 @@ package client |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "net/url" |
|
| 5 |
+ "io" |
|
| 6 | 6 |
"os" |
| 7 | 7 |
|
| 8 | 8 |
Cli "github.com/docker/docker/cli" |
| ... | ... |
@@ -35,18 +35,12 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
| 35 | 35 |
} |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
- sopts := &streamOpts{
|
|
| 39 |
- rawTerminal: true, |
|
| 40 |
- out: output, |
|
| 41 |
- } |
|
| 42 |
- |
|
| 43 |
- v := url.Values{}
|
|
| 44 |
- for _, arg := range cmd.Args() {
|
|
| 45 |
- v.Add("names", arg)
|
|
| 46 |
- } |
|
| 47 |
- if _, err := cli.stream("GET", "/images/get?"+v.Encode(), sopts); err != nil {
|
|
| 38 |
+ responseBody, err := cli.client.ImageSave(cmd.Args()) |
|
| 39 |
+ if err != nil {
|
|
| 48 | 40 |
return err |
| 49 | 41 |
} |
| 42 |
+ defer responseBody.Close() |
|
| 50 | 43 |
|
| 51 |
- return nil |
|
| 44 |
+ _, err = io.Copy(output, responseBody) |
|
| 45 |
+ return err |
|
| 52 | 46 |
} |