mirror of https://github.com/docker/docker-py.git
Disable compression by default when using get_archive method
Signed-off-by: Niklas Saari <niklas.saari@tutanota.com>
This commit is contained in:
parent
351b131fe9
commit
281bc31e21
|
@ -699,7 +699,8 @@ class ContainerApiMixin(object):
|
||||||
return self._stream_raw_result(res, chunk_size, False)
|
return self._stream_raw_result(res, chunk_size, False)
|
||||||
|
|
||||||
@utils.check_resource('container')
|
@utils.check_resource('container')
|
||||||
def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE):
|
def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE,
|
||||||
|
encode_stream=False):
|
||||||
"""
|
"""
|
||||||
Retrieve a file or folder from a container in the form of a tar
|
Retrieve a file or folder from a container in the form of a tar
|
||||||
archive.
|
archive.
|
||||||
|
@ -710,6 +711,8 @@ class ContainerApiMixin(object):
|
||||||
chunk_size (int): The number of bytes returned by each iteration
|
chunk_size (int): The number of bytes returned by each iteration
|
||||||
of the generator. If ``None``, data will be streamed as it is
|
of the generator. If ``None``, data will be streamed as it is
|
||||||
received. Default: 2 MB
|
received. Default: 2 MB
|
||||||
|
encode_stream (bool): Determines if data should be encoded
|
||||||
|
(gzip-compressed) during transmission. Default: False
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(tuple): First element is a raw tar data stream. Second element is
|
(tuple): First element is a raw tar data stream. Second element is
|
||||||
|
@ -734,8 +737,13 @@ class ContainerApiMixin(object):
|
||||||
params = {
|
params = {
|
||||||
'path': path
|
'path': path
|
||||||
}
|
}
|
||||||
|
headers = {
|
||||||
|
"Accept-Encoding": "gzip, deflate"
|
||||||
|
} if encode_stream else {
|
||||||
|
"Accept-Encoding": "identity"
|
||||||
|
}
|
||||||
url = self._url('/containers/{0}/archive', container)
|
url = self._url('/containers/{0}/archive', container)
|
||||||
res = self._get(url, params=params, stream=True)
|
res = self._get(url, params=params, stream=True, headers=headers)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
encoded_stat = res.headers.get('x-docker-container-path-stat')
|
encoded_stat = res.headers.get('x-docker-container-path-stat')
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -225,7 +225,8 @@ class Container(Model):
|
||||||
"""
|
"""
|
||||||
return self.client.api.export(self.id, chunk_size)
|
return self.client.api.export(self.id, chunk_size)
|
||||||
|
|
||||||
def get_archive(self, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE):
|
def get_archive(self, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE,
|
||||||
|
encode_stream=False):
|
||||||
"""
|
"""
|
||||||
Retrieve a file or folder from the container in the form of a tar
|
Retrieve a file or folder from the container in the form of a tar
|
||||||
archive.
|
archive.
|
||||||
|
@ -235,6 +236,8 @@ class Container(Model):
|
||||||
chunk_size (int): The number of bytes returned by each iteration
|
chunk_size (int): The number of bytes returned by each iteration
|
||||||
of the generator. If ``None``, data will be streamed as it is
|
of the generator. If ``None``, data will be streamed as it is
|
||||||
received. Default: 2 MB
|
received. Default: 2 MB
|
||||||
|
encode_stream (bool): Determines if data should be encoded
|
||||||
|
(gzip-compressed) during transmission. Default: False
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(tuple): First element is a raw tar data stream. Second element is
|
(tuple): First element is a raw tar data stream. Second element is
|
||||||
|
@ -255,7 +258,8 @@ class Container(Model):
|
||||||
... f.write(chunk)
|
... f.write(chunk)
|
||||||
>>> f.close()
|
>>> f.close()
|
||||||
"""
|
"""
|
||||||
return self.client.api.get_archive(self.id, path, chunk_size)
|
return self.client.api.get_archive(self.id, path,
|
||||||
|
chunk_size, encode_stream)
|
||||||
|
|
||||||
def kill(self, signal=None):
|
def kill(self, signal=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -450,7 +450,7 @@ class ContainerTest(unittest.TestCase):
|
||||||
container = client.containers.get(FAKE_CONTAINER_ID)
|
container = client.containers.get(FAKE_CONTAINER_ID)
|
||||||
container.get_archive('foo')
|
container.get_archive('foo')
|
||||||
client.api.get_archive.assert_called_with(
|
client.api.get_archive.assert_called_with(
|
||||||
FAKE_CONTAINER_ID, 'foo', DEFAULT_DATA_CHUNK_SIZE
|
FAKE_CONTAINER_ID, 'foo', DEFAULT_DATA_CHUNK_SIZE, False
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image(self):
|
def test_image(self):
|
||||||
|
|
Loading…
Reference in New Issue