This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stream = require('stream') | |
const readStream = new stream.Readable({ | |
read() {} | |
}) | |
const writeStream = new stream.Writable() | |
writeStream._write = (chunk, encoding, next) => { | |
next() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stream = require('stream'); | |
console.log(stream); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { PassThrough } = require("stream"); | |
const { createReadStream, createWriteStream } = require("fs"); | |
const readStream = createReadStream("./README.md"); | |
const writeStream = createWriteStream("./copy.txt"); | |
const tunnel = new PassThrough(); | |
tunnel.on("data", (chunk) => { | |
console.log("bytes:", chunk); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "prime-block", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Stream = require('stream') | |
const readableStream = new Stream.Readable({ | |
read() {} | |
}) | |
readableStream.push("Data"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Stream = require('stream'); | |
const writableStream = new Stream.Writable(); | |
writableStream._write = (chunk, encoding, next) => { | |
console.log(chunk.toString()) | |
next() | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ command1 | command2 | command3 | command4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const fs = require("fs"); | |
const server = http.createServer((req, res) => { | |
const stream = fs.createReadStream(__dirname + "/file.txt"); | |
stream.pipe(res); | |
}); | |
server.listen(5000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const fs = require('fs'); | |
const server = http.createServer((req, res) => { | |
fs.readFile(__dirname + '/file.txt', (err, data) => { | |
res.end(data) | |
}) | |
}); | |
server.listen(5000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.on('message', (message) => { | |
const response = calculatePrime(message.primeNumber); | |
process.send(response); | |
process.exit; | |
}); | |
const calculatePrime = (number) => { | |
let start = new Date(); | |
let end = new Date(); |