feat(storage): add support for 'skipIfExists' option for downloadMany… · googleapis/nodejs-storage@729efb2

@@ -30,6 +30,7 @@ import {

3030

TransferManager,

3131

Storage,

3232

DownloadResponse,

33+

DownloadManyFilesOptions,

3334

} from '../src/index.js';

3435

import assert from 'assert';

3536

import * as path from 'path';

@@ -195,6 +196,10 @@ describe('Transfer Manager', () => {

195196

});

196197197198

describe('downloadManyFiles', () => {

199+

beforeEach(() => {

200+

sandbox.stub(fs, 'existsSync').returns(true);

201+

});

202+198203

it('calls download for each provided file', async () => {

199204

let count = 0;

200205

const firstFile = new File(bucket, 'first.txt');

@@ -276,6 +281,27 @@ describe('Transfer Manager', () => {

276281

await transferManager.downloadManyFiles([file], {passthroughOptions});

277282

});

278283284+

it('does not download files that already exist locally when skipIfExists is true', async () => {

285+

const firstFile = new File(bucket, 'first.txt');

286+

sandbox.stub(firstFile, 'download').callsFake(options => {

287+

assert.strictEqual(

288+

(options as DownloadManyFilesOptions).skipIfExists,

289+

0

290+

);

291+

});

292+

const secondFile = new File(bucket, 'second.txt');

293+

sandbox.stub(secondFile, 'download').callsFake(options => {

294+

assert.strictEqual(

295+

(options as DownloadManyFilesOptions).skipIfExists,

296+

0

297+

);

298+

});

299+300+

const files = [firstFile, secondFile];

301+

const options = {skipIfExists: true};

302+

await transferManager.downloadManyFiles(files, options);

303+

});

304+279305

it('does not set the destination when prefix, strip prefix and passthroughOptions.destination are not provided', async () => {

280306

const options = {};

281307

const filename = 'first.txt';