Code files
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
const from = require('from2')
|
||||
const to = require('to2')
|
||||
const duplexify = require('duplexify')
|
||||
|
||||
const rs = from(() => {
|
||||
rs.push(Buffer.from('Hello, World!'))
|
||||
rs.push(null)
|
||||
})
|
||||
|
||||
const ws = to((data, enc, cb) => {
|
||||
console.log(`Data written: ${data.toString()}`)
|
||||
cb()
|
||||
})
|
||||
|
||||
const stream = duplexify(ws, rs)
|
||||
|
||||
stream.pipe(stream)
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "composing-duplex-streams",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"from2": "^2.3.0",
|
||||
"to2": "^1.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
const { Readable, Writable } = require('readable-stream')
|
||||
|
||||
const rs = Readable({
|
||||
read: () => {
|
||||
rs.push(Buffer.from('Hello, World!'))
|
||||
rs.push(null)
|
||||
}
|
||||
})
|
||||
|
||||
const ws = Writable({
|
||||
write: (data, enc, cb) => {
|
||||
console.log(`Data written: ${data.toString()}`)
|
||||
cb()
|
||||
}
|
||||
})
|
||||
|
||||
rs.pipe(ws)
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const from = require('from2')
|
||||
const to = require('to2')
|
||||
|
||||
const rs = from(() => {
|
||||
rs.push(Buffer.from('Hello, World!'))
|
||||
rs.push(null)
|
||||
})
|
||||
|
||||
// rs.on('data', (data) => {
|
||||
// console.log(data.toString())
|
||||
// })
|
||||
|
||||
const ws = to((data, enc, cb) => {
|
||||
console.log(`Data written: ${data.toString()}`)
|
||||
cb()
|
||||
})
|
||||
|
||||
rs.pipe(ws)
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "from2-to2-streams",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"from2": "^2.3.0",
|
||||
"to2": "^1.0.0"
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const from = require('from2')
|
||||
const rs = from((size, cb) => {
|
||||
setTimeout(() => {
|
||||
rs.push('Data 0')
|
||||
setTimeout(() => {
|
||||
rs.push('Data 1')
|
||||
cb()
|
||||
}, 50)
|
||||
}, 100)
|
||||
})
|
||||
|
||||
rs.on('data', (data) => {
|
||||
console.log(data.toString())
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "readable-flow-control",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"from2": "^2.3.0",
|
||||
"readable-stream": "^2.2.6"
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
// WARNING: DOES NOT WORK AS EXPECTED
|
||||
const { Readable } = require('readable-stream')
|
||||
const rs = Readable({
|
||||
read: () => {
|
||||
setTimeout(() => {
|
||||
rs.push('Data 0')
|
||||
setTimeout(() => {
|
||||
rs.push('Data 1')
|
||||
}, 50)
|
||||
}, 100)
|
||||
}
|
||||
})
|
||||
|
||||
rs.on('data', (data) => {
|
||||
console.log(data.toString())
|
||||
})
|
||||
Reference in New Issue
Block a user