clear
This commit is contained in:
1
node_modules/fork-stream/.npmignore
generated
vendored
Normal file
1
node_modules/fork-stream/.npmignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/node_modules
|
||||
3
node_modules/fork-stream/.travis.yml
generated
vendored
Normal file
3
node_modules/fork-stream/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
26
node_modules/fork-stream/LICENSE.md
generated
vendored
Normal file
26
node_modules/fork-stream/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
Copyright (c) 2013, Deoxxa Development
|
||||
======================================
|
||||
All rights reserved.
|
||||
--------------------
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of Deoxxa Development nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY DEOXXA DEVELOPMENT ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL DEOXXA DEVELOPMENT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
135
node_modules/fork-stream/README.md
generated
vendored
Normal file
135
node_modules/fork-stream/README.md
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
fork-stream [](https://travis-ci.org/deoxxa/fork-stream)
|
||||
===========
|
||||
|
||||
Fork a stream in multiple directions according to a function.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
fork-stream basically gives you conditional branching for streams. You supply
|
||||
the logic, fork-stream supplies the streaming.
|
||||
|
||||
Super Quickstart
|
||||
----------------
|
||||
|
||||
Code:
|
||||
|
||||
```javascript
|
||||
var ForkStream = require("fork-stream");
|
||||
|
||||
var fork = new ForkStream({
|
||||
classifier: function classify(e, done) {
|
||||
return done(null, e.match(/[aeiou]/));
|
||||
},
|
||||
});
|
||||
|
||||
fork.a.on("data", console.log.bind(console, "vowels:"));
|
||||
fork.b.on("data", console.log.bind(console, "no vowels:"));
|
||||
|
||||
fork.write("hello");
|
||||
fork.write("zxcbzz");
|
||||
fork.write("ooooooo");
|
||||
|
||||
fork.end();
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```
|
||||
vowels: hello
|
||||
no vowels: zxcbzz
|
||||
vowels: ooooooo
|
||||
```
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Available via [npm](http://npmjs.org/):
|
||||
|
||||
> $ npm install fork-stream
|
||||
|
||||
Or via git:
|
||||
|
||||
> $ git clone git://github.com/deoxxa/fork-stream.git node_modules/fork-stream
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
**constructor**
|
||||
|
||||
Creates a new fork-stream.
|
||||
|
||||
```javascript
|
||||
new ForkStream(options);
|
||||
```
|
||||
|
||||
```javascript
|
||||
var fork = new ForkStream({
|
||||
highWaterMark: 5,
|
||||
classifier: function(e, done) {
|
||||
return done(null, !!e);
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
* _options_ - regular stream options, and a `classifier` property that
|
||||
fork-stream will use to decide what output stream to send your object down.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
Also see [example.js](https://github.com/deoxxa/fork-stream/blob/master/example.js).
|
||||
|
||||
```javascript
|
||||
var ForkStream = require("fork-stream");
|
||||
|
||||
var fork = new ForkStream({
|
||||
classifier: function classify(e, done) {
|
||||
return done(null, e >= 5);
|
||||
},
|
||||
});
|
||||
|
||||
fork.a.on("data", console.log.bind(null, "a"));
|
||||
fork.b.on("data", console.log.bind(null, "b"));
|
||||
|
||||
for (var i=0;i<20;++i) {
|
||||
fork.write(Math.round(Math.random() * 10));
|
||||
}
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```
|
||||
b 1
|
||||
a 6
|
||||
a 9
|
||||
a 10
|
||||
a 7
|
||||
a 5
|
||||
b 2
|
||||
b 4
|
||||
a 8
|
||||
b 3
|
||||
a 5
|
||||
b 4
|
||||
a 7
|
||||
a 8
|
||||
b 1
|
||||
a 6
|
||||
b 2
|
||||
b 0
|
||||
a 5
|
||||
b 1
|
||||
```
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
3-clause BSD. A copy is included with the source.
|
||||
|
||||
Contact
|
||||
-------
|
||||
|
||||
* GitHub ([deoxxa](http://github.com/deoxxa))
|
||||
* Twitter ([@deoxxa](http://twitter.com/deoxxa))
|
||||
* Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))
|
||||
16
node_modules/fork-stream/example.js
generated
vendored
Normal file
16
node_modules/fork-stream/example.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var ForkStream = require("./");
|
||||
|
||||
var fork = new ForkStream({
|
||||
classifier: function classify(e, done) {
|
||||
return done(null, e >= 5);
|
||||
},
|
||||
});
|
||||
|
||||
fork.a.on("data", console.log.bind(null, "a"));
|
||||
fork.b.on("data", console.log.bind(null, "b"));
|
||||
|
||||
for (var i=0;i<20;++i) {
|
||||
fork.write(Math.round(Math.random() * 10));
|
||||
}
|
||||
57
node_modules/fork-stream/index.js
generated
vendored
Normal file
57
node_modules/fork-stream/index.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
var stream = require("stream");
|
||||
|
||||
var ForkStream = module.exports = function ForkStream(options) {
|
||||
options = options || {};
|
||||
|
||||
options.objectMode = true;
|
||||
|
||||
stream.Writable.call(this, options);
|
||||
|
||||
if (options.classifier) {
|
||||
this._classifier = options.classifier;
|
||||
}
|
||||
|
||||
this.a = new stream.Readable(options);
|
||||
this.b = new stream.Readable(options);
|
||||
|
||||
var self = this;
|
||||
|
||||
var resume = function resume() {
|
||||
if (self.resume) {
|
||||
var r = self.resume;
|
||||
self.resume = null;
|
||||
r.call(null);
|
||||
}
|
||||
};
|
||||
|
||||
this.a._read = resume;
|
||||
this.b._read = resume;
|
||||
|
||||
this.on("finish", function() {
|
||||
self.a.push(null);
|
||||
self.b.push(null);
|
||||
});
|
||||
};
|
||||
ForkStream.prototype = Object.create(stream.Writable.prototype, {constructor: {value: ForkStream}});
|
||||
|
||||
ForkStream.prototype._classifier = function(e, done) {
|
||||
return done(null, !!e);
|
||||
};
|
||||
|
||||
ForkStream.prototype._write = function _write(input, encoding, done) {
|
||||
var self = this;
|
||||
|
||||
this._classifier.call(null, input, function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
var out = res ? self.a : self.b;
|
||||
|
||||
if (out.push(input)) {
|
||||
return done();
|
||||
} else {
|
||||
self.resume = done;
|
||||
}
|
||||
});
|
||||
};
|
||||
90
node_modules/fork-stream/package.json
generated
vendored
Normal file
90
node_modules/fork-stream/package.json
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "fork-stream@^0.0.4",
|
||||
"scope": null,
|
||||
"escapedName": "fork-stream",
|
||||
"name": "fork-stream",
|
||||
"rawSpec": "^0.0.4",
|
||||
"spec": ">=0.0.4 <0.0.5",
|
||||
"type": "range"
|
||||
},
|
||||
"D:\\web\\layui\\res\\layui\\node_modules\\ternary-stream"
|
||||
]
|
||||
],
|
||||
"_from": "fork-stream@>=0.0.4 <0.0.5",
|
||||
"_id": "fork-stream@0.0.4",
|
||||
"_inCache": true,
|
||||
"_location": "/fork-stream",
|
||||
"_npmUser": {
|
||||
"name": "deoxxa",
|
||||
"email": "deoxxa@fknsrs.biz"
|
||||
},
|
||||
"_npmVersion": "1.2.32",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "fork-stream@^0.0.4",
|
||||
"scope": null,
|
||||
"escapedName": "fork-stream",
|
||||
"name": "fork-stream",
|
||||
"rawSpec": "^0.0.4",
|
||||
"spec": ">=0.0.4 <0.0.5",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ternary-stream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/fork-stream/-/fork-stream-0.0.4.tgz",
|
||||
"_shasum": "db849fce77f6708a5f8f386ae533a0907b54ae70",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "fork-stream@^0.0.4",
|
||||
"_where": "D:\\web\\layui\\res\\layui\\node_modules\\ternary-stream",
|
||||
"author": {
|
||||
"name": "Conrad Pankoff",
|
||||
"email": "deoxxa@fknsrs.biz",
|
||||
"url": "http://www.fknsrs.biz/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/deoxxa/fork-stream/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Fork a stream in multiple directions according to a function",
|
||||
"devDependencies": {
|
||||
"chai": "~1.7.2",
|
||||
"mocha": "~1.12.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "db849fce77f6708a5f8f386ae533a0907b54ae70",
|
||||
"tarball": "https://registry.npmjs.org/fork-stream/-/fork-stream-0.0.4.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/deoxxa/fork-stream#readme",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"fork",
|
||||
"split",
|
||||
"function",
|
||||
"conditional"
|
||||
],
|
||||
"license": "BSD",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "deoxxa",
|
||||
"email": "deoxxa@fknsrs.biz"
|
||||
}
|
||||
],
|
||||
"name": "fork-stream",
|
||||
"optionalDependencies": {},
|
||||
"readme": "fork-stream [](https://travis-ci.org/deoxxa/fork-stream)\n===========\n\nFork a stream in multiple directions according to a function.\n\nOverview\n--------\n\nfork-stream basically gives you conditional branching for streams. You supply\nthe logic, fork-stream supplies the streaming.\n\nSuper Quickstart\n----------------\n\nCode:\n\n```javascript\nvar ForkStream = require(\"fork-stream\");\n\nvar fork = new ForkStream({\n classifier: function classify(e, done) {\n return done(null, e.match(/[aeiou]/));\n },\n});\n\nfork.a.on(\"data\", console.log.bind(console, \"vowels:\"));\nfork.b.on(\"data\", console.log.bind(console, \"no vowels:\"));\n\nfork.write(\"hello\");\nfork.write(\"zxcbzz\");\nfork.write(\"ooooooo\");\n\nfork.end();\n```\n\nOutput:\n\n```\nvowels: hello\nno vowels: zxcbzz\nvowels: ooooooo\n```\n\nInstallation\n------------\n\nAvailable via [npm](http://npmjs.org/):\n\n> $ npm install fork-stream\n\nOr via git:\n\n> $ git clone git://github.com/deoxxa/fork-stream.git node_modules/fork-stream\n\nAPI\n---\n\n**constructor**\n\nCreates a new fork-stream.\n\n```javascript\nnew ForkStream(options);\n```\n\n```javascript\nvar fork = new ForkStream({\n highWaterMark: 5,\n classifier: function(e, done) {\n return done(null, !!e);\n },\n});\n```\n\n* _options_ - regular stream options, and a `classifier` property that\n fork-stream will use to decide what output stream to send your object down.\n\nExample\n-------\n\nAlso see [example.js](https://github.com/deoxxa/fork-stream/blob/master/example.js).\n\n```javascript\nvar ForkStream = require(\"fork-stream\");\n\nvar fork = new ForkStream({\n classifier: function classify(e, done) {\n return done(null, e >= 5);\n },\n});\n\nfork.a.on(\"data\", console.log.bind(null, \"a\"));\nfork.b.on(\"data\", console.log.bind(null, \"b\"));\n\nfor (var i=0;i<20;++i) {\n fork.write(Math.round(Math.random() * 10));\n}\n```\n\nOutput:\n\n```\nb 1\na 6\na 9\na 10\na 7\na 5\nb 2\nb 4\na 8\nb 3\na 5\nb 4\na 7\na 8\nb 1\na 6\nb 2\nb 0\na 5\nb 1\n```\n\nLicense\n-------\n\n3-clause BSD. A copy is included with the source.\n\nContact\n-------\n\n* GitHub ([deoxxa](http://github.com/deoxxa))\n* Twitter ([@deoxxa](http://twitter.com/deoxxa))\n* Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))\n",
|
||||
"readmeFilename": "README.md",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/deoxxa/fork-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R tap"
|
||||
},
|
||||
"version": "0.0.4"
|
||||
}
|
||||
94
node_modules/fork-stream/test/tests.js
generated
vendored
Normal file
94
node_modules/fork-stream/test/tests.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
var assert = require("chai").assert;
|
||||
|
||||
var ForkStream = require("../");
|
||||
|
||||
describe("fork-stream", function() {
|
||||
it("should split objects into their correct streams", function(done) {
|
||||
var fork = new ForkStream({
|
||||
classifier: function classify(e, done) {
|
||||
return done(null, e >= 5);
|
||||
},
|
||||
});
|
||||
|
||||
var expectedA = [5, 7, 9],
|
||||
expectedB = [1, 4, 3, 1];
|
||||
|
||||
var actualA = [],
|
||||
actualB = [];
|
||||
|
||||
fork.a.on("data", function(e) {
|
||||
actualA.push(e);
|
||||
});
|
||||
|
||||
fork.b.on("data", function(e) {
|
||||
actualB.push(e);
|
||||
});
|
||||
|
||||
fork.on("finish", function() {
|
||||
assert.deepEqual(expectedA, actualA);
|
||||
assert.deepEqual(expectedB, actualB);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
[1, 5, 7, 4, 9, 3, 1].forEach(function(n) {
|
||||
fork.write(n);
|
||||
});
|
||||
|
||||
fork.end();
|
||||
});
|
||||
|
||||
it("should respect backpressure", function(done) {
|
||||
var fork = new ForkStream({
|
||||
highWaterMark: 2,
|
||||
classifier: function classify(e, done) {
|
||||
return done(null, e >= 5);
|
||||
},
|
||||
});
|
||||
|
||||
var expected = [5, 7],
|
||||
actual = [];
|
||||
|
||||
fork.a.on("data", function(e) {
|
||||
actual.push(e);
|
||||
});
|
||||
|
||||
var timeout = setTimeout(function() {
|
||||
assert.deepEqual(expected, actual);
|
||||
|
||||
return done();
|
||||
}, 10);
|
||||
|
||||
fork.on("finish", function() {
|
||||
clearTimeout(timeout);
|
||||
|
||||
return done(Error("should not finish"));
|
||||
});
|
||||
|
||||
[1, 5, 7, 4, 9, 3, 1].forEach(function(n) {
|
||||
fork.write(n);
|
||||
});
|
||||
|
||||
fork.end();
|
||||
});
|
||||
|
||||
it("should end the outputs when the input finishes", function(done) {
|
||||
var fork = new ForkStream();
|
||||
|
||||
var count = 0;
|
||||
var onEnd = function onEnd() {
|
||||
if (++count === 2) {
|
||||
return done();
|
||||
}
|
||||
};
|
||||
|
||||
fork.a.on("end", onEnd)
|
||||
fork.b.on("end", onEnd);
|
||||
|
||||
// start "flowing" mode
|
||||
fork.a.resume();
|
||||
fork.b.resume();
|
||||
|
||||
fork.end();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user