Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it save the whole file to RAM? #48

Open
rfonovicell opened this issue Jan 28, 2022 · 1 comment
Open

Does it save the whole file to RAM? #48

rfonovicell opened this issue Jan 28, 2022 · 1 comment

Comments

@rfonovicell
Copy link

Sorry if my question is dumb, but I believe the whole point of reading a file line-by-line is not having to load it entirely into RAM in order to read it. So if I have, for example, an 100 MB file, will it be loaded into RAM before the code can read it?

@ungoldman
Copy link

It uses a read stream internally, and additionally buffers one line at a time using a separator character, if I'm reading the source correctly. So only one line is buffered into memory at a time.

What makes streams unique, is that instead of a program reading a file into memory all at once like in the traditional way, streams read chunks of data piece by piece, processing its content without keeping it all in memory.

src: https://nodesource.com/blog/understanding-streams-in-nodejs/

ref: https://nodejs.org/api/fs.html#filehandlecreatereadstreamoptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants