MCPcopy Index your code
hub / github.com/docker/docker-py / get_archive

Method get_archive

docker/api/container.py:725–775  ·  view source on GitHub ↗

Retrieve a file or folder from a container in the form of a tar archive. Args: container (str): The container where the file is located path (str): Path to the file or folder to retrieve chunk_size (int): The number of bytes returned by e

(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE,
                    encode_stream=False)

Source from the content-addressed store, hash-verified

723
724 @utils.check_resource('container')
725 def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE,
726 encode_stream=False):
727 """
728 Retrieve a file or folder from a container in the form of a tar
729 archive.
730
731 Args:
732 container (str): The container where the file is located
733 path (str): Path to the file or folder to retrieve
734 chunk_size (int): The number of bytes returned by each iteration
735 of the generator. If ``None``, data will be streamed as it is
736 received. Default: 2 MB
737 encode_stream (bool): Determines if data should be encoded
738 (gzip-compressed) during transmission. Default: False
739
740 Returns:
741 (tuple): First element is a raw tar data stream. Second element is
742 a dict containing ``stat`` information on the specified ``path``.
743
744 Raises:
745 :py:class:`docker.errors.APIError`
746 If the server returns an error.
747
748 Example:
749
750 >>> c = docker.APIClient()
751 >>> f = open('./sh_bin.tar', 'wb')
752 >>> bits, stat = c.api.get_archive(container, '/bin/sh')
753 >>> print(stat)
754 {'name': 'sh', 'size': 1075464, 'mode': 493,
755 'mtime': '2018-10-01T15:37:48-07:00', 'linkTarget': ''}
756 >>> for chunk in bits:
757 ... f.write(chunk)
758 >>> f.close()
759 """
760 params = {
761 'path': path
762 }
763 headers = {
764 "Accept-Encoding": "gzip, deflate"
765 } if encode_stream else {
766 "Accept-Encoding": "identity"
767 }
768 url = self._url('/containers/{0}/archive', container)
769 res = self._get(url, params=params, stream=True, headers=headers)
770 self._raise_for_status(res)
771 encoded_stat = res.headers.get('x-docker-container-path-stat')
772 return (
773 self._stream_raw_result(res, chunk_size, False),
774 utils.decode_json_header(encoded_stat) if encoded_stat else None
775 )
776
777 @utils.check_resource('container')
778 def inspect_container(self, container):

Callers

nothing calls this directly

Calls 5

_urlMethod · 0.80
_getMethod · 0.80
_raise_for_statusMethod · 0.80
_stream_raw_resultMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected