How to use the readable-stream.Transform function in readable-stream

To help you get started, we’ve selected a few readable-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 GraftJS / jschan / test / abstract_session.js View on Github external
it('should error if the stream is a Transform', function(done) {
      var chan   = outSession.WriteChannel();
      var bin    = new Transform();

      outSession.once('error', function(err) {
        expect(err.message).to.eql('unable to auto-serialize a Transform stream not in object mode');
        done();

        outSession.on('error', function() {});
      });

      chan.end({
        bin: bin
      });

      inSession.on('channel', function server(chan) {
        chan.resume(); // skip all of it
      });
    });
github stackhtml / documentify / test / transforms.js View on Github external
function append (text) {
  return Transform({
    write (chunk, enc, cb) {
      this.push(chunk)
      cb()
    },
    flush (cb) {
      this.push('\n' + text)
      cb()
    }
  })
}
github upringjs / upring-kv / bin.js View on Github external
function handleGet (req, res) {
    const split = req.url.split('?')
    const key = split[0]
    const query = querystring.parse(split[1])
    if (query.live) {
      res.writeHead(200, {
        'Content-Type': 'text/event-stream',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive'
      })
      var transform = new Transform({
        objectMode: true,
        transform (chunk, enc, cb) {
          this.push('data:' + JSON.stringify(chunk.value) + '\n\n')
          cb()
        }
      })
      pump(db.liveUpdates(key), transform, res)
    } else {
      db.get(key, function (err, data) {
        if (err) {
          res.statusCode = 500
          res.end(err.message)
          return
        }

        if (!data) {
github ArkEcosystem / core / packages / core-logger-pino / src / driver.ts View on Github external
private createPrettyTransport(level: string, prettyOptions?: PrettyOptions): Transform {
        const pinoPretty = PinoPretty({
            ...{
                levelFirst: false,
                translateTime: "yyyy-mm-dd HH:MM:ss.l",
            },
            ...prettyOptions,
        });

        const levelValue = this.logger.levels.values[level];

        return new Transform({
            transform(chunk, enc, cb) {
                try {
                    const json = JSON.parse(chunk);
                    if (json.level >= levelValue) {
                        const line = pinoPretty(json);
                        if (line !== undefined) {
                            return cb(null, line);
                        }
                    }
                } catch (ex) {
                    //
                }

                return cb();
            },
        });
github whitfin / neek / lib / reader.js View on Github external
module.exports = function(){
    var reader = new stream.Transform();

    reader.algorithm = 'sha1';

    reader.count = 0;

    reader.isTTY = false;

    reader.reset = function(){
        this.count = 0;
        this.set.clear();
        this.started = false;
    };

    reader.process = function(element){
        var hash = crypto
            .createHash(this.algorithm || 'sha1')
github mqttjs / MQTT.js / lib / connect / wx.js View on Github external
function buildProxy () {
  var proxy = new Transform()
  proxy._write = function (chunk, encoding, next) {
    socketTask.send({
      data: chunk.buffer,
      success: function () {
        next()
      },
      fail: function (errMsg) {
        next(new Error(errMsg))
      }
    })
  }
  proxy._flush = function socketEnd (done) {
    socketTask.close({
      success: function () {
        done()
      }
github words / afinn-165 / build.js View on Github external
function onresponse(res) {
  res
    .resume()
    .on('error', bail)
    .pipe(csv({delimiter: '\t', objectMode: true}))
    .pipe(new Transform({objectMode: true, transform: onrow}))
    .pipe(join(',\n'))
    .pipe(wrap('{\n', '\n}\n'))
    .pipe(fs.createWriteStream('index.json'))
}
github ipfs / js-ipfs-http-client / src / stats / bw-readable-stream.js View on Github external
return (opts) => {
    opts = opts || {}

    const pt = new Stream.Transform({
      objectMode: true,
      transform (chunk, encoding, cb) {
        cb(null, transformChunk(chunk))
      }
    })

    send({
      path: 'stats/bw',
      qs: opts
    }, (err, stream) => {
      if (err) {
        return pt.destroy(err)
      }

      pump(stream, pt)
    })
github ipfs / js-ipfs-http-client / src / files / ls-readable-stream.js View on Github external
return (args, opts) => {
    opts = opts || {}

    const transform = new Transform({
      objectMode: true,

      transform (entry, encoding, callback) {
        callback(null, toEntry(entry))
      }
    })

    const output = new PassThrough({
      objectMode: true
    })

    send({
      path: 'files/ls',
      args: args,
      qs: Object.assign({}, opts, { stream: true })
    }, (err, res) => {
github hax / semicolon-less.js / gulpplugin.js View on Github external
module.exports = function (options) {
	var t = new Transform({
		objectMode: true,
		//transform: ...
	})

	//should reformat after readable-stream support simplified constructor api
	t._transform = function (file, enc, next) {
		if (file.isBuffer()) {
			file.contents = less(file.contents, options)
		} else if (file.isStream()) {
			file.contents.on('error', this.emit.bind(this, 'error'))
			file.contents = less(file.contents, options)
		}
		this.push(file)
		return next()
	}