Browse Source

Implement docker export with standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
David Calavera 9 years ago
parent
commit
e0549b8ceb
2 changed files with 24 additions and 7 deletions
  1. 6 7
      api/client/export.go
  2. 18 0
      api/client/lib/export.go

+ 6 - 7
api/client/export.go

@@ -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 - 0
api/client/lib/export.go

@@ -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
+}