2
The point is that I can use both functions to do the same thing. For example:
const fs = require('fs')
const path = require('path')
const filePath = path.join(__dirname, '../arquivo.txt')
fs.readFile(filePath,
(error, fileContent) => console.log(fileContent.toString()))
fs.createReadStream(filePath)
.on('data', data => console.log(data.toString()))
I know that the createReadStream()
returns a stream, but I don’t know exactly all the things a stream can do. The point is I’m using the module fs
which I believe is focused on interacting with other files, if I already have two functions to read a file, one asynchronous and one synchronous (.readFile()
and .readFileSync()
) and return me his content, why do I need another to return me a stream? What will be the advantage in that?
I understood but I have almost no idea what would be a large file and a small one, I will give a search in relation to this, thanks for the help you have helped me a lot in my first two questions and it was bad for the bad use of grammar kkkk, but anyway I just wanted to thank you for the help msm.
– arturHamann
@arturHamann, imagine a . csv with millions of lines and you want to analyze one by one. Loading it all at once is impractical to the detriment of its size. In this type of situation, it is ideal to use streams. And what grammar, only? I just formatted the function names! :-)
– Luiz Felipe