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

reduce buffer copies #867

Merged
merged 1 commit into from
Mar 12, 2024
Merged

reduce buffer copies #867

merged 1 commit into from
Mar 12, 2024

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Aug 11, 2023

supercedes external contrib aws/aws-sdk-js-v3#2612

@@ -8,7 +8,7 @@ export const calculateBodyLength = (body: any): number | undefined => {
return 0;
}
if (typeof body === "string") {
return Buffer.from(body).length;
return Buffer.byteLength(body);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this works in Node.js 14+

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> Buffer.byteLength('🚀a')
5
> Buffer.from('🚀a').length
5

@@ -59,7 +59,14 @@ function writeBody(
// pipe automatically handles end
body.pipe(httpRequest);
} else if (body) {
httpRequest.end(Buffer.from(body as Parameters<typeof Buffer.from>[0]));
if (Buffer.isBuffer(body) || typeof body === "string") {
httpRequest.end(body);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClientRequest (node:http(s)) and ClientHttp2Stream (node:http2) both accept .end(string) in addition to .end(Buffer).

@kuhe kuhe merged commit 511206e into smithy-lang:main Mar 12, 2024
7 checks passed
@kuhe kuhe deleted the feat/buffer branch March 12, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants