summaryrefslogtreecommitdiff
path: root/gitlab/v4/objects/files.py
diff options
context:
space:
mode:
authorTom Catshoek <tomcatshoek@zeelandnet.nl>2022-06-26 08:29:13 +0200
committerGitHub <noreply@github.com>2022-06-26 08:29:13 +0200
commitb6447211754e126f64e12fc735ad74fe557b7fb4 (patch)
tree2c86425ce6b25b4d40bf0c12aa0d1f7def77838c /gitlab/v4/objects/files.py
parent0f2a602d3a9d6579f5fdfdf945a236ae44e93a12 (diff)
downloadgitlab-b6447211754e126f64e12fc735ad74fe557b7fb4.tar.gz
feat(downloads): allow streaming downloads access to response iterator (#1956)
* feat(downloads): allow streaming downloads access to response iterator Allow access to the underlying response iterator when downloading in streaming mode by specifying `iterator=True`. Update type annotations to support this change. * docs(api-docs): add iterator example to artifact download Document the usage of the `iterator=True` option when downloading artifacts * test(packages): add tests for streaming downloads
Diffstat (limited to 'gitlab/v4/objects/files.py')
-rw-r--r--gitlab/v4/objects/files.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py
index aa86704..2fd79fd 100644
--- a/gitlab/v4/objects/files.py
+++ b/gitlab/v4/objects/files.py
@@ -1,5 +1,15 @@
import base64
-from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING
+from typing import (
+ Any,
+ Callable,
+ cast,
+ Dict,
+ Iterator,
+ List,
+ Optional,
+ TYPE_CHECKING,
+ Union,
+)
import requests
@@ -220,10 +230,11 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
file_path: str,
ref: str,
streamed: bool = False,
+ iterator: bool = False,
action: Optional[Callable[..., Any]] = None,
chunk_size: int = 1024,
**kwargs: Any,
- ) -> Optional[bytes]:
+ ) -> Optional[Union[bytes, Iterator[Any]]]:
"""Return the content of a file for a commit.
Args:
@@ -232,6 +243,8 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
streamed: If True the data will be processed by chunks of
`chunk_size` and each chunk is passed to `action` for
treatment
+ iterator: If True directly return the underlying response
+ iterator
action: Callable responsible of dealing with chunk of
data
chunk_size: Size of each chunk
@@ -252,7 +265,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
)
if TYPE_CHECKING:
assert isinstance(result, requests.Response)
- return utils.response_content(result, streamed, action, chunk_size)
+ return utils.response_content(result, streamed, iterator, action, chunk_size)
@cli.register_custom_action("ProjectFileManager", ("file_path", "ref"))
@exc.on_http_error(exc.GitlabListError)