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