How to use the byline function in byline

To help you get started, we’ve selected a few byline 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 beepboopbangbang / githoard / src / main / modules / git.js View on Github external
processCallback: (process) => {
        byline(process.stderr).on('data', (chunk) => {
          // if (chunk.startsWith('Counting objects: ')) {
          //   const percent = this.tryParse(chunk)
          //   if (percent) {
          //     console.log('total object', percent)
          //     this.setReceivingProgress(repo, percent)
          //   }
          //   return
          // }
          if (chunk.startsWith('Receiving objects: ')) {
            const percent = this.tryParse(chunk);
            if (percent) {
              // console.log('receiving progress', percent)
              this.setReceivingProgress(repo, percent);
            }
            return;
          }
github zeit / pkg-fetch / lib / spawn.js View on Github external
export function spawn (cmd, args, opts) {
  const child = chip.spawn(cmd, args, opts);
  const stdout = byline(child.stdout);
  const stderr = byline(child.stderr);
  const lines = [];

  let onData = function (data) {
    const time = (new Date()).getTime();
    lines.push([ time, data.toString() ]); // TODO chalk stdout/stderr?
    const { thresholds } = this; // eslint-disable-line no-invalid-this
    if (thresholds) {
      for (const key in thresholds) {
        if (data.indexOf(key) >= 0) {
          const p = thresholds[key];
          log.showProgress(p);
          if (DEBUG_THRESHOLDS) {
            lines.push([ time, '************' ]);
            lines.push([ time, p + ': ' + key ]);
            lines.push([ time, '************' ]);
github zeit / pkg-fetch / lib / spawn.js View on Github external
export function spawn (cmd, args, opts) {
  const child = chip.spawn(cmd, args, opts);
  const stdout = byline(child.stdout);
  const stderr = byline(child.stderr);
  const lines = [];

  let onData = function (data) {
    const time = (new Date()).getTime();
    lines.push([ time, data.toString() ]); // TODO chalk stdout/stderr?
    const { thresholds } = this; // eslint-disable-line no-invalid-this
    if (thresholds) {
      for (const key in thresholds) {
        if (data.indexOf(key) >= 0) {
          const p = thresholds[key];
          log.showProgress(p);
          if (DEBUG_THRESHOLDS) {
            lines.push([ time, '************' ]);
            lines.push([ time, p + ': ' + key ]);
            lines.push([ time, '************' ]);
          }
github vladimiry / ElectronMail / scripts / prepare-protonmail-webclient.ts View on Github external
async function _exec(args: Arguments) {
    consoleLog(chalk.magenta(`Executing Shell command:`), chalkConsoleValue(JSON.stringify(args)));

    const taskPromise = spawnAsync(...args);

    byline(taskPromise.child.stdout).on("data", (chunk) => consoleLog(formatChunk(chunk)));
    byline(taskPromise.child.stderr).on("data", (chunk) => consoleError(formatChunk(chunk)));
    taskPromise.child.on("uncaughtException", (error) => {
        consoleError(`Failed Shell command execution (uncaught exception): ${JSON.stringify(args)}`, error);
        process.exit(1);
    });

    try {
        const {status: exitCode} = await taskPromise;

        if (exitCode) {
            consoleError(`Failed Shell command execution (${exitCode} exit code): ${JSON.stringify(args)}`);
            process.exit(exitCode);
        }
    } catch (error) {
        consoleError(`Failed Shell command execution: ${JSON.stringify(args)}`, error.stack);
        process.exit(1);
github vladimiry / ElectronMail / scripts / prepare-protonmail-webclient.ts View on Github external
async function _exec(args: Arguments) {
    consoleLog(chalk.magenta(`Executing Shell command:`), chalkConsoleValue(JSON.stringify(args)));

    const taskPromise = spawnAsync(...args);

    byline(taskPromise.child.stdout).on("data", (chunk) => consoleLog(formatChunk(chunk)));
    byline(taskPromise.child.stderr).on("data", (chunk) => consoleError(formatChunk(chunk)));
    taskPromise.child.on("uncaughtException", (error) => {
        consoleError(`Failed Shell command execution (uncaught exception): ${JSON.stringify(args)}`, error);
        process.exit(1);
    });

    try {
        const {status: exitCode} = await taskPromise;

        if (exitCode) {
            consoleError(`Failed Shell command execution (${exitCode} exit code): ${JSON.stringify(args)}`);
            process.exit(exitCode);
        }
    } catch (error) {
        consoleError(`Failed Shell command execution: ${JSON.stringify(args)}`, error.stack);
        process.exit(1);
    }
github vladimiry / ElectronMail / scripts / prepare-protonmail-webclient.ts View on Github external
processCallback: ({stderr}) => {
                byline(stderr).on("data", (chunk) => consoleLog(formatChunk(chunk)));
            },
            ...options,
github vladimiry / ElectronMail / scripts / lib.ts View on Github external
LOG_LEVELS.value(JSON.stringify({command, args, options}, null, 2)),
    );

    const spawnPromise = spawnAsync(command, args, options);

    if (printStd) {
        const {stdout, stderr} = spawnPromise.child;

        if (stdout) {
            byline(stdout).on("data", (chunk) => {
                LOG(chalk(formatStreamChunk(chunk)));
            });
        }

        if (stderr) {
            byline(stderr).on("data", (chunk) => {
                LOG(chalk(formatStreamChunk(chunk)));
            });
        }
    }

    try {
        return await spawnPromise;
    } catch (error) {
        const omitProps: Array>> = ["output", "stderr", "stdout"];
        omitProps.forEach((omitProp) => delete error[omitProp]);
        throw error;
    }
}
github vladimiry / ElectronMail / scripts / lib.ts View on Github external
export async function execShell(
    [command, args, options]: Arguments,
    {printStd = true}: { printStd?: boolean } = {},
): Promise>> {
    LOG(
        LOG_LEVELS.title("Executing Shell command:"),
        LOG_LEVELS.value(JSON.stringify({command, args, options}, null, 2)),
    );

    const spawnPromise = spawnAsync(command, args, options);

    if (printStd) {
        const {stdout, stderr} = spawnPromise.child;

        if (stdout) {
            byline(stdout).on("data", (chunk) => {
                LOG(chalk(formatStreamChunk(chunk)));
            });
        }

        if (stderr) {
            byline(stderr).on("data", (chunk) => {
                LOG(chalk(formatStreamChunk(chunk)));
            });
        }
    }

    try {
        return await spawnPromise;
    } catch (error) {
        const omitProps: Array>> = ["output", "stderr", "stdout"];
        omitProps.forEach((omitProp) => delete error[omitProp]);
github antonycourtney / tad / src / csvimport.js View on Github external
return new Promise((resolve, reject) => {
    const ret = []
    const fstream = fs.createReadStream(path, {encoding: 'utf8'})
    const lstream = byline(fstream)
    let linesRead = 0
    lstream.on('readable', () => {
      while (linesRead < lcount) {
        let line
        line = lstream.read()
        if (line === null) {
          resolve(ret)
          return
        } else {
          ret.push(line)
          linesRead++
        }
      }
      fstream.pause()
      resolve(ret)
    })

byline

simple line-by-line stream reader

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis