Last active
December 13, 2017 14:03
-
-
Save boostup/1b6195b63cab9ca5fa2708e0bf46d445 to your computer and use it in GitHub Desktop.
create huge file. then create readable stream with file and flush out line by line to the console
This file contains 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 fs = require('fs'); | |
const file = fs.createWriteStream('./big.file'); | |
for(let i=0; i<= 500000; i++) { | |
file.write('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n'); | |
} | |
file.end(); |
This file contains 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 fs = require('fs'); | |
const server = require('http').createServer(); | |
server.on('request', (req, res) => { | |
fs.readFile('./big.file', (err, data) => { | |
if (err) throw err; | |
res.end(data); | |
}); | |
}); | |
server.listen(8000); |
This file contains 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 fs = require('fs'); | |
const server = require('http').createServer(); | |
server.on('request', (req, res) => { | |
const src = fs.createReadStream('./big.file'); | |
src.pipe(res); | |
}); | |
server.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment