Streaming: Don't load the entire file into memory #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this change,
FileReadStream
would read the full file into memorywith a single readAsArrayBuffer() call.
This commit calls readAsArrayBuffer() with a slice of the file blob for
each call to _read(). This means the blob is never fully loaded into
memory.
The same FileReader object is reused, just with different slices of the
file blob passed into readAsArrayBuffer().
Also, this eliminates the event named 'readable' which was causing bugs
when I piped this stream into another stream library.
I also added browser tests for
FileReadStream
.Run the tests in a local browser with
npm run test-local
. Run the tests remotely with a free sauce labs account withnpm test
. Also, if we set up travis, it can run the tests automatically for us. :-)