How to use highland - 10 common examples

To help you get started, we’ve selected a few highland 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 GeoXForm / GeoXForm / src / index.js View on Github external
function createStream (format, options) {
  let ogr
  options = options || {}
  options.path = `${options.tempPath || '.'}/${random.generate()}`
  mkdirp.sync(options.path)
  const output = _.pipeline(stream => {
    // init VRT stream and attach listeners otherwise the error event will be missed
    const through = _()

    stream
    .pipe(VRT.createStream(options))
    .on('log', l => output.emit('log', l))
    .once('error', e => {
      output.emit('error', e)
      cleanup(output, options.path)
    })
    .on('error', e => output.emit('log', {level: 'error', message: e}))
    .on('properties', p => Object.assign(options, p))
    .on('finish', () => {
      ogr = OGR.createStream(format, options)

      ogr
github GeoXForm / GeoXForm / lib / ogr.js View on Github external
function createStream(format, options) {
  options.input = options.path + '/layer.vrt';
  var vrt = fs.createWriteStream(options.input);
  options.name = options.name ? sanitize(options.name) : 'output';

  var cmd = Cmd.create(format, options);

  var output = _.pipeline(function (stream) {
    var temp = _();
    stream.pipe(vrt).on('finish', function () {
      if (format === 'zip') return shapefile.createStream(options);
      var ogr = spawn('ogr2ogr', cmd);
      // TODO can I just pipe out vs writing to temp?
      ogr.stdout.on('data', function (data) {
        return temp.write(data);
      });
      ogr.stderr.on('data', function (data) {
        return output.emit('log', { level: 'debug', message: data.toString() });
      });
      ogr.on('close', function (c) {
        output.emit('log', { level: 'info', message: 'Executing: OGR2OGR ' + cmd.join(' ') });
        if (c > 0) output.emit('error', new Error('OGR Failed'));else temp.end();
      });
    });
github Streampunk / casparcl / scratch / high_beam_cl.js View on Github external
})

	let counter = 0

	const gen = (push, next) => {
		dm.read().then(p => {
			if (p.stream_index === 0) {
				push(null, p)
				next()
			} else {
				gen(push, next)
			}
		})
	}

	let pipel = H.pipeline(
		H.flatMap(p => { console.log('DECODE', process.hrtime(stamp)); return H(dec.decode(p)); }),
		H.flatMap(p => { console.log('ENCODE', process.hrtime(stamp)); return H(enc.encode(p.frames)); }),
		H.flatMap(p => { console.log('PROCESS', process.hrtime(stamp)); return H(processFrame(p.packets[0].data)); })
	)

	H(gen)
	// .drop(400)
	// .tap(() => console.log(counter++, stamp))
	.through(pipel)
	// .tap(console.log)
	.consume((err, x, push, next) => {
		if (lstamp === -1) {
			lstamp = process.hrtime()
		}
		let diff = process.hrtime(lstamp)
		let wait = (++counter * 40) - ((diff[0] * 1000) + (diff[1] / 1000000 | 0) )
github GeoXForm / GeoXForm / index.js View on Github external
function createStream(format, options) {
  var stream = _.pipeline(function (stream) {
    return stream.pipe(VRT.createStream(options)).on('log', function (l) {
      return stream.emit('log', l);
    }).on('error', function (e) {
      return stream.emit('error', e);
    }).pipe(OGR.createStream(format, options)).on('log', function (l) {
      return stream.emit('log', l);
    }).on('error', function (e) {
      return stream.emit('error', e);
    });
  });
  return stream;
}
github crcn / mesh.js / old / cases / database / index.js View on Github external
it("can load multiple items", function(next) {
    insertMultipleItems();
    db(mesh.op("load", {
      collection: "items",
      multi: true,
      query: { count: 1 }
    })).
    pipe(_.pipeline(_.collect)).
    on("data", function(data) {
      expect(data.length).to.be(2);
      next();
    });
  });
github GeoXForm / GeoXForm / lib / geojson.js View on Github external
function createStream(options) {
  var start = '{"type":"FeatureCollection","features":[';
  var end = ']}';
  var readStream = _.pipeline(function (s) {
    var features = options && options.json ? _(s).compact().map(JSON.stringify) : _(s).compact();
    return _([start]).concat(features.intersperse(',')).append(end);
  });
  return readStream;
}
github GeoXForm / GeoXForm / src / lib / geojson.js View on Github external
function createStream (options) {
  const start = '{"type":"FeatureCollection","features":['
  const end = ']}'
  const readStream = _.pipeline(s => {
    const features = options && options.json ? _(s).compact().map(JSON.stringify) : _(s).compact()
    return _([start])
      .concat(features.intersperse(','))
      .append(end)
  })
  return readStream
}
github GeoXForm / GeoXForm / lib / vrt.js View on Github external
function createStream(options) {
  var size = options.size || 5000;
  mkdirp.sync(options.path);

  return _.pipeline(function (stream) {
    var first = true;
    var index = 0;
    return stream.splitBy(',{').map(filter).batch(size).consume(function (err, batch, push, next) {
      if (first) {
        push(null, '');
        first = false;
      }
      if (batch === _.nil || batch === '{}') {
        push(null, '');
        return push(null, _.nil);
      }
      var fileName = options.path + '/part.' + index + '.json';
      writeJsonPart(batch, fileName, index).on('finish', function () {
        push(null, addMetadata(fileName));
        index++;
        next();
github crcn / mesh.js / examples / live-todos / entry.js View on Github external
function setData() {
  todosDb(mesh.op("load", { multi: true })).
  pipe(_.pipeline(_.collect)).
  on("data", view.set.bind(view, "todos"));
}
github crcn / mesh.js / old / examples / react / components / _loadState.js View on Github external
async.each(opsAsArray, function(info, next) {
    bus(info.op)
    .pipe(_.pipeline(_.collect))
    .on("data", function(result) {
      if (!info.op.multi) result = result[0];
      results[info.key] = result;
    })
    .once("end", next);
  }, function() {
    complete(void 0, results);

highland

The high-level streams library

Apache-2.0
Latest version published 5 years ago

Package Health Score

62 / 100
Full package analysis

Popular highland functions