Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-via

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-via - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

.travis.yml

58

lib/stream-via.js
"use strict";
var Transform = require("stream").Transform;
var util = require("util");
/**
Process each chunk of a stream via the supplied function.
@module stream-via
*/
module.exports = via;
via.async = viaAsync;
function SimpleTransform(options){
if (!(this instanceof SimpleTransform)) return new SimpleTransform(options);
Transform.call(this, options);
this.buf = new Buffer(0);
}
util.inherits(SimpleTransform, Transform);
/**
@param {function}
@param [options] {object} - passed to Transform constructor
@return {external:Duplex}
@alias module:stream-via
*/
function via(transformFunction, options){
var stream = SimpleTransform(options);
stream._transform = function(chunk, enc, done){
if (chunk){
try {
this.push(transformFunction(chunk, enc));
} catch(err){
stream.emit("error", err);
}
}
done();
};
return stream;
}
function viaAsync(transformFunction, options){
var stream = SimpleTransform(options);
stream._transform = function(chunk, enc, done){
if (chunk){
try {
this.push(transformFunction(chunk, enc, done));
} catch(err){
stream.emit("error", err);
done();
}
}
};
return stream;
}
/**
@external Duplex
@see https://nodejs.org/api/stream.html#stream_class_stream_duplex
*/

19

package.json
{
"name": "stream-via",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "0.0.0",
"version": "0.1.0",
"description": "stream-via",

@@ -9,6 +9,9 @@ "repository": "https://github.com/75lb/stream-via.git",

"main": "./lib/stream-via.js",
"bin": {
"stream-via": "bin/cli.js"
},
"keywords": [],
"keywords": [
"through",
"stream",
"process",
"chunk",
"transform"
],
"engines": {

@@ -19,5 +22,9 @@ "node": ">=0.10.0"

"test": "tape test/*.js",
"lint": "jshint lib/*.js bin/*.js test/*.js; echo",
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo"
},
"devDependencies": {
"buffer-equal": "0.0.1",
"jsdoc-to-markdown": "^1.1.1",
"tape": "^4.0.0"
}
}

@@ -5,4 +5,19 @@ [![view on npm](http://img.shields.io/npm/v/stream-via.svg)](https://www.npmjs.org/package/stream-via)

[![Dependency Status](https://david-dm.org/75lb/stream-via.svg)](https://david-dm.org/75lb/stream-via)
![Analytics](https://ga-beacon.appspot.com/UA-27725889-6/stream-via/README.md?pixel)
#stream-via
<a name="module_stream-via"></a>
## stream-via
Process each chunk of a stream via the supplied function.
<a name="exp_module_stream-via--via"></a>
### via(transformFunction, [options]) ⇒ <code>[Duplex](https://nodejs.org/api/stream.html#stream_class_stream_duplex)</code> ⏏
**Kind**: Exported function
| Param | Type | Description |
| --- | --- | --- |
| transformFunction | <code>function</code> | |
| [options] | <code>object</code> | passed to Transform constructor |
* * *
&copy; 2015 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
var test = require("tape");
var lib = require("../");
var via = require("../");
var PassThrough = require("stream").PassThrough;
var bufferEquals = require("buffer-equal");
test("first", function(t){
test("via(func) - utf8", function(t){
var stream = via(function(data){
return data + "yeah?";
});
stream.on("readable", function(){
var chunk = this.read();
if (chunk){
t.strictEqual(chunk, "cliveyeah?");
t.end();
}
});
stream.setEncoding("utf8");
stream.end("clive");
});
test("via(func) - buffer", function(t){
var stream = via(function(data){
return Buffer.concat([ data, Buffer([ 2 ])]);
});
stream.on("readable", function(){
var chunk = this.read();
if (chunk){
t.ok(bufferEquals(chunk, Buffer([ 1, 2 ])));
t.end();
}
});
stream.end(Buffer([ 1 ]));
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc