-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix: don't always convert bytes to text in streamToPromise #182
Conversation
Update doc in streamToPromise to indicate it is not always text. Remove `toString()` call when using `Buffer` type. Add test for binary type stream. Update assertions for `Buffer` streams to assert length and checksums.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
@ricellis Before merging, I want to make sure you're aware of this invocation - https://github.com/IBM/node-sdk-core/blob/main/lib/request-wrapper.ts#L445 It is calling |
Agreed. Though |
@dpopp07 I added the check in 1e9e691. FWIW I'm actually a little unsure about the "else" case - I don't understand what the expectation is for a returned |
@dpopp07 are you OK with the latest addition here? Would you like me to squash the commits? |
@ricellis Sorry, I've been distracted by urgent work the last few days. I looked at that last change and it looks great.
Agreed, no need to start tweaking existing behavior. If that becomes an issue, we will address it but it never has been in the past. Unless there are any more changes you're planning to make, I will merge today. |
@dpopp07 np, I know the feeling! I'm not planning anything else for this so happy for it to merge whenever you get the chance, thanks so much. |
## [2.17.4](v2.17.3...v2.17.4) (2021-12-16) ### Bug Fixes * don't always convert bytes to text in streamToPromise ([#182](#182)) ([7fe261b](7fe261b))
🎉 This PR is included in version 2.17.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Generated SDK source code using: - Generator version 3.26.0 - Specification version 1.0.0-dev0.0.31 - Automation (cloudant-sdks) version 7c23742
streamToPromise
callstoString()
on theconcat
edBuffer
which defaults toutf-8
encoding and consequently can mangle nonutf-8
content. This problem surfaced via IBM/cloudant-node-sdk#546.toString()
call when usingBuffer
type.The problem is resolved by not calling
toString()
as theBuffer
bytes may be passed as-is to the server for a byte stream. In cases where the stream is usingstring
orobjectMode
notBuffer
then the existingBuffer.isBuffer(results[0])
check puts the chunk as-is into theresults
array (i.e. it is an array of strings or objects).Buffer
streams to assert length and checksums.Checklist
npm test
passes (tip:npm run lint-fix
can correct most style issues)