clear
This commit is contained in:
6
node_modules/bufferstreams/.npmignore
generated
vendored
Normal file
6
node_modules/bufferstreams/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
*~
|
||||
*.swp
|
||||
node_modules/
|
||||
.git
|
||||
tests/results
|
||||
.coveralls.yml
|
||||
9
node_modules/bufferstreams/.travis.yml
generated
vendored
Normal file
9
node_modules/bufferstreams/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.10
|
||||
|
||||
before_script:
|
||||
- npm install --dev
|
||||
|
||||
script:
|
||||
- npm test
|
||||
21
node_modules/bufferstreams/LICENCE
generated
vendored
Normal file
21
node_modules/bufferstreams/LICENCE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2013 Nicolas Froidure, <http://insertafter.com/>
|
||||
|
||||
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.
|
||||
50
node_modules/bufferstreams/README.md
generated
vendored
Normal file
50
node_modules/bufferstreams/README.md
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# BufferStreams
|
||||
|
||||
[](https://npmjs.org/package/bufferstreams) [](https://travis-ci.org/nfroidure/BufferStreams) [](https://david-dm.org/nfroidure/bufferstreams) [](https://david-dm.org/nfroidure/bufferstreams#info=devDependencies) [](https://coveralls.io/r/nfroidure/BufferStreams?branch=master) [](https://codeclimate.com/github/nfroidure/BufferStreams)
|
||||
|
||||
BufferStreams abstracts streams to allow you to deal with their whole content in
|
||||
a single buffer when it becomes necessary (by example: a legacy library that
|
||||
do not support streams).
|
||||
|
||||
It is not a good practice, just some glue. Using BufferStreams means:
|
||||
* there is no library dealing with streams for your needs
|
||||
* you filled an issue to the wrapped library to support streams
|
||||
|
||||
## Usage
|
||||
Install the [npm module](https://npmjs.org/package/bufferstreams):
|
||||
```sh
|
||||
npm install bufferstreams --save
|
||||
```
|
||||
Then, in your scripts:
|
||||
```js
|
||||
var BufferStreams = require('bufferstreams');
|
||||
|
||||
Fs.createReadStream('input.txt')
|
||||
.pipe(new BufferStreams(function(err, buf, cb) {
|
||||
|
||||
// err will be filled with an error if the piped in stream emits one.
|
||||
if(err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
// buf will contain the whole piped in stream contents
|
||||
buf = Buffer(buf.toString('utf-8').replace('foo', 'bar'));
|
||||
|
||||
// cb is a callback to pass the result back to the piped out stream
|
||||
// first argument is an error that will be emitted if any
|
||||
// the second argument is the modified buffer
|
||||
cb(null, buf);
|
||||
|
||||
}))
|
||||
.pipe(Fs.createWriteStream('output.txt'));
|
||||
```
|
||||
|
||||
Note that you can use BufferStream with the objectMode option. In this case, the
|
||||
given buffer will be an array containing the streamed objects:
|
||||
```js
|
||||
new BufferStreams({objectMode: true}, myCallback);
|
||||
```
|
||||
|
||||
## Contributing
|
||||
Feel free to pull your code if you agree with publishing it under the MIT license.
|
||||
|
||||
106
node_modules/bufferstreams/package.json
generated
vendored
Normal file
106
node_modules/bufferstreams/package.json
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "bufferstreams@1.0.1",
|
||||
"scope": null,
|
||||
"escapedName": "bufferstreams",
|
||||
"name": "bufferstreams",
|
||||
"rawSpec": "1.0.1",
|
||||
"spec": "1.0.1",
|
||||
"type": "version"
|
||||
},
|
||||
"D:\\web\\layui\\res\\layui\\node_modules\\vinyl-bufferstream"
|
||||
]
|
||||
],
|
||||
"_from": "bufferstreams@1.0.1",
|
||||
"_id": "bufferstreams@1.0.1",
|
||||
"_inCache": true,
|
||||
"_location": "/bufferstreams",
|
||||
"_nodeVersion": "0.12.0",
|
||||
"_npmUser": {
|
||||
"name": "nfroidure",
|
||||
"email": "nfroidure@elitwork.com"
|
||||
},
|
||||
"_npmVersion": "2.5.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "bufferstreams@1.0.1",
|
||||
"scope": null,
|
||||
"escapedName": "bufferstreams",
|
||||
"name": "bufferstreams",
|
||||
"rawSpec": "1.0.1",
|
||||
"spec": "1.0.1",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vinyl-bufferstream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/bufferstreams/-/bufferstreams-1.0.1.tgz",
|
||||
"_shasum": "cfb1ad9568d3ba3cfe935ba9abdd952de88aab2a",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "bufferstreams@1.0.1",
|
||||
"_where": "D:\\web\\layui\\res\\layui\\node_modules\\vinyl-bufferstream",
|
||||
"author": {
|
||||
"name": "Nicolas Froidure",
|
||||
"url": "http://www.insertafter.com/blog.html"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/nfroidure/BufferStreams/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"readable-stream": "^1.0.33"
|
||||
},
|
||||
"description": "Abstract streams to deal with the whole buffered contents.",
|
||||
"devDependencies": {
|
||||
"coveralls": "~2.11.2",
|
||||
"istanbul": "~0.3.5",
|
||||
"mocha": "2.x.x",
|
||||
"mocha-lcov-reporter": "0.0.1",
|
||||
"streamtest": "^1.1.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "cfb1ad9568d3ba3cfe935ba9abdd952de88aab2a",
|
||||
"tarball": "https://registry.npmjs.org/bufferstreams/-/bufferstreams-1.0.1.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"gitHead": "7d4c975accd17ea382845d93e11761ad8c364534",
|
||||
"homepage": "https://github.com/nfroidure/BufferStreams",
|
||||
"keywords": [
|
||||
"buffer",
|
||||
"streaming",
|
||||
"stream",
|
||||
"async",
|
||||
"abstract"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/nfroidure/BufferStreams/blob/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "src/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "nfroidure",
|
||||
"email": "nfroidure@elitwork.com"
|
||||
}
|
||||
],
|
||||
"name": "bufferstreams",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/nfroidure/BufferStreams.git"
|
||||
},
|
||||
"scripts": {
|
||||
"cover": "./node_modules/istanbul/lib/cli.js cover --report html ./node_modules/mocha/bin/_mocha -- tests/*.mocha.js -R spec -t 5000",
|
||||
"coveralls": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- tests/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
|
||||
"test": "./node_modules/mocha/bin/mocha tests/*.mocha.js",
|
||||
"trinity": "npm-check-updates -u && npm test && git commit package.json -m \"Dependencies update\" && git push"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
||||
65
node_modules/bufferstreams/src/index.js
generated
vendored
Normal file
65
node_modules/bufferstreams/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
var PassThrough = require('readable-stream').PassThrough;
|
||||
var util = require('util');
|
||||
|
||||
// Inherit of PassThrough stream
|
||||
util.inherits(BufferStream, PassThrough);
|
||||
|
||||
// Constructor
|
||||
function BufferStream(options, cb) {
|
||||
// Ensure new were used
|
||||
if (!(this instanceof BufferStream)) {
|
||||
return new BufferStream(options, cb);
|
||||
}
|
||||
|
||||
// Cast args
|
||||
if(options instanceof Function) {
|
||||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
options = options || {};
|
||||
if(!(cb instanceof Function)) {
|
||||
throw new Error('The given callback must be a function.');
|
||||
}
|
||||
this.__objectMode = options.objectMode;
|
||||
|
||||
// Parent constructor
|
||||
PassThrough.call(this, options);
|
||||
|
||||
// Keep a reference to the callback
|
||||
this._cb = cb;
|
||||
|
||||
// Internal buffer
|
||||
this._buf = options.objectMode ? [] : Buffer('');
|
||||
}
|
||||
|
||||
BufferStream.prototype._transform = function(chunk, encoding, done) {
|
||||
|
||||
if(this.__objectMode) {
|
||||
this._buf.push(chunk);
|
||||
} else {
|
||||
this._buf = Buffer.concat([this._buf, chunk], this._buf.length + chunk.length);
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
};
|
||||
|
||||
BufferStream.prototype._flush = function(done) {
|
||||
var _this = this;
|
||||
|
||||
this._cb(null, this._buf, function(err, buf) {
|
||||
if(buf && buf.length) {
|
||||
if(_this.__objectMode) {
|
||||
buf.forEach(function(chunk) {
|
||||
_this.push(chunk);
|
||||
});
|
||||
} else {
|
||||
_this.push(buf);
|
||||
}
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
module.exports = BufferStream;
|
||||
263
node_modules/bufferstreams/tests/index.mocha.js
generated
vendored
Normal file
263
node_modules/bufferstreams/tests/index.mocha.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
var assert = require('assert')
|
||||
, StreamTest = require('streamtest')
|
||||
, BufferStream = require('../src')
|
||||
;
|
||||
|
||||
// Helpers
|
||||
function syncBufferPrefixer(headerText) {
|
||||
return new BufferStream({
|
||||
objectMode: headerText instanceof Object
|
||||
}, function(err, buf, cb) {
|
||||
assert.equal(err, null);
|
||||
if(null === buf) {
|
||||
cb(null, Buffer(headerText));
|
||||
} else if(buf instanceof Array) {
|
||||
buf.unshift(headerText);
|
||||
cb(null, buf);
|
||||
} else {
|
||||
cb(null, Buffer.concat([Buffer(headerText), buf]));
|
||||
}
|
||||
});
|
||||
}
|
||||
function asyncBufferPrefixer(headerText) {
|
||||
return new BufferStream({
|
||||
objectMode: headerText instanceof Object
|
||||
}, function(err, buf, cb) {
|
||||
assert.equal(err, null);
|
||||
if(null === buf) {
|
||||
setTimeout(function() {
|
||||
cb(null, Buffer(headerText));
|
||||
}, 0);
|
||||
} else if(buf instanceof Array) {
|
||||
setTimeout(function() {
|
||||
buff.push(headerText);
|
||||
cb(null, buf);
|
||||
}, 0);
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
cb(null, Buffer.concat([Buffer(headerText), buf]));
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Tests
|
||||
describe('bufferstreams', function() {
|
||||
|
||||
it('should fail when callback is not a function', function() {
|
||||
assert.throws(function() {
|
||||
new BufferStream();
|
||||
});
|
||||
});
|
||||
|
||||
// Iterating through versions
|
||||
StreamTest.versions.forEach(function(version) {
|
||||
|
||||
describe('for ' + version + ' streams', function() {
|
||||
|
||||
describe('in buffer mode', function() {
|
||||
|
||||
describe('synchonously', function() {
|
||||
|
||||
it('should work with one pipe', function(done) {
|
||||
StreamTest[version].fromChunks(['te', 'st'])
|
||||
.pipe(syncBufferPrefixer('plop'))
|
||||
.pipe(StreamTest[version].toText(function(err, data) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(data, 'ploptest');
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work when returning a null buffer', function(done) {
|
||||
|
||||
StreamTest[version].fromChunks(['te', 'st'])
|
||||
.pipe(new BufferStream(function(err, buf, cb){
|
||||
cb(null, null);
|
||||
}))
|
||||
.pipe(StreamTest[version].toText(function(err, data) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(data, '');
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work with multiple pipes', function(done) {
|
||||
StreamTest[version].fromChunks(['te', 'st'])
|
||||
.pipe(syncBufferPrefixer('plop'))
|
||||
.pipe(syncBufferPrefixer('plip'))
|
||||
.pipe(syncBufferPrefixer('plap'))
|
||||
.pipe(StreamTest[version].toText(function(err, data) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(data, 'plapplipploptest');
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('asynchonously', function() {
|
||||
|
||||
it('should work with one pipe', function(done) {
|
||||
StreamTest[version].fromChunks(['te', 'st'])
|
||||
.pipe(asyncBufferPrefixer('plop'))
|
||||
.pipe(StreamTest[version].toText(function(err, data) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(data, 'ploptest');
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work when returning a null buffer', function(done) {
|
||||
|
||||
StreamTest[version].fromChunks(['te', 'st'])
|
||||
.pipe(BufferStream(function(err, buf, cb){
|
||||
cb(null, null);
|
||||
}))
|
||||
.pipe(StreamTest[version].toText(function(err, data) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(data, '');
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work with multiple pipes', function(done) {
|
||||
StreamTest[version].fromChunks(['te', 'st'])
|
||||
.pipe(asyncBufferPrefixer('plop'))
|
||||
.pipe(asyncBufferPrefixer('plip'))
|
||||
|
||||
.pipe(asyncBufferPrefixer('plap'))
|
||||
.pipe(StreamTest[version].toText(function(err, data) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(data, 'plapplipploptest');
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('in object mode', function() {
|
||||
var object1 = {txt: 'te'};
|
||||
var object2 = {txt: 'st'};
|
||||
var object3 = {txt: 'e'};
|
||||
var object4 = {txt: 'd'};
|
||||
var object5 = {txt: 'u'};
|
||||
var object6 = {txt: 'ni'};
|
||||
var object7 = {txt: 't'};
|
||||
|
||||
describe('synchonously', function() {
|
||||
|
||||
it('should work with one pipe', function(done) {
|
||||
StreamTest[version].fromObjects([object1, object2])
|
||||
.pipe(syncBufferPrefixer(object4))
|
||||
.pipe(StreamTest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [object4, object1, object2]);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work when returning a null buffer', function(done) {
|
||||
|
||||
StreamTest[version].fromObjects([object1, object2])
|
||||
.pipe(new BufferStream({
|
||||
objectMode: true
|
||||
}, function(err, buf, cb){
|
||||
cb(null, null);
|
||||
}))
|
||||
.pipe(StreamTest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(objs.length, 0);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work with multiple pipes', function(done) {
|
||||
StreamTest[version].fromObjects([object1, object2])
|
||||
.pipe(syncBufferPrefixer(object4))
|
||||
.pipe(syncBufferPrefixer(object5))
|
||||
.pipe(syncBufferPrefixer(object6))
|
||||
.pipe(StreamTest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [object6, object5, object4, object1, object2]);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('asynchonously', function() {
|
||||
|
||||
it('should work with one pipe', function(done) {
|
||||
StreamTest[version].fromObjects([object1, object2])
|
||||
.pipe(syncBufferPrefixer(object4))
|
||||
.pipe(StreamTest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [object4, object1, object2]);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work when returning a null buffer', function(done) {
|
||||
StreamTest[version].fromObjects([object1, object2])
|
||||
.pipe(BufferStream({
|
||||
objectMode: true
|
||||
}, function(err, buf, cb){
|
||||
cb(null, null);
|
||||
}))
|
||||
.pipe(StreamTest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(objs.length, 0);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work with multiple pipes', function(done) {
|
||||
StreamTest[version].fromObjects([object1, object2])
|
||||
.pipe(syncBufferPrefixer(object4))
|
||||
.pipe(syncBufferPrefixer(object5))
|
||||
.pipe(syncBufferPrefixer(object6))
|
||||
.pipe(StreamTest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [object6, object5, object4, object1, object2]);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user