Skip to content

Commit c153ab6

Browse files
committed
rename transfer manager functions
1 parent 89e8204 commit c153ab6

File tree

3 files changed

+76
-79
lines changed

3 files changed

+76
-79
lines changed

internal-tooling/performTransferManagerTest.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ async function main() {
9393

9494
switch (argv.testtype) {
9595
case TRANSFER_MANAGER_TEST_TYPES.TRANSFER_MANAGER_UPLOAD_MULTIPLE_OBJECTS:
96-
result = await performUploadMultipleObjectsTest();
96+
result = await performUploadManyFilesTest();
9797
break;
9898
case TRANSFER_MANAGER_TEST_TYPES.TRANSFER_MANAGER_DOWNLOAD_MULTIPLE_OBJECTS:
99-
result = await performDownloadMultipleObjectsTest();
99+
result = await performDownloadManyFilesTest();
100100
break;
101101
case TRANSFER_MANAGER_TEST_TYPES.TRANSFER_MANAGER_LARGE_FILE_DOWNLOAD:
102-
result = await performDownloadLargeFileTest();
102+
result = await performDownloadFileInChunksTest();
103103
break;
104104
default:
105105
break;
@@ -120,7 +120,7 @@ async function performTestCleanup() {
120120
*
121121
* @returns {Promise<TestResult>} A promise that resolves containing information about the test results.
122122
*/
123-
async function performUploadMultipleObjectsTest(): Promise<TestResult> {
123+
async function performUploadManyFilesTest(): Promise<TestResult> {
124124
const creationInfo = generateRandomDirectoryStructure(
125125
argv.numobjects,
126126
TEST_NAME_STRING,
@@ -130,7 +130,7 @@ async function performUploadMultipleObjectsTest(): Promise<TestResult> {
130130
);
131131

132132
const start = performance.now();
133-
await transferManager.uploadMulti(creationInfo.paths, {
133+
await transferManager.uploadManyFiles(creationInfo.paths, {
134134
concurrencyLimit: argv.numpromises,
135135
passthroughOptions: {
136136
validation: checkType,
@@ -161,7 +161,7 @@ async function performUploadMultipleObjectsTest(): Promise<TestResult> {
161161
*
162162
* @returns {Promise<TestResult>} A promise that resolves containing information about the test results.
163163
*/
164-
async function performDownloadMultipleObjectsTest(): Promise<TestResult> {
164+
async function performDownloadManyFilesTest(): Promise<TestResult> {
165165
const creationInfo = generateRandomDirectoryStructure(
166166
argv.numobjects,
167167
TEST_NAME_STRING,
@@ -170,15 +170,15 @@ async function performDownloadMultipleObjectsTest(): Promise<TestResult> {
170170
DIRECTORY_PROBABILITY
171171
);
172172

173-
await transferManager.uploadMulti(creationInfo.paths, {
173+
await transferManager.uploadManyFiles(creationInfo.paths, {
174174
concurrencyLimit: argv.numpromises,
175175
passthroughOptions: {
176176
validation: checkType,
177177
},
178178
});
179179
const getFilesResult = await bucket.getFiles();
180180
const start = performance.now();
181-
await transferManager.downloadMulti(getFilesResult[0], {
181+
await transferManager.downloadManyFiles(getFilesResult[0], {
182182
prefix: path.join(__dirname, '..', '..'),
183183
concurrencyLimit: argv.numpromises,
184184
passthroughOptions: {
@@ -209,7 +209,7 @@ async function performDownloadMultipleObjectsTest(): Promise<TestResult> {
209209
*
210210
* @returns {Promise<TestResult>} A promise that resolves containing information about the test results.
211211
*/
212-
async function performDownloadLargeFileTest(): Promise<TestResult> {
212+
async function performDownloadFileInChunksTest(): Promise<TestResult> {
213213
const fileName = generateRandomFileName(TEST_NAME_STRING);
214214
const sizeInBytes = generateRandomFile(
215215
fileName,
@@ -222,10 +222,10 @@ async function performDownloadLargeFileTest(): Promise<TestResult> {
222222
await bucket.upload(`${__dirname}/${fileName}`);
223223
cleanupFile(fileName);
224224
const start = performance.now();
225-
await transferManager.downloadLargeFile(file, {
225+
await transferManager.downloadFileInChunks(file, {
226226
concurrencyLimit: argv.numpromises,
227227
chunkSizeBytes: argv.chunksize,
228-
path: `${__dirname}`,
228+
destination: path.join(__dirname, fileName),
229229
});
230230
const end = performance.now();
231231

src/transfer-manager.ts

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,31 @@ const DEFAULT_PARALLEL_LARGE_FILE_DOWNLOAD_LIMIT = 2;
3333
const LARGE_FILE_SIZE_THRESHOLD = 256 * 1024 * 1024;
3434
const LARGE_FILE_DEFAULT_CHUNK_SIZE = 10 * 1024 * 1024;
3535
const EMPTY_REGEX = '(?:)';
36-
export interface UploadMultiOptions {
36+
export interface UploadManyFilesOptions {
3737
concurrencyLimit?: number;
3838
skipIfExists?: boolean;
3939
prefix?: string;
4040
passthroughOptions?: Omit<UploadOptions, 'destination'>;
4141
}
4242

43-
export interface DownloadMultiOptions {
43+
export interface DownloadManyFilesOptions {
4444
concurrencyLimit?: number;
4545
prefix?: string;
4646
stripPrefix?: string;
4747
passthroughOptions?: DownloadOptions;
4848
}
4949

50-
export interface LargeFileDownloadOptions {
50+
export interface DownloadFileInChunksOptions {
5151
concurrencyLimit?: number;
5252
chunkSizeBytes?: number;
53-
path?: string;
53+
destination?: string;
5454
}
5555

56-
export interface UploadMultiCallback {
56+
export interface UploadManyFilesCallback {
5757
(err: Error | null, files?: File[], metadata?: Metadata[]): void;
5858
}
5959

60-
export interface DownloadMultiCallback {
60+
export interface DownloadManyFilesCallback {
6161
(err: Error | null, contents?: Buffer[]): void;
6262
}
6363

@@ -76,21 +76,21 @@ export class TransferManager {
7676
this.bucket = bucket;
7777
}
7878

79-
async uploadMulti(
79+
async uploadManyFiles(
8080
filePaths: string[],
81-
options?: UploadMultiOptions
81+
options?: UploadManyFilesOptions
8282
): Promise<UploadResponse[]>;
83-
async uploadMulti(
83+
async uploadManyFiles(
8484
filePaths: string[],
85-
callback: UploadMultiCallback
85+
callback: UploadManyFilesCallback
8686
): Promise<void>;
87-
async uploadMulti(
87+
async uploadManyFiles(
8888
filePaths: string[],
89-
options: UploadMultiOptions,
90-
callback: UploadMultiCallback
89+
options: UploadManyFilesOptions,
90+
callback: UploadManyFilesCallback
9191
): Promise<void>;
9292
/**
93-
* @typedef {object} UploadMultiOptions
93+
* @typedef {object} UploadManyFilesOptions
9494
* @property {number} [concurrencyLimit] The number of concurrently executing promises
9595
* to use when uploading the files.
9696
* @property {boolean} [skipIfExists] Do not upload the file if it already exists in
@@ -101,7 +101,7 @@ export class TransferManager {
101101
* @experimental
102102
*/
103103
/**
104-
* @callback UploadMultiCallback
104+
* @callback UploadManyFilesCallback
105105
* @param {?Error} [err] Request error, if any.
106106
* @param {array} [files] Array of uploaded {@link File}.
107107
* @param {array} [metadata] Array of uploaded {@link Metadata}
@@ -113,8 +113,8 @@ export class TransferManager {
113113
*
114114
* @param {array} [filePaths] An array of fully qualified paths to the files.
115115
* to be uploaded to the bucket
116-
* @param {UploadMultiOptions} [options] Configuration options.
117-
* @param {UploadMultiCallback} [callback] Callback function.
116+
* @param {UploadManyFilesOptions} [options] Configuration options.
117+
* @param {UploadManyFilesCallback} [callback] Callback function.
118118
* @returns {Promise<UploadResponse[] | void>}
119119
*
120120
* @example
@@ -127,7 +127,7 @@ export class TransferManager {
127127
* //-
128128
* // Upload multiple files in parallel.
129129
* //-
130-
* transferManager.uploadMulti(['/local/path/file1.txt, 'local/path/file2.txt'], function(err, files, metadata) {
130+
* transferManager.uploadManyFiles(['/local/path/file1.txt, 'local/path/file2.txt'], function(err, files, metadata) {
131131
* // Your bucket now contains:
132132
* // - "file1.txt" (with the contents of '/local/path/file1.txt')
133133
* // - "file2.txt" (with the contents of '/local/path/file2.txt')
@@ -137,16 +137,16 @@ export class TransferManager {
137137
* //-
138138
* // If the callback is omitted, we will return a promise.
139139
* //-
140-
* const response = await transferManager.uploadMulti(['/local/path/file1.txt, 'local/path/file2.txt']);
140+
* const response = await transferManager.uploadManyFiles(['/local/path/file1.txt, 'local/path/file2.txt']);
141141
* ```
142142
* @experimental
143143
*/
144-
async uploadMulti(
144+
async uploadManyFiles(
145145
filePaths: string[],
146-
optionsOrCallback?: UploadMultiOptions | UploadMultiCallback,
147-
callback?: UploadMultiCallback
146+
optionsOrCallback?: UploadManyFilesOptions | UploadManyFilesCallback,
147+
callback?: UploadManyFilesCallback
148148
): Promise<void | UploadResponse[]> {
149-
let options: UploadMultiOptions = {};
149+
let options: UploadManyFilesOptions = {};
150150
if (typeof optionsOrCallback === 'function') {
151151
callback = optionsOrCallback;
152152
} else if (optionsOrCallback) {
@@ -208,21 +208,21 @@ export class TransferManager {
208208
return Promise.all(promises);
209209
}
210210

211-
async downloadMulti(
211+
async downloadManyFiles(
212212
files: File[],
213-
options?: DownloadMultiOptions
213+
options?: DownloadManyFilesOptions
214214
): Promise<DownloadResponse[]>;
215-
async downloadMulti(
215+
async downloadManyFiles(
216216
files: File[],
217-
callback: DownloadMultiCallback
217+
callback: DownloadManyFilesCallback
218218
): Promise<void>;
219-
async downloadMulti(
219+
async downloadManyFiles(
220220
files: File[],
221-
options: DownloadMultiOptions,
222-
callback: DownloadMultiCallback
221+
options: DownloadManyFilesOptions,
222+
callback: DownloadManyFilesCallback
223223
): Promise<void>;
224224
/**
225-
* @typedef {object} DownloadMultiOptions
225+
* @typedef {object} DownloadManyFilesOptions
226226
* @property {number} [concurrencyLimit] The number of concurrently executing promises
227227
* to use when downloading the files.
228228
* @property {string} [prefix] A prefix to append to all of the downloaded files.
@@ -232,7 +232,7 @@ export class TransferManager {
232232
* @experimental
233233
*/
234234
/**
235-
* @callback DownloadMultiCallback
235+
* @callback DownloadManyFilesCallback
236236
* @param {?Error} [err] Request error, if any.
237237
* @param {array} [contents] Contents of the downloaded files.
238238
* @experimental
@@ -242,8 +242,8 @@ export class TransferManager {
242242
* that utilizes {@link File#download} to perform the download.
243243
*
244244
* @param {array} [files] An array of file objects to be downloaded.
245-
* @param {DownloadMultiOptions} [options] Configuration options.
246-
* @param {DownloadMultiCallback} {callback} Callback function.
245+
* @param {DownloadManyFilesOptions} [options] Configuration options.
246+
* @param {DownloadManyFilesCallback} {callback} Callback function.
247247
* @returns {Promise<DownloadResponse[] | void>}
248248
*
249249
* @example
@@ -256,7 +256,7 @@ export class TransferManager {
256256
* //-
257257
* // Download multiple files in parallel.
258258
* //-
259-
* transferManager.downloadMulti([bucket.file('file1.txt'), bucket.file('file2.txt')], function(err, contents){
259+
* transferManager.downloadManyFiles([bucket.file('file1.txt'), bucket.file('file2.txt')], function(err, contents){
260260
* // Your local directory now contains:
261261
* // - "file1.txt" (with the contents from my-bucket.file1.txt)
262262
* // - "file2.txt" (with the contents from my-bucket.file2.txt)
@@ -266,15 +266,15 @@ export class TransferManager {
266266
* //-
267267
* // If the callback is omitted, we will return a promise.
268268
* //-
269-
* const response = await transferManager.downloadMulti(bucket.File('file1.txt'), bucket.File('file2.txt')]);
269+
* const response = await transferManager.downloadManyFiles(bucket.File('file1.txt'), bucket.File('file2.txt')]);
270270
* @experimental
271271
*/
272-
async downloadMulti(
272+
async downloadManyFiles(
273273
files: File[],
274-
optionsOrCallback?: DownloadMultiOptions | DownloadMultiCallback,
275-
callback?: DownloadMultiCallback
274+
optionsOrCallback?: DownloadManyFilesOptions | DownloadManyFilesCallback,
275+
callback?: DownloadManyFilesCallback
276276
): Promise<void | DownloadResponse[]> {
277-
let options: DownloadMultiOptions = {};
277+
let options: DownloadManyFilesOptions = {};
278278
if (typeof optionsOrCallback === 'function') {
279279
callback = optionsOrCallback;
280280
} else if (optionsOrCallback) {
@@ -323,21 +323,21 @@ export class TransferManager {
323323
return Promise.all(promises);
324324
}
325325

326-
async downloadLargeFile(
326+
async downloadFileInChunks(
327327
file: File,
328-
options?: LargeFileDownloadOptions
328+
options?: DownloadFileInChunksOptions
329329
): Promise<DownloadResponse>;
330-
async downloadLargeFile(
330+
async downloadFileInChunks(
331331
file: File,
332332
callback: DownloadCallback
333333
): Promise<void>;
334-
async downloadLargeFile(
334+
async downloadFileInChunks(
335335
file: File,
336-
options: LargeFileDownloadOptions,
336+
options: DownloadFileInChunksOptions,
337337
callback: DownloadCallback
338338
): Promise<void>;
339339
/**
340-
* @typedef {object} LargeFileDownloadOptions
340+
* @typedef {object} DownloadFileInChunksOptions
341341
* @property {number} [concurrencyLimit] The number of concurrently executing promises
342342
* to use when downloading the file.
343343
* @property {number} [chunkSizeBytes] The size in bytes of each chunk to be downloaded.
@@ -348,7 +348,7 @@ export class TransferManager {
348348
* that utilizes {@link File#download} to perform the download.
349349
*
350350
* @param {object} [file] {@link File} to download.
351-
* @param {LargeFileDownloadOptions} [options] Configuration options.
351+
* @param {DownloadFileInChunksOptions} [options] Configuration options.
352352
* @param {DownloadCallback} [callbac] Callback function.
353353
* @returns {Promise<DownloadResponse | void>}
354354
*
@@ -373,12 +373,12 @@ export class TransferManager {
373373
* const response = await transferManager.downloadLargeFile(bucket.file('large-file.txt');
374374
* @experimental
375375
*/
376-
async downloadLargeFile(
376+
async downloadFileInChunks(
377377
file: File,
378-
optionsOrCallback?: LargeFileDownloadOptions | DownloadCallback,
378+
optionsOrCallback?: DownloadFileInChunksOptions | DownloadCallback,
379379
callback?: DownloadCallback
380380
): Promise<void | DownloadResponse> {
381-
let options: LargeFileDownloadOptions = {};
381+
let options: DownloadFileInChunksOptions = {};
382382
if (typeof optionsOrCallback === 'function') {
383383
callback = optionsOrCallback;
384384
} else if (optionsOrCallback) {
@@ -400,10 +400,7 @@ export class TransferManager {
400400
}
401401

402402
let start = 0;
403-
const filePath = path.join(
404-
options.path || __dirname,
405-
path.basename(file.name)
406-
);
403+
const filePath = options.destination || path.basename(file.name);
407404
const fileToWrite = await fsp.open(filePath, 'w+');
408405
while (start < size) {
409406
const chunkStart = start;

0 commit comments

Comments
 (0)