-
Notifications
You must be signed in to change notification settings - Fork 103
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
reduce buffer copies #867
Conversation
3f3c073
to
3833f3e
Compare
@@ -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); |
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.
Confirmed this works in Node.js 14+
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.
> 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); |
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.
ClientRequest (node:http(s)
) and ClientHttp2Stream (node:http2
) both accept .end(string)
in addition to .end(Buffer)
.
supercedes external contrib aws/aws-sdk-js-v3#2612