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

addChunked stream version method for Node.js, #1513 #1517

Merged

Conversation

koltyakov
Copy link
Member

@koltyakov koltyakov commented Jan 10, 2021

Category

  • Bug fix?
  • New feature?
  • New sample?
  • Documentation update?

Related Issues

mentioned in #1513

What's in this Pull Request?

The PR adds addChunked method extension to support ReadStream in Node.js.

Guidance

For a test, run npm run test -- -g 'nodejs - sp-extensions'

Usage: when Node.js sp-extensions are loaded addChunked method is extended and "polyfilled" to support stream content received with Node's fs.createReadStream.

const stream = fs.createReadStream('/path/to/file.dat');
await files.addChunked(name, stream);

Existing user implementations should not fail. When no-stream content is passed, it is processed as previously.

@patrick-rodgers patrick-rodgers added this to the 2.1.0 milestone Jan 11, 2021
@patrick-rodgers
Copy link
Member

Awesome, thanks! We'll have a look and get it merged ahead of the release Friday so will land in 2.1.0.

@patrick-rodgers
Copy link
Member

TIL about the -g option for mocha. That is awesome. Thanks for doing this, will be a big help for folks in node. I added the methods to the docs page too.

@patrick-rodgers patrick-rodgers merged commit 5d200cd into pnp:version-2 Jan 15, 2021
@koltyakov
Copy link
Member Author

Oh, docs, that's what I forgot completely.

Tested the published version's method by uploading 3GB file and checking if I can playback it after. Went well. But found a nuance which we could add to docs as well. Readable stream should be created with fixed hight water mark equal to chunk size:

// Important: highWaterMark must be equal to chunkSize
const rs = fs.createReadStream(filePath, { highWaterMark: chunkSize });

Linking a comment with usage sample for those who found a the PR directly #1513 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants