diff --git a/src/bucket.ts b/src/bucket.ts index 20aca29cf..25227f9ea 100644 --- a/src/bucket.ts +++ b/src/bucket.ts @@ -127,6 +127,7 @@ export interface GetFilesOptions { endOffset?: string; includeTrailingDelimiter?: boolean; prefix?: string; + matchGlob?: string; maxApiCalls?: number; maxResults?: number; pageToken?: string; @@ -2528,6 +2529,8 @@ class Bucket extends ServiceObject { * in addition to the relevant part of the object name appearing in prefixes[]. * @property {string} [prefix] Filter results to objects whose names begin * with this prefix. + * @property {string} [matchGlob] A glob pattern used to filter results, + * for example foo*bar * @property {number} [maxApiCalls] Maximum number of API calls to make. * @property {number} [maxResults] Maximum number of items plus prefixes to * return per call. diff --git a/system-test/storage.ts b/system-test/storage.ts index 469683da6..d99af4441 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -3057,6 +3057,28 @@ describe('storage', () => { }); }); + it('should only get files matching the supplied matchGlob argument', async () => { + let expectedFileNames = ['CloudLogo1', 'CloudLogo2', 'CloudLogo3']; + let [files] = await bucket.getFiles({matchGlob: 'CloudLogo*'}); + assert.strictEqual(files.length, expectedFileNames.length); + for (const curFile of files) { + assert.strictEqual(expectedFileNames.includes(curFile.name), true); + } + + expectedFileNames = [ + `${DIRECTORY_NAME}/CloudLogo4`, + `${DIRECTORY_NAME}/CloudLogo5`, + `${DIRECTORY_NAME}/inner/CloudLogo6`, + ]; + [files] = await bucket.getFiles({ + matchGlob: `${DIRECTORY_NAME}/**/CloudLogo*`, + }); + assert.strictEqual(files.length, expectedFileNames.length); + for (const curFile of files) { + assert.strictEqual(expectedFileNames.includes(curFile.name), true); + } + }); + it('should paginate the list', async () => { const query = { maxResults: NEW_FILES.length - 1,