Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Storage } from '@google-cloud/storage';
import { Injectable } from '@nestjs/common';
@Injectable()
export class CloudStorageCountService {
public constructor(private readonly storage: Storage) {}
/**
* Get the number of files in a bucket
* @param bucket The bucket name
* @param delimiter The delimiter to use (used to exclude some files).
* > Results will contain only objects whose names, aside from the prefix, do not contain delimiter.
* > Objects whose names, aside from the prefix, contain delimiter will have their name truncated after the delimiter,
* > returned in apiResponse.prefixes.
* > Duplicate prefixes are omitted.
* @see https://googleapis.dev/nodejs/storage/latest/Bucket.html#getFiles
*/
public async countBucketFiles(bucket: string, delimiter?: string): Promise<number> {
const [files] = await this.storage.bucket(bucket).getFiles({ delimiter });
return files.length;
}
}
|