-
Notifications
You must be signed in to change notification settings - Fork 154
/
storage_transfer_manager_download_chunks_concurrently.py
43 lines (34 loc) · 1.64 KB
/
storage_transfer_manager_download_chunks_concurrently.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START storage_transfer_manager_download_chunks_concurrently]
def download_chunks_concurrently(bucket_name, blob_name, filename, processes=8):
"""Download a single file in chunks, concurrently."""
# The ID of your GCS bucket
# bucket_name = "your-bucket-name"
# The file to be downloaded
# blob_name = "target-file"
# The destination filename or path
# filename = ""
# The maximum number of processes to use for the operation. The performance
# impact of this value depends on the use case, but smaller files usually
# benefit from a higher number of processes. Each additional process occupies
# some CPU and memory resources until finished.
# processes=8
from google.cloud.storage import Client, transfer_manager
storage_client = Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(blob_name)
transfer_manager.download_chunks_concurrently(blob, filename, max_workers=processes)
print("Downloaded {} to {}.".format(blob_name, filename))
# [END storage_transfer_manager_download_chunks_concurrently]