@@ -694,7 +694,8 @@ def export(self, container, chunk_size=DEFAULT_DATA_CHUNK_SIZE):
694694 return self ._stream_raw_result (res , chunk_size , False )
695695
696696 @utils .check_resource ('container' )
697- def get_archive (self , container , path , chunk_size = DEFAULT_DATA_CHUNK_SIZE ):
697+ def get_archive (self , container , path , chunk_size = DEFAULT_DATA_CHUNK_SIZE ,
698+ encode_stream = False ):
698699 """
699700 Retrieve a file or folder from a container in the form of a tar
700701 archive.
@@ -705,6 +706,8 @@ def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE):
705706 chunk_size (int): The number of bytes returned by each iteration
706707 of the generator. If ``None``, data will be streamed as it is
707708 received. Default: 2 MB
709+ encode_stream (bool): Determines if data should be encoded
710+ (gzip-compressed) during transmission. Default: False
708711
709712 Returns:
710713 (tuple): First element is a raw tar data stream. Second element is
@@ -729,8 +732,13 @@ def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE):
729732 params = {
730733 'path' : path
731734 }
735+ headers = {
736+ "Accept-Encoding" : "gzip, deflate"
737+ } if encode_stream else {
738+ "Accept-Encoding" : "identity"
739+ }
732740 url = self ._url ('/containers/{0}/archive' , container )
733- res = self ._get (url , params = params , stream = True )
741+ res = self ._get (url , params = params , stream = True , headers = headers )
734742 self ._raise_for_status (res )
735743 encoded_stat = res .headers .get ('x-docker-container-path-stat' )
736744 return (
0 commit comments