TransferManager

TransferManager

Create a TransferManager object to perform parallel transfer operations on a Cloud Storage bucket.

Constructor

new TransferManager(bucket)

Parameters:
Name Type Description
bucket Bucket

A Bucket instance

Methods

(async) downloadFileInChunks(fileOrName, optionsopt) → {Promise.<(void|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
fileOrName File | string

File to download.

options DownloadFileInChunksOptions <optional>

Configuration options.

Returns:
Type Description
Promise.<(void|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.downloadFileInChunks(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. Setting options.prefix or options.stripPrefix or options.passthroughOptions.destination will cause the downloaded files to be written to the file system instead of being returned as a buffer.

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) uploadFileInChunks(filePathopt, optionsopt, generatoropt) → {Promise.<void>}

Upload a large file in chunks utilizing parallel upload opertions. If the upload fails, an uploadId and map containing all the successfully uploaded parts will be returned to the caller. These arguments can be used to resume the upload.

Parameters:
Name Type Attributes Description
filePath string <optional>

The path of the file to be uploaded

options UploadFileInChunksOptions <optional>

Configuration options.

generator MultiPartHelperGenerator <optional>

A function that will return a type that implements the MPU interface. Most users will not need to use this.

Returns:
Type Description
Promise.<void>

If successful a promise resolving to void, otherwise a error containing the message, uploadid, and parts map.

Example
```
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('my-bucket');
const transferManager = new TransferManager(bucket);

//-
// Upload a large file in chunks utilizing parallel operations.
//-
const response = await transferManager.uploadFileInChunks('large-file.txt');
// Your bucket now contains:
// - "large-file.txt"
```

(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.
```