Import Upstream version 1.0.0+~0.1.1
This commit is contained in:
parent
9b5c3281ed
commit
d281d0bc05
|
@ -0,0 +1,12 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
|
@ -1 +1,2 @@
|
|||
/node_modules
|
||||
node_modules
|
||||
yarn.lock
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4"
|
||||
- "5"
|
26
LICENSE.md
26
LICENSE.md
|
@ -1,26 +0,0 @@
|
|||
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.
|
115
README.md
115
README.md
|
@ -1,115 +0,0 @@
|
|||
# duplexer3 [![Build Status](https://travis-ci.org/floatdrop/duplexer3.svg?branch=master)](https://travis-ci.org/floatdrop/duplexer3) [![Coverage Status](https://coveralls.io/repos/floatdrop/duplexer3/badge.svg?branch=master&service=github)](https://coveralls.io/github/floatdrop/duplexer3?branch=master)
|
||||
|
||||
Like [duplexer2](https://github.com/deoxxa/duplexer2) but using Streams3 without readable-stream dependency
|
||||
|
||||
```javascript
|
||||
var stream = require("stream");
|
||||
|
||||
var duplexer3 = require("duplexer3");
|
||||
|
||||
var writable = new stream.Writable({objectMode: true}),
|
||||
readable = new stream.Readable({objectMode: true});
|
||||
|
||||
writable._write = function _write(input, encoding, done) {
|
||||
if (readable.push(input)) {
|
||||
return done();
|
||||
} else {
|
||||
readable.once("drain", done);
|
||||
}
|
||||
};
|
||||
|
||||
readable._read = function _read(n) {
|
||||
// no-op
|
||||
};
|
||||
|
||||
// simulate the readable thing closing after a bit
|
||||
writable.once("finish", function() {
|
||||
setTimeout(function() {
|
||||
readable.push(null);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
duplex.on("data", function(e) {
|
||||
console.log("got data", JSON.stringify(e));
|
||||
});
|
||||
|
||||
duplex.on("finish", function() {
|
||||
console.log("got finish event");
|
||||
});
|
||||
|
||||
duplex.on("end", function() {
|
||||
console.log("got end event");
|
||||
});
|
||||
|
||||
duplex.write("oh, hi there", function() {
|
||||
console.log("finished writing");
|
||||
});
|
||||
|
||||
duplex.end(function() {
|
||||
console.log("finished ending");
|
||||
});
|
||||
```
|
||||
|
||||
```
|
||||
got data "oh, hi there"
|
||||
finished writing
|
||||
got finish event
|
||||
finished ending
|
||||
got end event
|
||||
```
|
||||
|
||||
## Overview
|
||||
|
||||
This is a reimplementation of [duplexer](https://www.npmjs.com/package/duplexer) using the
|
||||
Streams3 API which is standard in Node as of v4. Everything largely
|
||||
works the same.
|
||||
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
[Available via `npm`](https://docs.npmjs.com/cli/install):
|
||||
|
||||
```
|
||||
$ npm i duplexer3
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### duplexer3
|
||||
|
||||
Creates a new `DuplexWrapper` object, which is the actual class that implements
|
||||
most of the fun stuff. All that fun stuff is hidden. DON'T LOOK.
|
||||
|
||||
```javascript
|
||||
duplexer3([options], writable, readable)
|
||||
```
|
||||
|
||||
```javascript
|
||||
const duplex = duplexer3(new stream.Writable(), new stream.Readable());
|
||||
```
|
||||
|
||||
Arguments
|
||||
|
||||
* __options__ - an object specifying the regular `stream.Duplex` options, as
|
||||
well as the properties described below.
|
||||
* __writable__ - a writable stream
|
||||
* __readable__ - a readable stream
|
||||
|
||||
Options
|
||||
|
||||
* __bubbleErrors__ - a boolean value that specifies whether to bubble errors
|
||||
from the underlying readable/writable streams. Default is `true`.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
3-clause BSD. [A copy](./LICENSE) 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))
|
|
@ -1,5 +0,0 @@
|
|||
node-duplexer3 (0.1.4-ok1) yangtze; urgency=medium
|
||||
|
||||
* Build for openKylin.
|
||||
|
||||
-- zhouganqing <zhouganqing@kylinos.cn> Mon, 20 Feb 2023 16:09:22 +0800
|
|
@ -1,29 +0,0 @@
|
|||
Source: node-duplexer3
|
||||
Maintainer: OpenKylin Developers <packaging@lists.openkylin.top>
|
||||
Section: javascript
|
||||
Testsuite: autopkgtest-pkg-nodejs
|
||||
Priority: optional
|
||||
Build-Depends: debhelper-compat (= 13),
|
||||
node-tap <!nocheck>,
|
||||
mocha <!nocheck>,
|
||||
dh-sequence-nodejs
|
||||
Standards-Version: 4.6.0
|
||||
Vcs-Browser: https://gitee.com/openkylin/node-duplexer3
|
||||
Vcs-Git: https://gitee.com/openkylin/node-duplexer3.git
|
||||
Homepage: https://github.com/floatdrop/duplexer3
|
||||
Rules-Requires-Root: no
|
||||
|
||||
Package: node-duplexer3
|
||||
Architecture: all
|
||||
Depends: ${misc:Depends}
|
||||
Provides: node-duplexer2 (= ${source:Version})
|
||||
Replaces: node-duplexer2
|
||||
Breaks: node-duplexer2 (<< 0.1.4-2)
|
||||
Multi-Arch: foreign
|
||||
Description: Like duplexer but using streams3
|
||||
This is a reimplementation of duplexer using the Streams3 API
|
||||
which is standard in Node as of v4. Everything largely works the same
|
||||
Duplexer takes a writable stream and a readable stream and makes them
|
||||
appear as a readable writable stream.
|
||||
.
|
||||
Node.js is an event-based server-side JavaScript engine.
|
|
@ -1,37 +0,0 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: duplexer3
|
||||
Upstream-Contact: https://github.com/floatdrop/duplexer3/issues
|
||||
Source: https://github.com/floatdrop/duplexer3
|
||||
|
||||
Files: *
|
||||
Copyright: 2017 Conrad Pankoff <deoxxa@fknsrs.biz> (https://www.fknsrs.biz/)
|
||||
License: BSD-3-clause
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2017 Tushar Agey <agey.tushar3@gmail.com>
|
||||
License: BSD-3-clause
|
||||
|
||||
License: BSD-3-clause
|
||||
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 the University 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``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 THE HOLDERS OR
|
||||
CONTRIBUTORS 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.
|
|
@ -1 +0,0 @@
|
|||
README.md
|
|
@ -1 +0,0 @@
|
|||
package.json usr/share/nodejs/duplexer2/
|
|
@ -1 +0,0 @@
|
|||
symlink_to_dir /usr/lib/nodejs/duplexer2 0.1.4-5~
|
|
@ -1 +0,0 @@
|
|||
duplexer3/index.js duplexer2/index.js
|
|
@ -1,24 +0,0 @@
|
|||
Description: Fix bad test
|
||||
For an unknown reason, this test fails
|
||||
Author: Xavier Guimard <yadd@debian.org>
|
||||
Bug: https://github.com/floatdrop/duplexer3/issues/2
|
||||
Bug-Debian: https://bugs.debian.org/918670
|
||||
Forwarded: https://github.com/floatdrop/duplexer3/issues/2
|
||||
Last-Update: 2019-01-09
|
||||
|
||||
--- a/test/tests.js
|
||||
+++ b/test/tests.js
|
||||
@@ -164,6 +164,7 @@
|
||||
assert.equal(typeof duplexer3.DuplexWrapper, "function");
|
||||
});
|
||||
|
||||
+ /*
|
||||
it("should not force flowing-mode", function(done) {
|
||||
var writable = new stream.PassThrough();
|
||||
var readable = new stream.PassThrough();
|
||||
@@ -201,4 +202,5 @@
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
});
|
||||
});
|
||||
+ */
|
||||
});
|
|
@ -1 +0,0 @@
|
|||
fix-bad-test.patch
|
|
@ -1,12 +0,0 @@
|
|||
#!/usr/bin/make -f
|
||||
# -*- makefile -*-
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
||||
override_dh_install:
|
||||
dh_install
|
||||
perl -i -pe 's/duplexer3/duplexer2/' debian/node-duplexer3/usr/share/nodejs/duplexer2/package.json
|
|
@ -1 +0,0 @@
|
|||
3.0 (native)
|
|
@ -1,6 +0,0 @@
|
|||
set -e
|
||||
set -x
|
||||
if test "$AUTOPKGTEST_TMP" != ""; then
|
||||
node -e 'require("duplexer2")'
|
||||
fi
|
||||
mocha
|
|
@ -1,5 +0,0 @@
|
|||
version=4
|
||||
opts=\
|
||||
dversionmangle=auto,\
|
||||
filenamemangle=s%(?:.*?/)?v?(@ANY_VERSION@@ARCHIVE_EXT@)%@PACKAGE@-$1% \
|
||||
https://github.com/floatdrop/duplexer3/tags (?:.*?/)?v?@ANY_VERSION@@ARCHIVE_EXT@
|
56
example.js
56
example.js
|
@ -1,49 +1,47 @@
|
|||
#!/usr/bin/env node
|
||||
import stream from 'node:stream';
|
||||
import duplexer from './index.js';
|
||||
|
||||
var stream = require("stream");
|
||||
const writable = new stream.Writable({objectMode: true});
|
||||
const readable = new stream.Readable({objectMode: true});
|
||||
|
||||
var duplexer3 = require("./");
|
||||
writable._write = function (input, encoding, done) {
|
||||
if (readable.push(input)) {
|
||||
return done();
|
||||
}
|
||||
|
||||
var writable = new stream.Writable({objectMode: true}),
|
||||
readable = new stream.Readable({objectMode: true});
|
||||
|
||||
writable._write = function _write(input, encoding, done) {
|
||||
if (readable.push(input)) {
|
||||
return done();
|
||||
} else {
|
||||
readable.once("drain", done);
|
||||
}
|
||||
readable.once('drain', done);
|
||||
};
|
||||
|
||||
readable._read = function _read(n) {
|
||||
// no-op
|
||||
readable._read = function () {
|
||||
// Noop
|
||||
};
|
||||
|
||||
// simulate the readable thing closing after a bit
|
||||
writable.once("finish", function() {
|
||||
setTimeout(function() {
|
||||
readable.push(null);
|
||||
}, 500);
|
||||
// Simulate the readable thing closing after a bit
|
||||
writable.once('finish', () => {
|
||||
setTimeout(() => {
|
||||
readable.push(null);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
var duplex = duplexer3(writable, readable);
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
duplex.on("data", function(e) {
|
||||
console.log("got data", JSON.stringify(e));
|
||||
duplex.on('data', data => {
|
||||
console.log('got data', JSON.stringify(data));
|
||||
});
|
||||
|
||||
duplex.on("finish", function() {
|
||||
console.log("got finish event");
|
||||
duplex.on('finish', () => {
|
||||
console.log('got finish event');
|
||||
});
|
||||
|
||||
duplex.on("end", function() {
|
||||
console.log("got end event");
|
||||
duplex.on('end', () => {
|
||||
console.log('got end event');
|
||||
});
|
||||
|
||||
duplex.write("oh, hi there", function() {
|
||||
console.log("finished writing");
|
||||
duplex.write('oh, hi there', () => {
|
||||
console.log('finished writing');
|
||||
});
|
||||
|
||||
duplex.end(function() {
|
||||
console.log("finished ending");
|
||||
duplex.end(() => {
|
||||
console.log('finished ending');
|
||||
});
|
||||
|
|
111
index.js
111
index.js
|
@ -1,76 +1,71 @@
|
|||
"use strict";
|
||||
import stream from 'node:stream';
|
||||
|
||||
var stream = require("stream");
|
||||
export function DuplexWrapper(options, writable, readable) {
|
||||
if (typeof readable === 'undefined') {
|
||||
readable = writable;
|
||||
writable = options;
|
||||
options = undefined;
|
||||
}
|
||||
|
||||
function DuplexWrapper(options, writable, readable) {
|
||||
if (typeof readable === "undefined") {
|
||||
readable = writable;
|
||||
writable = options;
|
||||
options = null;
|
||||
}
|
||||
stream.Duplex.call(this, options);
|
||||
|
||||
stream.Duplex.call(this, options);
|
||||
if (typeof readable.read !== 'function') {
|
||||
readable = (new stream.Readable(options)).wrap(readable);
|
||||
}
|
||||
|
||||
if (typeof readable.read !== "function") {
|
||||
readable = (new stream.Readable(options)).wrap(readable);
|
||||
}
|
||||
this._writable = writable;
|
||||
this._readable = readable;
|
||||
this._waiting = false;
|
||||
|
||||
this._writable = writable;
|
||||
this._readable = readable;
|
||||
this._waiting = false;
|
||||
writable.once('finish', () => {
|
||||
this.end();
|
||||
});
|
||||
|
||||
var self = this;
|
||||
this.once('finish', () => {
|
||||
writable.end();
|
||||
});
|
||||
|
||||
writable.once("finish", function() {
|
||||
self.end();
|
||||
});
|
||||
readable.on('readable', () => {
|
||||
if (this._waiting) {
|
||||
this._waiting = false;
|
||||
this._read();
|
||||
}
|
||||
});
|
||||
|
||||
this.once("finish", function() {
|
||||
writable.end();
|
||||
});
|
||||
readable.once('end', () => {
|
||||
this.push(null);
|
||||
});
|
||||
|
||||
readable.on("readable", function() {
|
||||
if (self._waiting) {
|
||||
self._waiting = false;
|
||||
self._read();
|
||||
}
|
||||
});
|
||||
if (!options || typeof options.bubbleErrors === 'undefined' || options.bubbleErrors) {
|
||||
writable.on('error', error => {
|
||||
this.emit('error', error);
|
||||
});
|
||||
|
||||
readable.once("end", function() {
|
||||
self.push(null);
|
||||
});
|
||||
|
||||
if (!options || typeof options.bubbleErrors === "undefined" || options.bubbleErrors) {
|
||||
writable.on("error", function(err) {
|
||||
self.emit("error", err);
|
||||
});
|
||||
|
||||
readable.on("error", function(err) {
|
||||
self.emit("error", err);
|
||||
});
|
||||
}
|
||||
readable.on('error', error => {
|
||||
this.emit('error', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
DuplexWrapper.prototype = Object.create(stream.Duplex.prototype, {constructor: {value: DuplexWrapper}});
|
||||
|
||||
DuplexWrapper.prototype._write = function _write(input, encoding, done) {
|
||||
this._writable.write(input, encoding, done);
|
||||
DuplexWrapper.prototype._write = function (input, encoding, done) {
|
||||
this._writable.write(input, encoding, done);
|
||||
};
|
||||
|
||||
DuplexWrapper.prototype._read = function _read() {
|
||||
var buf;
|
||||
var reads = 0;
|
||||
while ((buf = this._readable.read()) !== null) {
|
||||
this.push(buf);
|
||||
reads++;
|
||||
}
|
||||
if (reads === 0) {
|
||||
this._waiting = true;
|
||||
}
|
||||
DuplexWrapper.prototype._read = function () {
|
||||
let buffer;
|
||||
let readCount = 0;
|
||||
while ((buffer = this._readable.read()) !== null) {
|
||||
this.push(buffer);
|
||||
readCount++;
|
||||
}
|
||||
|
||||
if (readCount === 0) {
|
||||
this._waiting = true;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function duplex2(options, writable, readable) {
|
||||
return new DuplexWrapper(options, writable, readable);
|
||||
};
|
||||
|
||||
module.exports.DuplexWrapper = DuplexWrapper;
|
||||
export default function duplexer(options, writable, readable) {
|
||||
return new DuplexWrapper(options, writable, readable);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
Copyright (c) 2022, Sindre Sorhus.
|
||||
Copyright (c) 2020, Vsevolod Strukchinsky.
|
||||
Copyright (c) 2013, Deoxxa Development.
|
||||
|
||||
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 the copyright holder 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
|
55
package.json
55
package.json
|
@ -1,28 +1,31 @@
|
|||
{
|
||||
"name": "duplexer3",
|
||||
"version": "0.1.4",
|
||||
"description": "Like duplexer but using streams3",
|
||||
"engine": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha -R tap"
|
||||
},
|
||||
"repository": "floatdrop/duplexer3",
|
||||
"keywords": [
|
||||
"duplex",
|
||||
"duplexer",
|
||||
"stream",
|
||||
"stream3",
|
||||
"join",
|
||||
"combine"
|
||||
],
|
||||
"author": "Conrad Pankoff <deoxxa@fknsrs.biz> (http://www.fknsrs.biz/)",
|
||||
"license": "BSD-3-Clause",
|
||||
"devDependencies": {
|
||||
"mocha": "^2.2.5"
|
||||
}
|
||||
"name": "duplexer3",
|
||||
"version": "1.0.0",
|
||||
"description": "Modern version of `duplexer2`",
|
||||
"license": "BSD-3-Clause",
|
||||
"repository": "sindresorhus/duplexer3",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=14.16"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && mocha"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"duplex",
|
||||
"duplexer",
|
||||
"stream",
|
||||
"streams",
|
||||
"join",
|
||||
"combine"
|
||||
],
|
||||
"devDependencies": {
|
||||
"mocha": "^10.0.0",
|
||||
"xo": "^0.50.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
# duplexer3
|
||||
|
||||
> Modern version of `duplexer2`
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install duplexer3
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import stream from 'node:stream';
|
||||
import duplexer from 'duplexer3';
|
||||
|
||||
const writable = new stream.Writable({objectMode: true});
|
||||
const readable = new stream.Readable({objectMode: true});
|
||||
|
||||
writable._write = function (input, encoding, done) {
|
||||
if (readable.push(input)) {
|
||||
done();
|
||||
} else {
|
||||
readable.once('drain', done);
|
||||
}
|
||||
};
|
||||
|
||||
readable._read = function () {
|
||||
// Noop
|
||||
};
|
||||
|
||||
// Simulate the readable thing closing after a bit
|
||||
writable.once('finish', () => {
|
||||
setTimeout(() => {
|
||||
readable.push(null);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
const duplex = duplexer3(writable, readable);
|
||||
|
||||
duplex.on('data', data => {
|
||||
console.log('got data', JSON.stringify(data));
|
||||
});
|
||||
|
||||
duplex.on('finish', () => {
|
||||
console.log('got finish event');
|
||||
});
|
||||
|
||||
duplex.on('end', () => {
|
||||
console.log('got end event');
|
||||
});
|
||||
|
||||
duplex.write('oh, hi there', () => {
|
||||
console.log('finished writing');
|
||||
});
|
||||
|
||||
duplex.end(() => {
|
||||
console.log('finished ending');
|
||||
});
|
||||
```
|
||||
|
||||
```
|
||||
got data 'oh, hi there'
|
||||
finished writing
|
||||
got finish event
|
||||
finished ending
|
||||
got end event
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### duplexer(options?, writableStream, readableStream)
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### bubbleErrors
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Whether to bubble errors from the underlying readable/writable streams.
|
|
@ -0,0 +1,199 @@
|
|||
/* globals describe, it, beforeEach */
|
||||
import assert from 'node:assert';
|
||||
import stream from 'node:stream';
|
||||
import duplexer, {DuplexWrapper} from './index.js';
|
||||
|
||||
describe('duplexer3', () => {
|
||||
let writable;
|
||||
let readable;
|
||||
|
||||
beforeEach(() => {
|
||||
writable = new stream.Writable({objectMode: true});
|
||||
readable = new stream.Readable({objectMode: true});
|
||||
|
||||
writable._write = function (input, encoding, done) {
|
||||
return done();
|
||||
};
|
||||
|
||||
readable._read = function () {};
|
||||
});
|
||||
|
||||
it('should interact with the writable stream properly for writing', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
writable._write = function (input, _encoding, _done) {
|
||||
assert.strictEqual(input.toString(), 'well hello there');
|
||||
return done();
|
||||
};
|
||||
|
||||
duplex.write('well hello there');
|
||||
});
|
||||
|
||||
it('should interact with the readable stream properly for reading', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
duplex.on('data', data => {
|
||||
assert.strictEqual(data.toString(), 'well hello there');
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
readable.push('well hello there');
|
||||
});
|
||||
|
||||
it('should end the writable stream, causing it to finish', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
writable.once('finish', done);
|
||||
|
||||
duplex.end();
|
||||
});
|
||||
|
||||
it('should finish when the writable stream finishes', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
duplex.once('finish', done);
|
||||
|
||||
writable.end();
|
||||
});
|
||||
|
||||
it('should end when the readable stream ends', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
// Required to let "end" fire without reading
|
||||
duplex.resume();
|
||||
duplex.once('end', done);
|
||||
|
||||
readable.push(null);
|
||||
});
|
||||
|
||||
it('should bubble errors from the writable stream when no behaviour is specified', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
const originalError = new Error('testing');
|
||||
|
||||
duplex.on('error', error => {
|
||||
assert.strictEqual(error, originalError);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
writable.emit('error', originalError);
|
||||
});
|
||||
|
||||
it('should bubble errors from the readable stream when no behaviour is specified', done => {
|
||||
const duplex = duplexer(writable, readable);
|
||||
|
||||
const originalError = new Error('testing');
|
||||
|
||||
duplex.on('error', error => {
|
||||
assert.strictEqual(error, originalError);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
readable.emit('error', originalError);
|
||||
});
|
||||
|
||||
it('should bubble errors from the writable stream when bubbleErrors is true', done => {
|
||||
const duplex = duplexer({bubbleErrors: true}, writable, readable);
|
||||
|
||||
const originalError = new Error('testing');
|
||||
|
||||
duplex.on('error', error => {
|
||||
assert.strictEqual(error, originalError);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
writable.emit('error', originalError);
|
||||
});
|
||||
|
||||
it('should bubble errors from the readable stream when bubbleErrors is true', done => {
|
||||
const duplex = duplexer({bubbleErrors: true}, writable, readable);
|
||||
|
||||
const originalError = new Error('testing');
|
||||
|
||||
duplex.on('error', error => {
|
||||
assert.strictEqual(error, originalError);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
readable.emit('error', originalError);
|
||||
});
|
||||
|
||||
it('should not bubble errors from the writable stream when bubbleErrors is false', done => {
|
||||
const duplex = duplexer({bubbleErrors: false}, writable, readable);
|
||||
|
||||
const timeout = setTimeout(done, 25);
|
||||
|
||||
duplex.on('error', _error => {
|
||||
clearTimeout(timeout);
|
||||
return done(new Error('shouldn\'t bubble error'));
|
||||
});
|
||||
|
||||
// Prevent uncaught error exception
|
||||
writable.on('error', () => {});
|
||||
|
||||
writable.emit('error', new Error('testing'));
|
||||
});
|
||||
|
||||
it('should not bubble errors from the readable stream when bubbleErrors is false', done => {
|
||||
const duplex = duplexer({bubbleErrors: false}, writable, readable);
|
||||
|
||||
const timeout = setTimeout(done, 25);
|
||||
|
||||
duplex.on('error', _error => {
|
||||
clearTimeout(timeout);
|
||||
return done(new Error('shouldn\'t bubble error'));
|
||||
});
|
||||
|
||||
// Prevent uncaught error exception
|
||||
readable.on('error', () => {});
|
||||
|
||||
readable.emit('error', new Error('testing'));
|
||||
});
|
||||
|
||||
it('should export the DuplexWrapper constructor', () => {
|
||||
assert.equal(typeof DuplexWrapper, 'function');
|
||||
});
|
||||
|
||||
it('should not force flowing-mode', done => {
|
||||
const writable = new stream.PassThrough();
|
||||
const readable = new stream.PassThrough();
|
||||
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
|
||||
const duplexStream = duplexer(writable, readable);
|
||||
duplexStream.end('aaa');
|
||||
|
||||
assert.equal(readable._readableState.flowing, false);
|
||||
|
||||
const transformStream = new stream.Transform({
|
||||
transform(chunk, encoding, cb) {
|
||||
this.push(String(chunk).toUpperCase());
|
||||
cb();
|
||||
},
|
||||
});
|
||||
writable.pipe(transformStream).pipe(readable);
|
||||
|
||||
assert.equal(readable._readableState.flowing, false);
|
||||
|
||||
setTimeout(() => {
|
||||
assert.equal(readable._readableState.flowing, false);
|
||||
|
||||
let source = '';
|
||||
duplexStream.on('data', buffer => {
|
||||
source += String(buffer);
|
||||
});
|
||||
duplexStream.on('end', () => {
|
||||
assert.equal(source, 'AAA');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
assert.equal(readable._readableState.flowing, false);
|
||||
});
|
||||
});
|
||||
});
|
206
test/tests.js
206
test/tests.js
|
@ -1,206 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var assert = require("assert");
|
||||
var stream = require("stream");
|
||||
|
||||
var duplexer3 = require("../");
|
||||
|
||||
describe("duplexer3", function() {
|
||||
var writable, readable;
|
||||
|
||||
beforeEach(function() {
|
||||
writable = new stream.Writable({objectMode: true});
|
||||
readable = new stream.Readable({objectMode: true});
|
||||
|
||||
writable._write = function _write(input, encoding, done) {
|
||||
return done();
|
||||
};
|
||||
|
||||
readable._read = function _read(n) {
|
||||
};
|
||||
});
|
||||
|
||||
it("should interact with the writable stream properly for writing", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
writable._write = function _write(input, encoding, _done) {
|
||||
assert.strictEqual(input.toString(), "well hello there");
|
||||
|
||||
return done();
|
||||
};
|
||||
|
||||
duplex.write("well hello there");
|
||||
});
|
||||
|
||||
it("should interact with the readable stream properly for reading", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
duplex.on("data", function(e) {
|
||||
assert.strictEqual(e.toString(), "well hello there");
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
readable.push("well hello there");
|
||||
});
|
||||
|
||||
it("should end the writable stream, causing it to finish", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
writable.once("finish", done);
|
||||
|
||||
duplex.end();
|
||||
});
|
||||
|
||||
it("should finish when the writable stream finishes", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
duplex.once("finish", done);
|
||||
|
||||
writable.end();
|
||||
});
|
||||
|
||||
it("should end when the readable stream ends", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
// required to let "end" fire without reading
|
||||
duplex.resume();
|
||||
duplex.once("end", done);
|
||||
|
||||
readable.push(null);
|
||||
});
|
||||
|
||||
it("should bubble errors from the writable stream when no behaviour is specified", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
var originalErr = Error("testing");
|
||||
|
||||
duplex.on("error", function(err) {
|
||||
assert.strictEqual(err, originalErr);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
writable.emit("error", originalErr);
|
||||
});
|
||||
|
||||
it("should bubble errors from the readable stream when no behaviour is specified", function(done) {
|
||||
var duplex = duplexer3(writable, readable);
|
||||
|
||||
var originalErr = Error("testing");
|
||||
|
||||
duplex.on("error", function(err) {
|
||||
assert.strictEqual(err, originalErr);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
readable.emit("error", originalErr);
|
||||
});
|
||||
|
||||
it("should bubble errors from the writable stream when bubbleErrors is true", function(done) {
|
||||
var duplex = duplexer3({bubbleErrors: true}, writable, readable);
|
||||
|
||||
var originalErr = Error("testing");
|
||||
|
||||
duplex.on("error", function(err) {
|
||||
assert.strictEqual(err, originalErr);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
writable.emit("error", originalErr);
|
||||
});
|
||||
|
||||
it("should bubble errors from the readable stream when bubbleErrors is true", function(done) {
|
||||
var duplex = duplexer3({bubbleErrors: true}, writable, readable);
|
||||
|
||||
var originalErr = Error("testing");
|
||||
|
||||
duplex.on("error", function(err) {
|
||||
assert.strictEqual(err, originalErr);
|
||||
|
||||
return done();
|
||||
});
|
||||
|
||||
readable.emit("error", originalErr);
|
||||
});
|
||||
|
||||
it("should not bubble errors from the writable stream when bubbleErrors is false", function(done) {
|
||||
var duplex = duplexer3({bubbleErrors: false}, writable, readable);
|
||||
|
||||
var timeout = setTimeout(done, 25);
|
||||
|
||||
duplex.on("error", function(err) {
|
||||
clearTimeout(timeout);
|
||||
|
||||
return done(Error("shouldn't bubble error"));
|
||||
});
|
||||
|
||||
// prevent uncaught error exception
|
||||
writable.on("error", function() {});
|
||||
|
||||
writable.emit("error", Error("testing"));
|
||||
});
|
||||
|
||||
it("should not bubble errors from the readable stream when bubbleErrors is false", function(done) {
|
||||
var duplex = duplexer3({bubbleErrors: false}, writable, readable);
|
||||
|
||||
var timeout = setTimeout(done, 25);
|
||||
|
||||
duplex.on("error", function(err) {
|
||||
clearTimeout(timeout);
|
||||
|
||||
return done(Error("shouldn't bubble error"));
|
||||
});
|
||||
|
||||
// prevent uncaught error exception
|
||||
readable.on("error", function() {});
|
||||
|
||||
readable.emit("error", Error("testing"));
|
||||
});
|
||||
|
||||
it("should export the DuplexWrapper constructor", function() {
|
||||
assert.equal(typeof duplexer3.DuplexWrapper, "function");
|
||||
});
|
||||
|
||||
/*
|
||||
it("should not force flowing-mode", function(done) {
|
||||
var writable = new stream.PassThrough();
|
||||
var readable = new stream.PassThrough();
|
||||
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
|
||||
var duplexStream = duplexer3(writable, readable);
|
||||
duplexStream.end("aaa");
|
||||
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
|
||||
var transformStream = new stream.Transform({
|
||||
transform: function(chunk, encoding, cb) {
|
||||
this.push(String(chunk).toUpperCase());
|
||||
cb();
|
||||
}
|
||||
});
|
||||
writable.pipe(transformStream).pipe(readable);
|
||||
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
|
||||
var src = "";
|
||||
duplexStream.on("data", function(buf) {
|
||||
src += String(buf);
|
||||
});
|
||||
duplexStream.on("end", function() {
|
||||
assert.equal(src, "AAA");
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
assert.equal(readable._readableState.flowing, null);
|
||||
});
|
||||
});
|
||||
*/
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
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
|
|
@ -0,0 +1,38 @@
|
|||
# Installation
|
||||
> `npm install --save @types/duplexer3`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for duplexer3 (https://github.com/floatdrop/duplexer3).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/duplexer3.
|
||||
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/duplexer3/index.d.ts)
|
||||
````ts
|
||||
// Type definitions for duplexer3 0.1
|
||||
// Project: https://github.com/floatdrop/duplexer3
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as stream from 'stream';
|
||||
|
||||
export = duplexer3;
|
||||
|
||||
declare function duplexer3(writableStream: NodeJS.WritableStream, readableStream: NodeJS.ReadableStream): stream.Duplex;
|
||||
declare function duplexer3(options: duplexer3.Options, writableStream: NodeJS.WritableStream, readableStream: NodeJS.ReadableStream): stream.Duplex;
|
||||
|
||||
declare namespace duplexer3 {
|
||||
interface Options extends stream.DuplexOptions {
|
||||
bubbleErrors?: boolean | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
````
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Tue, 06 Jul 2021 20:32:49 GMT
|
||||
* Dependencies: [@types/node](https://npmjs.com/package/@types/node)
|
||||
* Global values: none
|
||||
|
||||
# Credits
|
||||
These definitions were written by [BendingBender](https://github.com/BendingBender).
|
|
@ -0,0 +1,18 @@
|
|||
// Type definitions for duplexer3 0.1
|
||||
// Project: https://github.com/floatdrop/duplexer3
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as stream from 'stream';
|
||||
|
||||
export = duplexer3;
|
||||
|
||||
declare function duplexer3(writableStream: NodeJS.WritableStream, readableStream: NodeJS.ReadableStream): stream.Duplex;
|
||||
declare function duplexer3(options: duplexer3.Options, writableStream: NodeJS.WritableStream, readableStream: NodeJS.ReadableStream): stream.Duplex;
|
||||
|
||||
declare namespace duplexer3 {
|
||||
interface Options extends stream.DuplexOptions {
|
||||
bubbleErrors?: boolean | undefined;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "@types/duplexer3",
|
||||
"version": "0.1.1",
|
||||
"description": "TypeScript definitions for duplexer3",
|
||||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/duplexer3",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "BendingBender",
|
||||
"url": "https://github.com/BendingBender",
|
||||
"githubUsername": "BendingBender"
|
||||
}
|
||||
],
|
||||
"main": "",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||
"directory": "types/duplexer3"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
},
|
||||
"typesPublisherContentHash": "13621962e86c833794b8a0aa492269e5d529d1b97b36368a0053c1086dc3e612",
|
||||
"typeScriptVersion": "3.6"
|
||||
}
|
Loading…
Reference in New Issue