How to use concat-stream - 10 common examples

To help you get started, we’ve selected a few concat-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 beakerbrowser / beaker / app / bg / logger.js View on Github external
return new Promise((resolve, reject) => {
    opts.limit = opts.limit || 100
    var readFn = opts.sort === 'desc' ? fsReverse : fs.createReadStream
    var readStream = readFn(getLogPath(opts.logFile || 0), {encoding: 'utf8'})
    const nosplit = (readFn === fsReverse) // fs-reverse splits for us
    pump(
      readPipeline(readStream, opts, nosplit),
      concat({encoding: 'object'}, res => resolve(/** @type any */(res))),
      reject
    )
  })
}
github SassDoc / sassdoc / src / parser.js View on Github external
})
      }

      let parseError = false;
      try {
        if (file.isBuffer()) {
          let args = {
            buf: file.contents,
            name: path.basename(file.relative),
            path: file.relative,
          }
          parseFile(args)
        }

        if (file.isStream()) {
          file.pipe(concat(buf => {
            parseFile({ buf })
          }))
        }
      } catch (error) {
        parseError = true;
        cb(error);
      }

      // Pass-through.
      if (!parseError) {
        cb(null, file)
      }
    }
github cypress-io / cypress / packages / net-stubbing / lib / server / intercept-request.ts View on Github external
}

  if (route.staticResponse) {
    emitReceived()
    sendStaticResponse(request.res, route.staticResponse, request.onResponse!)

    return // don't call cb since we've satisfied the response here
  }

  // if we already have a body, just emit
  if (frame.req.body) {
    return emitReceived()
  }

  // else, buffer the body
  request.req.pipe(concatStream((reqBody) => {
    frame.req.body = reqBody.toString()
    emitReceived()
  }))
}
github google / dorusu-js / lib / codec.js View on Github external
function MsgHeaderStream(opts, callback) {
  // Initializes the base class with the buffer
  this.opts = opts || {};
  ConcatStream.call(this, { encoding: 'buffer' }, callback);
  this.size = 0;
}
MsgHeaderStream.prototype = Object.create(
github google / dorusu-js / lib / codec.js View on Github external
/**
 * MsgHeaderStream is a `Writable` that concatenates strings or `Buffer`
 * and invokes a callback with an `Buffer` prepended by its length.
 *
 * @param {object} opts options for determining how the data is written
 * @param {function} callback is invoked when all data has been written
 * @constructor
 */
function MsgHeaderStream(opts, callback) {
  // Initializes the base class with the buffer
  this.opts = opts || {};
  ConcatStream.call(this, { encoding: 'buffer' }, callback);
  this.size = 0;
}
MsgHeaderStream.prototype = Object.create(
  ConcatStream.prototype, {constructor: {value: MsgHeaderStream }});

/**
 * Overrides ConcatStream._write to count the size of data in bytes.
 */
MsgHeaderStream.prototype._write = function(chunk, enc, next) {
  this.body.push(chunk);
  this.size += chunk.length;
  next();
};

/**
 * Overrides `ConcatStream.getBody` to return the body prefixed with the
 * size.
 *
 * @returns {external:Buffer} containing the data written to this stream
 *                            prefixed with its length
github beakerbrowser / beaker / app / background-process / networks / dat / library.js View on Github external
return new Promise((resolve, reject) => {
    let rs = debugLogFile.createReadStream()
    rs
      .pipe(split())
      .pipe(through({encoding: 'utf8', decodeStrings: false}, (data, _, cb) => {
        if (data && data.startsWith(key)) {
          return cb(null, data.slice(key.length) + '\n')
        }
        cb()
      }))
      .pipe(concat({encoding: 'string'}, resolve))
    rs.on('error', reject)
  })
}
github beakerbrowser / beaker / app / background-process / web-apis / dat-archive.js View on Github external
return new Promise((resolve, reject) => {
        var stream = checkoutFS.history({live: false, start, end})
        stream.pipe(concat({encoding: 'object'}, values => {
          values = values.map(massageHistoryObj)
          if (reverse) values.reverse()
          resolve(values)
        }))
        stream.on('error', reject)
      })
    })
github minio / minio-js / src / main / upload.js View on Github external
var request = transport.request(requestParams, (response) => {
      if (response.statusCode !== 200) {
        return parseError(response, cb)
      }
      response.pipe(Concat(xml => {
        var parsedXml = ParseXml(xml.toString()),
          uploadId = null
        parsedXml.root.children.forEach(element => {
          if (element.name === 'UploadId') {
            uploadId = element.content
          }
        })

        if (uploadId) {
          return cb(null, uploadId)
        }
        cb('unable to get upload id')
      }))
    })
    request.end()
github expo / expo-cli / packages / xdl / src / TurtleApi.ts View on Github external
return new Promise(resolve => {
      formData.pipe(concat({ encoding: 'buffer' }, data => resolve({ data })));
    });
  }
github beakerbrowser / beaker / app / background-process / analytics.js View on Github external
}, (res) => {
      if (res.statusCode === 204) {
        debug('Ping succeeded')
        resolve()
      } else {
        res.setEncoding('utf8')
        res.pipe(concat(body => debug('Ping failed', res.statusCode, body)))
        reject()
      }
    })
    req.on('error', err => {

concat-stream

writable stream that concatenates strings or binary data and calls a callback with the result

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis