How to use the @ionic/utils-stream.WritableStreamBuffer function in @ionic/utils-stream

To help you get started, we’ve selected a few @ionic/utils-stream 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 ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should error for signal exit', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const buf = new WritableStreamBuffer();
      const promise = cmd.run();
      promise.p.stdout.pipe(buf);
      promise.p.stderr.pipe(buf);
      mockSpawnStdout.stop();
      mockSpawnStderr.stop();
      await promisifyEvent(buf, 'finish');
      cp.emit('close', null, 'SIGINT');
      await expect(promise).rejects.toThrow('Signal exit from subprocess.');
    });
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should pipe stdout and stderr in run()', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const stdoutMock = new WritableStreamBuffer();
      const stderrMock = new WritableStreamBuffer();
      const promise = cmd.run();
      promise.p.stdout.pipe(stdoutMock);
      promise.p.stderr.pipe(stderrMock);
      mockSpawnStdout.feed('hello world!');
      mockSpawnStdout.stop();
      mockSpawnStderr.feed('oh no!');
      mockSpawnStderr.stop();
      await Promise.all([promisifyEvent(stdoutMock, 'finish'), promisifyEvent(stderrMock, 'finish')]);
      cp.emit('close', 0);
      await promise;
      expect(mockCrossSpawn).toHaveBeenCalledTimes(1);
      expect(stdoutMock.consume().toString()).toEqual('hello world!');
      expect(stderrMock.consume().toString()).toEqual('oh no!');
    });
github ionic-team / ionic-cli / packages / @ionic / cli-framework / src / lib / __tests__ / logger.ts View on Github external
it('should create a writable stream', () => {
          const stream = new WritableStreamBuffer();
          const handler = new StreamHandler({ stream });
          const logger = new Logger({ handlers: new Set([handler]) });
          const ws = logger.createWriteStream();
          ws.write('hi');
          expect(stream.consume().toString()).toEqual('hi\n');
        });
github ionic-team / ionic-cli / packages / @ionic / cli-framework / src / lib / __tests__ / logger.ts View on Github external
beforeEach(() => {
          stream = new WritableStreamBuffer();
          handler = new StreamHandler({ stream });
          logger = new Logger({ handlers: new Set([handler]) });
        });
github ionic-team / ionic-cli / packages / @ionic / cli-framework / src / lib / __tests__ / logger.ts View on Github external
beforeEach(() => {
        stream = new WritableStreamBuffer();
        handler = new StreamHandler({ stream });
        logger = new Logger({ handlers: new Set([handler]) });
      });
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / index.ts View on Github external
async combinedOutput(): Promise {
    this._options.stdio = 'pipe';

    const promise = this.run();
    const buf = new WritableStreamBuffer();

    promise.p.stdout.pipe(buf);
    promise.p.stderr.pipe(buf);

    try {
      await promise;
    } catch (e) {
      e.output = buf.consume().toString();
      throw e;
    }

    return buf.consume().toString();
  }
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / index.ts View on Github external
async output(): Promise {
    this._options.stdio = 'pipe';

    const promise = this.run();
    const stdoutBuf = new WritableStreamBuffer();
    const stderrBuf = new WritableStreamBuffer();
    const combinedBuf = new WritableStreamBuffer();

    promise.p.stdout.pipe(stdoutBuf);
    promise.p.stdout.pipe(combinedBuf);
    promise.p.stderr.pipe(stderrBuf);
    promise.p.stderr.pipe(combinedBuf);

    try {
      await promise;
    } catch (e) {
      stdoutBuf.end();
      stderrBuf.end();
      e.output = combinedBuf.consume().toString();
      throw e;
    }
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / index.ts View on Github external
async output(): Promise {
    this._options.stdio = 'pipe';

    const promise = this.run();
    const stdoutBuf = new WritableStreamBuffer();
    const stderrBuf = new WritableStreamBuffer();
    const combinedBuf = new WritableStreamBuffer();

    promise.p.stdout.pipe(stdoutBuf);
    promise.p.stdout.pipe(combinedBuf);
    promise.p.stderr.pipe(stderrBuf);
    promise.p.stderr.pipe(combinedBuf);

    try {
      await promise;
    } catch (e) {
      stdoutBuf.end();
      stderrBuf.end();
      e.output = combinedBuf.consume().toString();
      throw e;
    }

    stderrBuf.end();
github ionic-team / ionic-cli / packages / ionic / src / lib / integrations / cordova / resources.ts View on Github external
.on('response', res => {
        debug('response %d received for %s: (id: %s)', res.status, resource.name, resource.imageId);

        if (res.status !== 200) {
          const generalErrorMsg = !res.status || res.status >= 500
            ? 'the server may be experiencing difficulties right now--please try again later.'
            : 'the server marked a source image as invalid for this resource.';

          errorMarker = true;

          const buf = new WritableStreamBuffer();

          res.pipe(buf);

          buf.on('finish', () => {
            let serverMsg = buf.consume().toString();

            try {
              serverMsg = JSON.parse(serverMsg).Error;
            } catch (e) {
              serverMsg = formatResponseError(req, res.status, serverMsg);
            }

            result.error = new Error(
              `Error while generating ${strong(resource.name)}: ` +
              `${generalErrorMsg}\n\n` +
              `Server: "${serverMsg}"`
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / index.ts View on Github external
async output(): Promise {
    this._options.stdio = 'pipe';

    const promise = this.run();
    const stdoutBuf = new WritableStreamBuffer();
    const stderrBuf = new WritableStreamBuffer();
    const combinedBuf = new WritableStreamBuffer();

    promise.p.stdout.pipe(stdoutBuf);
    promise.p.stdout.pipe(combinedBuf);
    promise.p.stderr.pipe(stderrBuf);
    promise.p.stderr.pipe(combinedBuf);

    try {
      await promise;
    } catch (e) {
      stdoutBuf.end();
      stderrBuf.end();
      e.output = combinedBuf.consume().toString();
      throw e;
    }

@ionic/utils-stream

Stream utils for NodeJS

MIT
Latest version published 11 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages