Skip to content

Commit d4f8231

Browse files
author
Nitzan Uziely
committed
fixup! feat(lib-storage): improve performance by reducing buffer copies
1 parent cc1e011 commit d4f8231

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/node-http-handler/src/write-request-body.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ function writeBody(
2222
// pipe automatically handles end
2323
body.pipe(httpRequest);
2424
} else if (body) {
25-
httpRequest.end(Buffer.from(body));
25+
if (Buffer.isBuffer(body) || typeof body === "string") {
26+
httpRequest.end(body);
27+
} else {
28+
httpRequest.end(Buffer.from(body));
29+
}
2630
} else {
2731
httpRequest.end();
2832
}

packages/util-body-length-node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function calculateBodyLength(body: any): number | undefined {
55
return 0;
66
}
77
if (typeof body === "string") {
8-
return Buffer.from(body).length;
8+
return Buffer.byteLength(body);
99
} else if (typeof body.byteLength === "number") {
1010
// handles Uint8Array, ArrayBuffer, Buffer, and ArrayBufferView
1111
return body.byteLength;

0 commit comments

Comments
 (0)