@google-cloud/storage#File TypeScript Examples

The following examples show how to use @google-cloud/storage#File. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: googleStorage.ts    From backstage with Apache License 2.0 6 votes vote down vote up
private getFilesForFolder(folder: string): Promise<string[]> {
    const fileMetadataStream: Readable = this.storageClient
      .bucket(this.bucketName)
      .getFilesStream({ prefix: folder });

    return new Promise((resolve, reject) => {
      const files: string[] = [];

      fileMetadataStream.on('error', error => {
        // push file to file array
        reject(error);
      });

      fileMetadataStream.on('data', (file: File) => {
        // push file to file array
        files.push(file.name);
      });

      fileMetadataStream.on('end', () => {
        // resolve promise
        resolve(files);
      });
    });
  }
Example #2
Source File: gcs_store.ts    From CIAnalyzer with MIT License 5 votes vote down vote up
file: File
Example #3
Source File: gcp-cache.ts    From nx-extend with MIT License 5 votes vote down vote up
private async downloadFile(cacheDirectory: string, file: File) {
    const destination = join(cacheDirectory, file.name)
    mkdirSync(dirname(destination), {
      recursive: true
    })

    await file.download({ destination })
  }
Example #4
Source File: GoogleMigration.ts    From backstage with Apache License 2.0 5 votes vote down vote up
_write(file: File, _encoding: BufferEncoding, next: Function) {
    let shouldCallNext = true;
    let newFile;
    try {
      newFile = lowerCaseEntityTripletInStoragePath(file.name);
    } catch (e) {
      assertError(e);
      this.logger.warn(e.message);
      next();
      return;
    }

    // If all parts are already lowercase, ignore.
    if (newFile === file.name) {
      next();
      return;
    }

    // Allow up to n-many files to be migrated at a time.
    this.inFlight++;
    if (this.inFlight < this.maxConcurrency) {
      next();
      shouldCallNext = false;
    }

    // Otherwise, copy or move the file.
    const migrate = this.removeOriginal
      ? file.move.bind(file)
      : file.copy.bind(file);
    this.logger.verbose(`Migrating ${file.name}`);
    migrate(newFile)
      .catch(e =>
        this.logger.warn(`Unable to migrate ${file.name}: ${e.message}`),
      )
      .finally(() => {
        this.inFlight--;
        if (shouldCallNext) {
          next();
        }
      });
  }
Example #5
Source File: storage.ts    From mail-my-ballot with Apache License 2.0 5 votes vote down vote up
file: File