podman

Форк
0
58 строк · 1.8 Кб
1
package docker
2

3
import (
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.
15
type UploadToContainerOptions struct {
16
	InputStream          io.Reader `json:"-" qs:"-"`
17
	Path                 string    `qs:"path"`
18
	NoOverwriteDirNonDir bool      `qs:"noOverwriteDirNonDir"`
19
	Context              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.
26
func (c *Client) UploadToContainer(id string, opts UploadToContainerOptions) error {
27
	url := fmt.Sprintf("/containers/%s/archive?", id) + queryString(opts)
28

29
	return c.stream(http.MethodPut, url, streamOptions{
30
		in:      opts.InputStream,
31
		context: 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.
39
type DownloadFromContainerOptions struct {
40
	OutputStream      io.Writer     `json:"-" qs:"-"`
41
	Path              string        `qs:"path"`
42
	InactivityTimeout time.Duration `qs:"-"`
43
	Context           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.
49
func (c *Client) DownloadFromContainer(id string, opts DownloadFromContainerOptions) error {
50
	url := fmt.Sprintf("/containers/%s/archive?", id) + queryString(opts)
51

52
	return c.stream(http.MethodGet, url, streamOptions{
53
		setRawTerminal:    true,
54
		stdout:            opts.OutputStream,
55
		inactivityTimeout: opts.InactivityTimeout,
56
		context:           opts.Context,
57
	})
58
}
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.