fix: handle stream reading past file size in FsaNodeReadStream#1210
Merged
streamich merged 2 commits intoOct 6, 2025
Conversation
Co-authored-by: streamich <[email protected]>
Copilot
AI
changed the title
[WIP] Bug: stream reading past file size
fix: handle stream reading past file size in FsaNodeReadStream
Oct 6, 2025
Contributor
|
🎉 This PR is included in version 4.49.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
When using the FSA-to-Node adapter with
createReadStream()and a range read where thestartposition is beyond the file end, the stream would throw an unhandledRangeError: Invalid typed array lengthinstead of returning an empty buffer and closing gracefully.Root Cause
The
FsaNodeReadStream.__read__()method was attempting to create aUint8Arraywith an offset (start) that exceeded the buffer's byte length:When
start >= buffer.byteLength, this constructor call fails because you cannot create a typed array view with an offset beyond the buffer bounds.Solution
Added a check to return an empty
Uint8Array(0)when the start position is at or beyond the file size:This matches the behavior of Node.js's native
fs.createReadStream(), which returns an empty stream when reading past the file end.Testing
Added two test cases:
start: 100on a 4-byte file - returns empty bufferstart: 4on a 4-byte file (exactly at end) - returns empty bufferBoth tests verify the stream closes properly without errors and produces an empty output.
All existing tests continue to pass (897 tests).
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.