3
3
4
4
from .. import errors
5
5
from .. import utils
6
+ from ..constants import DEFAULT_DATA_CHUNK_SIZE
6
7
from ..types import (
7
8
ContainerConfig , EndpointConfig , HostConfig , NetworkingConfig
8
9
)
@@ -645,12 +646,15 @@ def diff(self, container):
645
646
)
646
647
647
648
@utils .check_resource ('container' )
648
- def export (self , container ):
649
+ def export (self , container , chunk_size = DEFAULT_DATA_CHUNK_SIZE ):
649
650
"""
650
651
Export the contents of a filesystem as a tar archive.
651
652
652
653
Args:
653
654
container (str): The container to export
655
+ chunk_size (int): The number of bytes returned by each iteration
656
+ of the generator. If ``None``, data will be streamed as it is
657
+ received. Default: 2 MB
654
658
655
659
Returns:
656
660
(generator): The archived filesystem data stream
@@ -662,17 +666,20 @@ def export(self, container):
662
666
res = self ._get (
663
667
self ._url ("/containers/{0}/export" , container ), stream = True
664
668
)
665
- return self ._stream_raw_result (res )
669
+ return self ._stream_raw_result (res , chunk_size , False )
666
670
667
671
@utils .check_resource ('container' )
668
- def get_archive (self , container , path ):
672
+ def get_archive (self , container , path , chunk_size = DEFAULT_DATA_CHUNK_SIZE ):
669
673
"""
670
674
Retrieve a file or folder from a container in the form of a tar
671
675
archive.
672
676
673
677
Args:
674
678
container (str): The container where the file is located
675
679
path (str): Path to the file or folder to retrieve
680
+ chunk_size (int): The number of bytes returned by each iteration
681
+ of the generator. If ``None``, data will be streamed as it is
682
+ received. Default: 2 MB
676
683
677
684
Returns:
678
685
(tuple): First element is a raw tar data stream. Second element is
@@ -690,7 +697,7 @@ def get_archive(self, container, path):
690
697
self ._raise_for_status (res )
691
698
encoded_stat = res .headers .get ('x-docker-container-path-stat' )
692
699
return (
693
- self ._stream_raw_result (res ),
700
+ self ._stream_raw_result (res , chunk_size , False ),
694
701
utils .decode_json_header (encoded_stat ) if encoded_stat else None
695
702
)
696
703
0 commit comments