Create a TransferManager object to perform parallel transfer operations on a Cloud Storage bucket.
Package
@google-cloud/storageConstructors
(constructor)(bucket)
constructor
(
bucket
:
Bucket
);
Constructs a new instance of the TransferManager
class
Properties
bucket
bucket
:
Bucket
;
Methods
downloadFileInChunks(fileOrName, options)
downloadFileInChunks
(
fileOrName
:
File
|
string
,
options
?:
DownloadFileInChunksOptions
)
:
Promise<void
|
DownloadResponse
> ;
Download a large file in chunks utilizing parallel download operations. This is a convenience method that utilizes to perform the download.
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)
downloadManyFiles(filesOrFolder, options)
downloadManyFiles
(
filesOrFolder
:
File
[]
|
string
[]
|
string
,
options
?:
DownloadManyFilesOptions
)
:
Promise<void
|
DownloadResponse
[]>;
Download multiple files in parallel to the local filesystem. This is a convenience method that utilizes to perform the download.
filesOrFolder
File
[] | string[] | string
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
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.
uploadManyFiles(filePathsOrDirectory, options)
uploadManyFiles
(
filePathsOrDirectory
:
string
[]
|
string
,
options
?:
UploadManyFilesOptions
)
:
Promise<UploadResponse
[]>;
Upload multiple files in parallel to the bucket. This is a convenience method that utilizes to perform the upload.
filePathsOrDirectory
string[] | string
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
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
.