forked from enviPath/enviPy
Current Dev State
This commit is contained in:
21
static/js/ketcher2/node_modules/plexer/LICENCE
generated
vendored
Executable file
21
static/js/ketcher2/node_modules/plexer/LICENCE
generated
vendored
Executable 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.
|
||||
49
static/js/ketcher2/node_modules/plexer/README.md
generated
vendored
Executable file
49
static/js/ketcher2/node_modules/plexer/README.md
generated
vendored
Executable file
@ -0,0 +1,49 @@
|
||||
# Plexer
|
||||
> A stream duplexer embracing Streams 2.0 (for real).
|
||||
|
||||
[](https://npmjs.org/package/plexer) [](https://travis-ci.org/nfroidure/plexer) [](https://david-dm.org/nfroidure/plexer) [](https://david-dm.org/nfroidure/plexer#info=devDependencies) [](https://coveralls.io/r/nfroidure/plexer?branch=master)
|
||||
|
||||
## Usage
|
||||
|
||||
### plexer([options,] writable, readable)
|
||||
|
||||
#### options
|
||||
##### options.reemitErrors
|
||||
Type: `Boolean`
|
||||
Default value: `true`
|
||||
|
||||
Tells the duplexer to reemit given streams errors.
|
||||
|
||||
##### options.objectMode
|
||||
Type: `Boolean`
|
||||
Default value: `false`
|
||||
|
||||
Use if given in streams are in object mode. In this case, the duplexer will
|
||||
also be in the object mode.
|
||||
|
||||
##### options.*
|
||||
|
||||
Plexer inherits of Stream.Duplex, the options are passed to the
|
||||
parent constructor so you can use it's options too.
|
||||
|
||||
#### writable
|
||||
Type: `Stream`
|
||||
|
||||
Required. Any writable stream.
|
||||
|
||||
#### readable
|
||||
Type: `Stream`
|
||||
|
||||
Required. Any readable stream.
|
||||
|
||||
### plexer.obj([options], writable, readable)
|
||||
|
||||
A shortcut for `plexer({objectMode: true})`.
|
||||
|
||||
## Stats
|
||||
|
||||
[](https://nodei.co/npm/plexer/)
|
||||
[](https://nodei.co/npm/plexer/)
|
||||
|
||||
## Contributing
|
||||
Feel free to pull your code if you agree with publishing it under the MIT license.
|
||||
84
static/js/ketcher2/node_modules/plexer/package.json
generated
vendored
Normal file
84
static/js/ketcher2/node_modules/plexer/package.json
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
{
|
||||
"_from": "plexer@^1.0.1",
|
||||
"_id": "plexer@1.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-qAG2Ur+BRXOXlepNO/CvlGwwwN0=",
|
||||
"_location": "/plexer",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "plexer@^1.0.1",
|
||||
"name": "plexer",
|
||||
"escapedName": "plexer",
|
||||
"rawSpec": "^1.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gulp-iconfont",
|
||||
"/gulp-svgicons2svgfont"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/plexer/-/plexer-1.0.1.tgz",
|
||||
"_shasum": "a801b652bf8145739795ea4d3bf0af946c30c0dd",
|
||||
"_spec": "plexer@^1.0.1",
|
||||
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/gulp-iconfont",
|
||||
"author": {
|
||||
"name": "Nicolas Froidure",
|
||||
"url": "http://www.insertafter.com/blog.html"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/nfroidure/plexer/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"isstream": "^0.1.2",
|
||||
"readable-stream": "^2.0.2"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Streams2 duplexer.",
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.4",
|
||||
"eslint": "^1.3.1",
|
||||
"eslint-config-simplifield": "^1.1.0",
|
||||
"istanbul": "^0.3.19",
|
||||
"mocha": "^2.3.1",
|
||||
"mocha-lcov-reporter": "^0.0.2",
|
||||
"streamtest": "^1.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"homepage": "https://github.com/nfroidure/plexer",
|
||||
"keywords": [
|
||||
"duplexer",
|
||||
"streaming",
|
||||
"stream2",
|
||||
"stream",
|
||||
"readable",
|
||||
"writable",
|
||||
"async",
|
||||
"pipe"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/nfroidure/plexer/blob/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "src/index.js",
|
||||
"name": "plexer",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/nfroidure/plexer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"cli": "env NPM_RUN_CLI=1",
|
||||
"cover": "istanbul cover --report html _mocha -- tests/*.mocha.js -R spec -t 5000",
|
||||
"coveralls": "istanbul cover _mocha --report lcovonly -- tests/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
|
||||
"lint": "eslint **/*.js",
|
||||
"prepublish": "npm test && npm run lint",
|
||||
"test": "mocha tests/*.mocha.js"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
||||
124
static/js/ketcher2/node_modules/plexer/src/index.js
generated
vendored
Normal file
124
static/js/ketcher2/node_modules/plexer/src/index.js
generated
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
'use strict';
|
||||
|
||||
var isStream = require('isstream');
|
||||
var Stream = require('readable-stream');
|
||||
var util = require('util');
|
||||
|
||||
// Inherit of Duplex stream
|
||||
util.inherits(Duplexer, Stream.Duplex);
|
||||
|
||||
// Constructor
|
||||
function Duplexer(options, writableStream, readableStream) {
|
||||
var _this = this;
|
||||
|
||||
// Ensure new were used
|
||||
if (!(this instanceof Duplexer)) {
|
||||
return new (Duplexer.bind.apply(Duplexer,
|
||||
[Duplexer].concat([].slice.call(arguments, 0))));
|
||||
}
|
||||
|
||||
// Mapping args
|
||||
if(isStream(options)) {
|
||||
readableStream = writableStream;
|
||||
writableStream = options;
|
||||
options = {};
|
||||
} else {
|
||||
options = options || {};
|
||||
}
|
||||
this._reemitErrors = 'boolean' === typeof options.reemitErrors ?
|
||||
options.reemitErrors :
|
||||
true;
|
||||
delete options.reemitErrors;
|
||||
|
||||
// Checking arguments
|
||||
if(!isStream(writableStream, 'Writable', 'Duplex')) {
|
||||
throw new Error('The writable stream must be an instanceof Writable or Duplex.');
|
||||
}
|
||||
if(!isStream(readableStream, 'Readable')) {
|
||||
throw new Error('The readable stream must be an instanceof Readable.');
|
||||
}
|
||||
|
||||
// Parent constructor
|
||||
Stream.Duplex.call(this, options);
|
||||
|
||||
// Save streams refs
|
||||
this._writable = writableStream;
|
||||
this._readable = readableStream;
|
||||
|
||||
// Internal state
|
||||
this._waitDatas = false;
|
||||
this._hasDatas = false;
|
||||
|
||||
if('undefined' == typeof this._readable._readableState) {
|
||||
this._readable = (new Stream.Readable({
|
||||
objectMode: options.objectMode || false,
|
||||
})).wrap(this._readable);
|
||||
}
|
||||
|
||||
if(this._reemitErrors) {
|
||||
this._writable.on('error', function(err) {
|
||||
_this.emit('error', err);
|
||||
});
|
||||
this._readable.on('error', function(err) {
|
||||
_this.emit('error', err);
|
||||
});
|
||||
}
|
||||
|
||||
this._writable.on('drain', function() {
|
||||
_this.emit('drain');
|
||||
});
|
||||
|
||||
this.once('finish', function() {
|
||||
_this._writable.end();
|
||||
});
|
||||
|
||||
this._writable.once('finish', function() {
|
||||
_this.end();
|
||||
});
|
||||
|
||||
this._readable.on('readable', function() {
|
||||
_this._hasDatas = true;
|
||||
if(_this._waitDatas) {
|
||||
_this._pushAll();
|
||||
}
|
||||
});
|
||||
|
||||
this._readable.once('end', function() {
|
||||
_this.push(null);
|
||||
});
|
||||
}
|
||||
|
||||
Duplexer.prototype._read = function() {
|
||||
this._waitDatas = true;
|
||||
if(this._hasDatas) {
|
||||
this._pushAll();
|
||||
}
|
||||
};
|
||||
|
||||
Duplexer.prototype._pushAll = function() {
|
||||
var _this = this;
|
||||
var chunk;
|
||||
|
||||
do {
|
||||
chunk = _this._readable.read();
|
||||
if(null !== chunk) {
|
||||
this._waitDatas = _this.push(chunk);
|
||||
}
|
||||
this._hasDatas = (null !== chunk);
|
||||
} while(this._waitDatas && this._hasDatas);
|
||||
};
|
||||
|
||||
Duplexer.prototype._write = function(chunk, encoding, callback) {
|
||||
return this._writable.write(chunk, encoding, callback);
|
||||
};
|
||||
|
||||
Duplexer.obj = function plexerObj(options) {
|
||||
var firstArgumentIsAStream = isStream(options);
|
||||
var streams = [].slice.call(arguments, firstArgumentIsAStream ? 0 : 1);
|
||||
|
||||
options = firstArgumentIsAStream ? {} : options;
|
||||
options.objectMode = true;
|
||||
return Duplexer.apply({}.undef, [options].concat(streams));
|
||||
};
|
||||
|
||||
module.exports = Duplexer;
|
||||
699
static/js/ketcher2/node_modules/plexer/tests/index.mocha.js
generated
vendored
Executable file
699
static/js/ketcher2/node_modules/plexer/tests/index.mocha.js
generated
vendored
Executable file
@ -0,0 +1,699 @@
|
||||
/* eslint max-nested-callbacks:[1] */
|
||||
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var Duplexer = require('../src');
|
||||
var Stream = require('readable-stream');
|
||||
var streamtest = require('streamtest');
|
||||
|
||||
describe('Duplexer', function() {
|
||||
|
||||
streamtest.versions.forEach(function(version) {
|
||||
describe('for ' + version + ' streams', function() {
|
||||
|
||||
describe('in binary mode', function() {
|
||||
|
||||
describe('and with async streams', function() {
|
||||
|
||||
it('should work with functionnal API', function(done) {
|
||||
|
||||
var createDuplexStream = Duplexer;
|
||||
var readable = streamtest[version].fromChunks(['biba', 'beloola']);
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = createDuplexStream({}, writable, readable);
|
||||
|
||||
assert(duplex instanceof Duplexer);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
done();
|
||||
}));
|
||||
|
||||
streamtest[version].fromChunks(['oude', 'lali'])
|
||||
.pipe(duplex);
|
||||
|
||||
});
|
||||
|
||||
it('should work with POO API', function(done) {
|
||||
|
||||
var readable = streamtest[version].fromChunks(['biba', 'beloola']);
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = new Duplexer({}, writable, readable);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
done();
|
||||
}));
|
||||
|
||||
streamtest[version].fromChunks(['oude', 'lali'])
|
||||
.pipe(duplex);
|
||||
|
||||
});
|
||||
|
||||
it('should reemit errors', function(done) {
|
||||
var readable = new Stream.PassThrough();
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = new Duplexer(writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
assert.equal(errorsCount, 2);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
setImmediate(function() {
|
||||
// Writing content to duplex
|
||||
duplex.write('oude');
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write('lali');
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write('biba');
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write('beloola');
|
||||
readable.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should not reemit errors when option is set', function(done) {
|
||||
var readable = new Stream.PassThrough();
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = new Duplexer({ reemitErrors: false }, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
assert.equal(errorsCount, 0);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
// Catch error events
|
||||
readable.on('error', function() {});
|
||||
writable.on('error', function() {});
|
||||
|
||||
setImmediate(function() {
|
||||
// Writing content to duplex
|
||||
duplex.write('oude');
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write('lali');
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write('biba');
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write('beloola');
|
||||
readable.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('and with sync streams', function() {
|
||||
|
||||
it('should work with functionnal API', function(done) {
|
||||
var createDuplexStream = Duplexer;
|
||||
var readable = new Stream.PassThrough();
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = createDuplexStream({}, writable, readable);
|
||||
|
||||
assert(duplex instanceof Duplexer);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
done();
|
||||
}));
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write('oude');
|
||||
duplex.write('lali');
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write('biba');
|
||||
readable.write('beloola');
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
it('should work with POO API', function(done) {
|
||||
var readable = new Stream.PassThrough();
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = new Duplexer(writable, readable);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
done();
|
||||
}));
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write('oude');
|
||||
duplex.write('lali');
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write('biba');
|
||||
readable.write('beloola');
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
it('should reemit errors', function(done) {
|
||||
var readable = new Stream.PassThrough();
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = new Duplexer(null, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
assert.equal(errorsCount, 2);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write('oude');
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write('lali');
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write('biba');
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write('beloola');
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
it('should not reemit errors when option is set', function(done) {
|
||||
var readable = new Stream.PassThrough();
|
||||
var writable = new Stream.PassThrough();
|
||||
var duplex = new Duplexer({ reemitErrors: false }, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'oudelali');
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toText(function(err, text) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.equal(text, 'bibabeloola');
|
||||
assert.equal(errorsCount, 0);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
// Catch error events
|
||||
readable.on('error', function() {});
|
||||
writable.on('error', function() {});
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write('oude');
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write('lali');
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write('biba');
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write('beloola');
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('in object mode', function() {
|
||||
var obj1 = { cnt: 'oude' };
|
||||
var obj2 = { cnt: 'lali' };
|
||||
var obj3 = { cnt: 'biba' };
|
||||
var obj4 = { cnt: 'beloola' };
|
||||
|
||||
describe('and with async streams', function() {
|
||||
|
||||
it('should work with functionnal API', function(done) {
|
||||
|
||||
var createDuplexStream = Duplexer;
|
||||
var readable = streamtest[version].fromObjects([obj1, obj2]);
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = createDuplexStream({ objectMode: true }, writable, readable);
|
||||
|
||||
assert(duplex instanceof Duplexer);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
done();
|
||||
}));
|
||||
|
||||
streamtest[version].fromObjects([obj3, obj4])
|
||||
.pipe(duplex);
|
||||
|
||||
});
|
||||
|
||||
it('should work with functionnal API', function(done) {
|
||||
|
||||
var readable = streamtest[version].fromObjects([obj1, obj2]);
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = Duplexer.obj(writable, readable);
|
||||
|
||||
assert(duplex instanceof Duplexer);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
done();
|
||||
}));
|
||||
|
||||
streamtest[version].fromObjects([obj3, obj4])
|
||||
.pipe(duplex);
|
||||
|
||||
});
|
||||
|
||||
it('should work with POO API', function(done) {
|
||||
|
||||
var readable = streamtest[version].fromObjects([obj1, obj2]);
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = new Duplexer({ objectMode: true }, writable, readable);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
done();
|
||||
}));
|
||||
|
||||
streamtest[version].fromObjects([obj3, obj4])
|
||||
.pipe(duplex);
|
||||
|
||||
});
|
||||
|
||||
it('should reemit errors', function(done) {
|
||||
var readable = new Stream.PassThrough({ objectMode: true });
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = new Duplexer({ objectMode: true }, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
assert.equal(errorsCount, 2);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
setImmediate(function() {
|
||||
// Writing content to duplex
|
||||
duplex.write(obj1);
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write(obj2);
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write(obj3);
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write(obj4);
|
||||
readable.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should not reemit errors when option is set', function(done) {
|
||||
var readable = new Stream.PassThrough({ objectMode: true });
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = Duplexer.obj({ reemitErrors: false }, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
assert.equal(errorsCount, 0);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
// Catch error events
|
||||
readable.on('error', function() {});
|
||||
writable.on('error', function() {});
|
||||
|
||||
setImmediate(function() {
|
||||
// Writing content to duplex
|
||||
duplex.write(obj1);
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write(obj2);
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write(obj3);
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write(obj4);
|
||||
readable.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('and with sync streams', function() {
|
||||
|
||||
it('should work with functionnal API', function(done) {
|
||||
var createDuplexStream = Duplexer;
|
||||
var readable = new Stream.PassThrough({ objectMode: true });
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = createDuplexStream({ objectMode: true }, writable, readable);
|
||||
|
||||
assert(duplex instanceof Duplexer);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
done();
|
||||
}));
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write(obj1);
|
||||
duplex.write(obj2);
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write(obj3);
|
||||
readable.write(obj4);
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
it('should work with POO API', function(done) {
|
||||
var readable = new Stream.PassThrough({ objectMode: true });
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = new Duplexer({ objectMode: true }, writable, readable);
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
done();
|
||||
}));
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write(obj1);
|
||||
duplex.write(obj2);
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write(obj3);
|
||||
readable.write(obj4);
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
it('should reemit errors', function(done) {
|
||||
var readable = new Stream.PassThrough({ objectMode: true });
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = new Duplexer({ objectMode: true }, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
assert.equal(errorsCount, 2);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write(obj1);
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write(obj2);
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write(obj3);
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write(obj4);
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
it('should not reemit errors when option is set', function(done) {
|
||||
var readable = new Stream.PassThrough({ objectMode: true });
|
||||
var writable = new Stream.PassThrough({ objectMode: true });
|
||||
var duplex = new Duplexer({
|
||||
objectMode: true,
|
||||
reemitErrors: false,
|
||||
}, writable, readable);
|
||||
var errorsCount = 0;
|
||||
|
||||
// Checking writable content
|
||||
writable.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj1, obj2]);
|
||||
}));
|
||||
|
||||
// Checking duplex output
|
||||
duplex.pipe(streamtest[version].toObjects(function(err, objs) {
|
||||
if(err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.deepEqual(objs, [obj3, obj4]);
|
||||
assert.equal(errorsCount, 0);
|
||||
done();
|
||||
}));
|
||||
|
||||
duplex.on('error', function() {
|
||||
errorsCount++;
|
||||
});
|
||||
|
||||
// Catch error events
|
||||
readable.on('error', function() {});
|
||||
writable.on('error', function() {});
|
||||
|
||||
// Writing content to duplex
|
||||
duplex.write(obj1);
|
||||
writable.emit('error', new Error('hip'));
|
||||
duplex.write(obj2);
|
||||
duplex.end();
|
||||
|
||||
// Writing content to readable
|
||||
readable.write(obj3);
|
||||
readable.emit('error', new Error('hip'));
|
||||
readable.write(obj4);
|
||||
readable.end();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user