async getFiles()

in src/io/xpi.ts [110:157]


  async getFiles(_onEventsSubscribed?: () => void): Promise<Files> {
    // If we have already processed the file and have data on this instance
    // return that.
    if (this.processed) {
      const wantedFiles: Files = {};
      Object.keys(this.files).forEach((fileName) => {
        if (this.shouldScanFile(fileName, false)) {
          wantedFiles[fileName] = this.files[fileName];
        } else {
          this.stderr.debug(`skipping cached file: ${fileName}`);
        }
      });
      return wantedFiles;
    }

    const zipfile = await this.open();

    return new Promise((resolve, reject) => {
      zipfile.on('error', (err: Error) => {
        reject(new InvalidZipFileError(err.message));
      });

      zipfile.on('entry', (entry: Entry) => {
        this.handleEntry(entry, reject);
      });

      // When the last entry has been processed, resolve the promise.
      //
      // Note: we were using 'close' before because of a potential race
      // condition but we are not able to reproduce it and the `yauzl` code has
      // changed a bit. We are using 'end' again now so that this function
      // continues to work with `autoClose: false`.
      //
      // See: https://github.com/mozilla/addons-linter/pull/43
      zipfile.on('end', () => {
        this.processed = true;
        resolve(this.files);
      });

      if (_onEventsSubscribed) {
        // Run optional callback when we know the event handlers
        // have been inited. Useful for testing.
        if (typeof _onEventsSubscribed === 'function') {
          Promise.resolve().then(() => _onEventsSubscribed());
        }
      }
    });
  }