diff options
author | Joffrey F <joffrey@docker.com> | 2018-02-13 15:17:03 -0800 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2018-02-14 16:07:19 -0800 |
commit | 581ccc9f7e8e189248054268c98561ca775bd3d7 (patch) | |
tree | 682c25e7e624ecf6933a918b869f990950798d2f /docker/models | |
parent | 9e75609aec497361068bd0f57d5cc24065621106 (diff) | |
download | docker-py-1352-data_stream_control.tar.gz |
Add chunk_size parameter to data downloading methods (export, get_archive, save)1352-data_stream_control
Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'docker/models')
-rw-r--r-- | docker/models/containers.py | 17 | ||||
-rw-r--r-- | docker/models/images.py | 10 |
2 files changed, 21 insertions, 6 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py index 107a020..b6e34dd 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -3,6 +3,7 @@ import ntpath from collections import namedtuple from ..api import APIClient +from ..constants import DEFAULT_DATA_CHUNK_SIZE from ..errors import (ContainerError, ImageNotFound, create_unexpected_kwargs_error) from ..types import HostConfig @@ -181,10 +182,15 @@ class Container(Model): exec_output ) - def export(self): + def export(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE): """ Export the contents of the container's filesystem as a tar archive. + Args: + chunk_size (int): The number of bytes returned by each iteration + of the generator. If ``None``, data will be streamed as it is + received. Default: 2 MB + Returns: (str): The filesystem tar archive @@ -192,15 +198,18 @@ class Container(Model): :py:class:`docker.errors.APIError` If the server returns an error. """ - return self.client.api.export(self.id) + return self.client.api.export(self.id, chunk_size) - def get_archive(self, path): + def get_archive(self, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE): """ Retrieve a file or folder from the container in the form of a tar archive. Args: path (str): Path to the file or folder to retrieve + chunk_size (int): The number of bytes returned by each iteration + of the generator. If ``None``, data will be streamed as it is + received. Default: 2 MB Returns: (tuple): First element is a raw tar data stream. Second element is @@ -210,7 +219,7 @@ class Container(Model): :py:class:`docker.errors.APIError` If the server returns an error. """ - return self.client.api.get_archive(self.id, path) + return self.client.api.get_archive(self.id, path, chunk_size) def kill(self, signal=None): """ diff --git a/docker/models/images.py b/docker/models/images.py index 0f3c71a..d604f7c 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -4,6 +4,7 @@ import re import six from ..api import APIClient +from ..constants import DEFAULT_DATA_CHUNK_SIZE from ..errors import BuildError, ImageLoadError from ..utils import parse_repository_tag from ..utils.json_stream import json_stream @@ -58,10 +59,15 @@ class Image(Model): """ return self.client.api.history(self.id) - def save(self): + def save(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE): """ Get a tarball of an image. Similar to the ``docker save`` command. + Args: + chunk_size (int): The number of bytes returned by each iteration + of the generator. If ``None``, data will be streamed as it is + received. Default: 2 MB + Returns: (generator): A stream of raw archive data. @@ -77,7 +83,7 @@ class Image(Model): >>> f.write(chunk) >>> f.close() """ - return self.client.api.get_image(self.id) + return self.client.api.get_image(self.id, chunk_size) def tag(self, repository, tag=None, **kwargs): """ |