Implement docker export with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-12-03 14:49:41 -05:00
parent 11c4cc9dde
commit e0549b8ceb
2 changed files with 24 additions and 7 deletions

View file

@ -2,6 +2,7 @@ package client
import (
"errors"
"io"
"os"
Cli "github.com/docker/docker/cli"
@ -33,14 +34,12 @@ func (cli *DockerCli) CmdExport(args ...string) error {
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
}
image := cmd.Arg(0)
sopts := &streamOpts{
rawTerminal: true,
out: output,
}
if _, err := cli.stream("GET", "/containers/"+image+"/export", sopts); err != nil {
responseBody, err := cli.client.ContainerExport(cmd.Arg(0))
if err != nil {
return err
}
defer responseBody.Close()
return nil
_, err = io.Copy(output, responseBody)
return err
}

18
api/client/lib/export.go Normal file
View file

@ -0,0 +1,18 @@
package lib
import (
"io"
"net/url"
)
// ContainerExport retrieves the raw contents of a container
// and returns them as a io.ReadCloser. It's up to the caller
// to close the stream.
func (cli *Client) ContainerExport(containerID string) (io.ReadCloser, error) {
serverResp, err := cli.GET("/containers/"+containerID+"/export", url.Values{}, nil)
if err != nil {
return nil, err
}
return serverResp.body, nil
}