podman
58 строк · 1.8 Кб
1package docker
2
3import (
4"context"
5"fmt"
6"io"
7"net/http"
8"time"
9)
10
11// UploadToContainerOptions is the set of options that can be used when
12// uploading an archive into a container.
13//
14// See https://goo.gl/g25o7u for more details.
15type UploadToContainerOptions struct {
16InputStream io.Reader `json:"-" qs:"-"`
17Path string `qs:"path"`
18NoOverwriteDirNonDir bool `qs:"noOverwriteDirNonDir"`
19Context context.Context
20}
21
22// UploadToContainer uploads a tar archive to be extracted to a path in the
23// filesystem of the container.
24//
25// See https://goo.gl/g25o7u for more details.
26func (c *Client) UploadToContainer(id string, opts UploadToContainerOptions) error {
27url := fmt.Sprintf("/containers/%s/archive?", id) + queryString(opts)
28
29return c.stream(http.MethodPut, url, streamOptions{
30in: opts.InputStream,
31context: opts.Context,
32})
33}
34
35// DownloadFromContainerOptions is the set of options that can be used when
36// downloading resources from a container.
37//
38// See https://goo.gl/W49jxK for more details.
39type DownloadFromContainerOptions struct {
40OutputStream io.Writer `json:"-" qs:"-"`
41Path string `qs:"path"`
42InactivityTimeout time.Duration `qs:"-"`
43Context context.Context
44}
45
46// DownloadFromContainer downloads a tar archive of files or folders in a container.
47//
48// See https://goo.gl/W49jxK for more details.
49func (c *Client) DownloadFromContainer(id string, opts DownloadFromContainerOptions) error {
50url := fmt.Sprintf("/containers/%s/archive?", id) + queryString(opts)
51
52return c.stream(http.MethodGet, url, streamOptions{
53setRawTerminal: true,
54stdout: opts.OutputStream,
55inactivityTimeout: opts.InactivityTimeout,
56context: opts.Context,
57})
58}
59