Gathering detailed insights and metrics for @justinbeckwith/duplexify
Gathering detailed insights and metrics for @justinbeckwith/duplexify
npm install @justinbeckwith/duplexify
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.8
Supply Chain
98.5
Quality
74.9
Maintenance
100
Vulnerability
100
License
Total Downloads
9,414
Last Day
5
Last Week
40
Last Month
276
Last Year
3,876
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
@justinbeckwith/duplexify@4.0.0
Unpacked Size
22.34 kB
Size
6.41 kB
File Count
6
NPM Version
6.10.1
Node Version
10.16.0
Cumulative downloads
Total Downloads
Last day
-76.2%
5
Compared to previous day
Last week
-56.5%
40
Compared to previous week
Last month
41.5%
276
Compared to previous month
Last year
4.8%
3,876
Compared to previous year
Turn a writeable and readable stream into a single streams2 duplex stream.
duplexify
This is a fork of duplexify. It does a few things different:
npm install @justinbeckwith/duplexify
Use duplexify(writable, readable, streamOptions)
(or duplexify.obj(writable, readable)
to create an object stream)
1const {duplexify} = require('@justinbeckwith/duplexify') 2 3// turn writableStream and readableStream into a single duplex stream 4const dup = duplexify(writableStream, readableStream) 5 6dup.write('hello world') // will write to writableStream 7dup.on('data', (data) => { 8 // will read from readableStream 9})
You can also set the readable and writable parts asynchronously
1const dup = duplexify() 2 3dup.write('hello world') // write will buffer until the writable 4 // part has been set 5 6// wait a bit ... 7dup.setReadable(readableStream) 8 9// maybe wait some more? 10dup.setWritable(writableStream)
If you call setReadable
or setWritable
multiple times it will unregister the previous readable/writable stream.
To disable the readable or writable part call setReadable
or setWritable
with null
.
If the readable or writable streams emits an error or close it will destroy both streams and bubble up the event.
You can also explicitly destroy the streams by calling dup.destroy()
. The destroy
method optionally takes an
error object as argument, in which case the error is emitted as part of the error
event.
1dup.on('error', (err) => { 2 console.log('readable or writable emitted an error - close will follow') 3}) 4 5dup.on('close', () => { 6 console.log('the duplex stream is destroyed') 7}) 8 9dup.destroy() // calls destroy on the readable and writable part (if present)
Turn a node core http request into a duplex stream is as easy as
1const {duplexify} = require('duplexify') 2const http = require('http') 3 4const request = (opts) => { 5 const req = http.request(opts) 6 const dup = duplexify(req) 7 req.on('response', (res) => { 8 dup.setReadable(res) 9 }) 10 return dup 11} 12 13const req = request({ 14 method: 'GET', 15 host: 'www.google.com', 16 port: 80 17}) 18 19req.end() 20req.pipe(process.stdout)
MIT
No vulnerabilities found.
No security vulnerabilities found.