feat: range request support for getBytes and getStream#21
Merged
Conversation
Contributor
Author
|
Hi @thetutlage. Could you please provide any feedback and your thoughts on when it might be possible to release this functionality? I work on a large project which uses flydrive and really needs this functionality. Thank you 👍 |
Collaborator
|
Looks good. Sorry for sleeping on it for a while. Can you also send a PR for the docs? |
Contributor
Author
|
Thanks for getting this merged @thetutlage! As requested, I've raised a PR with the documentation under flydrive-js/flydrive.dev#3 |
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.
Range Reads
The
getStreamandgetBytesmethods support reading a subset of a file's bytes by passing an optionalrangeoption. This is useful for use cases like serving media segments, implementing resumable downloads, or reading file headers without fetching the entire file.Basic usage
Range options
The
rangeoption accepts aRangeRequestobject with optionalstartandendproperties.startnumberendnumberBoth
startandendare absolute byte positions. They must be positive integers and are both inclusive. For example,{ start: 0, end: 9 }reads the first 10 bytes of the file.When
startis omitted, reading begins from byte 0. Whenendis omitted, reading continues to the end of the file.Passing an empty
rangeobject ({}) or omitting therangeoption entirely both result in the full file being returned.Validation and errors
Range values are validated before any I/O is performed. An
E_RANGE_UNSATISFIABLEexception is thrown if:startorendis a negative numberstartorendis not an integerstartis greater thanendstartorendexceeds the file sizeThe validation behaviour is consistent across all three drivers (FS, GCS, and S3). A content length preflight is performed before the read in all cases to ensure uniform error handling regardless of the underlying storage backend.
Note on text content
Range reads are not supported on the
getmethod, which returns file contents as a UTF-8 string. This is intentional, splitting a file at an arbitrary byte boundary can produce invalid UTF-8 sequences if a multi-byte character spans the boundary. UsegetByteswith a range and decode the result yourself if you need ranged text reads and can guarantee boundary alignment.