Replace fs.ReadStream
-centric handling with more generic PathReference
#767
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.
In all current tus-js-client versions, the only way to upload a file on disk in Node.js without loading the entire content into a Buffer is to create an fs.ReadStream and pass it to the Upload constructor. While this might make sense in the beginning, it's actually pretty useless since tus-js-client doesn't use the stream at all to read the file. Instead, it inspects the fs.ReadStream's path property and uses it when opening new fs.ReadStreams for each PATCH request.
This allows tus-js-client to effortlessly seek to previous positions without buffering when the upload is interrupted and has to be resumed. However, requiring our users to first create an fs.ReadStream, which then basically thrown away by tus-js-client is not a good approach.
Hence, this PR changes how files can be uploaded in Node.js. Instead of testing specifically for fs.ReadStream, tus-js-client will now accept a more generic object that matches a PathReference interface, which is basically just an object with a
path
property and optional start/end positions (seelib/options.ts
). The interface has been designed to match fs.ReadStream, so existing integrations with tus-js-client won't break due to this PR.However, the new interface allows users to also upload files by just giving tus-js-client the path: