Constructor
new TransferManager(bucket)
Parameters:
Name | Type | Description |
---|---|---|
bucket |
Bucket |
A Bucket instance |
Methods
(async) downloadFileInChunks(file | stringopt, optionsopt) → {Promise.<DownloadResponse>}
Download a large file in chunks utilizing parallel download operations. This is a convenience method that utilizes File#download to perform the download.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
file | string |
object |
<optional> |
File to download. |
options |
DownloadFileInChunksOptions |
<optional> |
Configuration options. |
Returns:
Type | Description |
---|---|
Promise.<DownloadResponse> |
Example
```
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-bucket');
const transferManager = new TransferManager(bucket);
//-
// Download a large file in chunks utilizing parallel operations.
//-
const response = await transferManager.downloadLargeFile(bucket.file('large-file.txt');
// Your local directory now contains:
// - "large-file.txt" (with the contents from my-bucket.large-file.txt)
```
(async) downloadManyFiles(filesOrFolderopt, optionsopt) → {Promise.<Array.<DownloadResponse>>}
Download multiple files in parallel to the local filesystem. This is a convenience method that utilizes File#download to perform the download.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filesOrFolder |
array | string |
<optional> |
An array of file name strings or file objects to be downloaded. If a string is provided this will be treated as a GCS prefix and all files with that prefix will be downloaded. |
options |
DownloadManyFilesOptions |
<optional> |
Configuration options. |
Returns:
Type | Description |
---|---|
Promise.<Array.<DownloadResponse>> |
Example
```
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-bucket');
const transferManager = new TransferManager(bucket);
//-
// Download multiple files in parallel.
//-
const response = await transferManager.downloadManyFiles(['file1.txt', 'file2.txt']);
// The following files have been downloaded:
// - "file1.txt" (with the contents from my-bucket.file1.txt)
// - "file2.txt" (with the contents from my-bucket.file2.txt)
const response = await transferManager.downloadManyFiles([bucket.File('file1.txt'), bucket.File('file2.txt')]);
// The following files have been downloaded:
// - "file1.txt" (with the contents from my-bucket.file1.txt)
// - "file2.txt" (with the contents from my-bucket.file2.txt)
const response = await transferManager.downloadManyFiles('test-folder');
// All files with GCS prefix of 'test-folder' have been downloaded.
```
(async) uploadManyFiles(filePathsOrDirectoryopt, optionsopt) → {Promise.<Array.<UploadResponse>>}
Upload multiple files in parallel to the bucket. This is a convenience method that utilizes Bucket#upload to perform the upload.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filePathsOrDirectory |
array | string |
<optional> |
An array of fully qualified paths to the files or a directory name. If a directory name is provided, the directory will be recursively walked and all files will be added to the upload list. to be uploaded to the bucket |
options |
UploadManyFilesOptions |
<optional> |
Configuration options. |
Returns:
Type | Description |
---|---|
Promise.<Array.<UploadResponse>> |
Example
```
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-bucket');
const transferManager = new TransferManager(bucket);
//-
// Upload multiple files in parallel.
//-
const response = await transferManager.uploadManyFiles(['/local/path/file1.txt, 'local/path/file2.txt']);
// Your bucket now contains:
// - "local/path/file1.txt" (with the contents of '/local/path/file1.txt')
// - "local/path/file2.txt" (with the contents of '/local/path/file2.txt')
const response = await transferManager.uploadManyFiles('/local/directory');
// Your bucket will now contain all files contained in '/local/directory' maintaining the subdirectory structure.
```