1.0.0 • Published 3 years ago

duplexer3 v1.0.0

Weekly downloads
12,693,768
License
BSD-3-Clause
Repository
github
Last release
3 years ago

duplexer3

Modern version of duplexer2

Install

npm install duplexer3

Usage

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.

archetype-libraryreact-native-bluetooth2killi8n-react-native-fast-imagegot-blah-blah-testcad-cli@cashremit/cr-streamline-iconsairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationdiscord-music-botsreact-native-covid-sdk@saeon/ol-react@saeon/quick-formmysql-formatreact-native-printer-brotherscogoportutilsdyx-reacttalent-to-vite-clione-indexunblock-block-save-variables@infinitebrahmanuniverse/nolb-dup@prodam/prodam-types@everything-registry/sub-chunk-1538tap-ontap-minweb-elements-iconswebchewhatsconcteapackage-tatespoorman297spooky2test-public-provision-camera-plugin-scan-facesvdv-451-readervite_vue3_ts_ssssdddddyyyycauseway-concrete-stylesjeuxuijnf-accesscontrol-rnttljm-etljametlazy-bee-uihw9hubot-budaherculemama-exporterm2m-chartjs-plugin-crosshairkooks@wecraftapps/react-native-use-keyboard@thismr/bitmindtest-core@tonysusi/vapid@vandai-nguyen/module_test@xsahxl/got@xswap/v2-core@xiwen5566/aqara-automation-switch@yplabs-ltd/react-native-detector@yak-spirit/yak-swap-uiarvm-bestdeveloper@olympfin/olymp-swap-lib@npm-lt/cli@nodeberry/solidity-payment-processor@innodata/vue-v3-ya-metrika@innoswap/core@imrtoy/homebridge-night-light@igniswap/igni-swap-lib@phong95/react-native-multiple-image-picker@orschweitzer/git-clone-packagegenerator-liuhuijun-vuegdphptt@sudophunk/fulido@taingo97/react-native-expo-key-rsa-kt@taingo97/react-native-expo-rsa@taingo97/react-native-rsa@taingo97/react-native-telpo-printerdrift-npmelectron-epos-printerelectron-auto-print-pdfelectron-pdf-window-autoetletheral-clifhir2first-app-lyfuci@prantlf/faucet@bkrmadtya/sorting-steps@bonsaiswap-lib/lib@bonsaiswapv3/core@bonsaiswapv3/deploy@chauhan-rakesh/cardjs@chauhan-rakesh/chauhan-rakesh@chiaraani/bouncing-ball@chakra-swap/core@bee-icons/qwik@borealisswap/borealis-swap-libcblink-clicotrader-dex-sdkcordova-plugin-demotoastdb-stations-clidereamcustom-got
1.0.0

3 years ago

0.1.5

3 years ago

0.1.4

10 years ago