How to use the @verdaccio/streams.ReadTarball function in @verdaccio/streams

To help you get started, we’ve selected a few @verdaccio/streams examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github verdaccio / verdaccio / src / lib / local-storage.ts View on Github external
private _streamSuccessReadTarBall(storage: any, filename: string): IReadTarball {
    const stream: IReadTarball = new ReadTarball({});
    const readTarballStream = storage.readTarball(filename);
    const e404 = ErrorCode.getNotFound;

    stream.abort = function(): void {
      if (_.isNil(readTarballStream) === false) {
        readTarballStream.abort();
      }
    };

    readTarballStream.on('error', function(err) {
      // @ts-ignore
      if (err.code === STORAGE.NO_SUCH_FILE_ERROR || err.code === HTTP_STATUS.NOT_FOUND) {
        stream.emit('error', e404('no such file available'));
      } else {
        stream.emit('error', err);
      }
github verdaccio / verdaccio / src / lib / storage.ts View on Github external
public getTarball(name: string, filename: string): IReadTarball {
    const readStream = new ReadTarball({});
    readStream.abort = function() {};

    const self = this;

    // if someone requesting tarball, it means that we should already have some
    // information about it, so fetching package info is unnecessary

    // trying local first
    // flow: should be IReadTarball
    let localStream: any = self.localStorage.getTarball(name, filename);
    let isOpen = false;
    localStream.on(
      'error',
      (err): any => {
        if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {
          return readStream.emit('error', err);
github verdaccio / verdaccio / src / lib / local-storage.ts View on Github external
public search(startKey: string, options: any): IReadTarball {
    const stream = new ReadTarball({ objectMode: true });

    this._searchEachPackage(
      (item: Package, cb: CallbackAction): void => {
        // @ts-ignore
        if (item.time > parseInt(startKey, 10)) {
          this.getPackageMetadata(item.name, (err: VerdaccioError, data: Package): void => {
            if (err) {
              return cb(err);
            }

            // @ts-ignore
            const time = new Date(item.time).toISOString();
            const result = prepareSearchPackage(data, time);
            if (_.isNil(result) === false) {
              stream.push(result);
            }
github verdaccio / verdaccio / src / lib / storage / local / local-storage.js View on Github external
_streamSuccessReadTarBall(storage, filename) {
    const stream = new customStream.ReadTarball();
    const readTarballStream = storage.createReadStream(filename);
    const e404 = this.utils.ErrorCode.get404;

    stream.abort = function() {
      if (_.isNil(readTarballStream) === false) {
        readTarballStream.abort();
      }
    };

    readTarballStream.on('error', function(err) {
      if (err && err.code === noSuchFile) {
        stream.emit('error', e404('no such file available'));
      } else {
        stream.emit('error', err);
      }
    });
github verdaccio / local-storage / src / local-storage.js View on Github external
_streamSuccessReadTarBall(storage: ILocalFS, filename: string) {
    const stream = new ReadTarball();
    const readTarballStream = storage.createReadStream(filename);
    const e404 = this.utils.ErrorCode.get404;

    stream.abort = function() {
      if (_.isNil(readTarballStream) === false) {
        readTarballStream.abort();
      }
    };

    readTarballStream.on('error', function(err) {
      if (err && err.code === noSuchFile) {
        stream.emit('error', e404('no such file available'));
      } else {
        stream.emit('error', err);
      }
    });
github verdaccio / local-storage / src / local-storage.js View on Github external
_createFailureStreamResponse() {
    const stream = new ReadTarball();

    process.nextTick(() => {
      stream.emit('error', this._getFileNotAvailable());
    });
    return stream;
  }
github verdaccio / verdaccio / src / lib / local-storage.ts View on Github external
private _createFailureStreamResponse(): IReadTarball {
    const stream: IReadTarball = new ReadTarball({});

    process.nextTick((): void => {
      stream.emit('error', this._getFileNotAvailable());
    });
    return stream;
  }
github verdaccio / verdaccio / src / lib / storage / local / local-storage.js View on Github external
_createFailureStreamResponse() {
    const stream = new customStream.ReadTarball();

    process.nextTick(() => {
      stream.emit('error', this._getFileNotAvailable());
    });
    return stream;
  }
github verdaccio / local-storage / src / local-fs.ts View on Github external
public readTarball(name: string) {
    const pathName: string = this._getStorage(name);
    this.logger.debug({ packageName: name }, '[local-storage/readTarball] read a tarball for package: @{packageName}');

    const readTarballStream = new ReadTarball({});

    const readStream = fs.createReadStream(pathName);

    readStream.on('error', function(err) {
      readTarballStream.emit('error', err);
    });

    readStream.on('open', function(fd) {
      fs.fstat(fd, function(err, stats) {
        if (_.isNil(err) === false) {
          return readTarballStream.emit('error', err);
        }
        readTarballStream.emit('content-length', stats.size);
        readTarballStream.emit('open');
        readStream.pipe(readTarballStream);
      });

@verdaccio/streams

Stream extension for Verdaccio

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis