super-stream.through

0.0.3 • Public • Published

Through

NPM version Build Status Dependency Status devDependency Status Coverage Status MIT Licensed

A basic wrapper function around through2@0.4.x

This is the base function used by super-stream as a standalone module. Also it is a drop in replacement for through2

Why shouldn't you use through2 instead of this module?
You wouldn't if all you need is a basic helper for creating stream.Transform.

But if you need some functional style transforms and other stream utilities and reduce your dependencies at the same time, this is your basic through stream you are looking for. For all the API, go here

See also.
super-stream
super-stream.each
super-stream.map
super-stream.reduce
super-stream.filter
super-stream.junction
super-stream.pipeline


through([options,] [transformFn,] [flushFn]);

this is how
 
var expect = require('chai').expect;
var through = require("super-stream.through")
 
var streamA = through.obj(function(counter, enc, done){
  counter += 1;
  done(null, counter);
});
var streamB = through({objectMode: true}, function(counter, enc, done){
  counter += 1;
  done(null, counter);
});
 
thr = through.factory({objectMode: true});
 
streamA.pipe(streamB).pipe(thr(function(counter, enc, done){
  expect(counter).to.be.equal(2);
}));
 
streamA.write(0);
 
 
var streamA = through(function(chunk, enc, done){
  data = chunk.toString();
  done(null, new Buffer(data +'-'+ data));
});
 
thrObj = through.factory({objectMode: true});
var streamB = thrObj.buf(function(chunk, enc, done){
  expect(chunk.toString()).to.be.equal('myData-myData');
  done();
});
 
streamA.pipe(streamB);
streamA.write(new Buffer('myData'));
 

through.ctor([options,] [transformFn,] [flushFn]);

Note: This is the same ctor method from through2
If called without arguments, returns a passthrough Transform

var Transform = require('readable-stream').Transform;
var Ctor = through.ctor({objectMode: true}, transformFn, flushFn);
var streamA = new Ctor();
 
// no need for the new operator
var streamB = Ctor(); 
 
//overriding options
var streamC = Ctor({objectMode: false}); 
 
expect(streamA).to.be.an.instanceof(Transform);
expect(streamB).to.be.an.instanceof(Transform);
expect(streamC).to.be.an.instanceof(Transform);
 

through.obj([transfromFn,] [flushFn])

It is a conveniece method for through({objectMode: true}, transformFn, flushFn);
If called without arguments, returns a passthrough Transform

Note: This is the same obj method from through2

var stream = through.obj(function(string, enc, done){
  expect(string).to.be.deep.equal({data: 'myData'});
  done();
});
stream.write({data: 'myData'});

through.buf([transfromFn,] [flushFn])

It is a conveniece method for through({objectMode: false}, transformFn, flushFn);
If called without arguments, returns a passthrough Transform

// see the factory method.
var thr = through.factory({objectMode: true});
var myData = new Buffer('my data');
 
var streamBuf = thr.buf(function(chunk, enc, done){
  expect(chunk).to.be.equal(myData);
  expect(chunk).to.not.be.equal('my data');
  done();
});
streamBuf.write(myData);

through.factory([options]);

A factory method for creating a custom through instance.

var thrObj = through.factory({objectMode: true});
 
var streamObj = thrObj(function(string, enc, done){
  expect(string).to.be.equal('my data');
  done();
});
streamObj.write('my data');
var myData = new Buffer('my data');
var thrBuf = through.factory({objectMode: false, highWaterMark: 1000*Math.pow(2,6)});
 
var streamBuf = thrBuf(function(chunk, enc, done){
  expect(chunk).to.be.equal(myData);
  expect(chunk).to.not.be.equal('my data');
  done();
});
streamBuf.write(myData);

License

The MIT License (MIT)

Copyright (c) 2014 Markuz GJ

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

NPM NPM

Package Sidebar

Install

npm i super-stream.through

Weekly Downloads

4

Version

0.0.3

License

MIT

Last publish

Collaborators

  • markuz-gj