Skip to content

Commit 683ee1d

Browse files
fengmk2Copilot
andauthored
fix: zero copy to create a new Buffer (#916)
https://nodejs.org/docs/latest-v24.x/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Optimized binary data handling to reduce memory copies and improve performance. * Preserves identical visible content while changing internal buffer object identity — callers that rely on object identity (rather than content) may observe differences. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: MK (fengmk2) <fengmk2@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0a5c90c commit 683ee1d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/repository/DistRepository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export class DistRepository {
9090
async readDistBytesToBuffer(dist: Dist): Promise<Buffer | undefined> {
9191
const bytes = await this.readDistBytes(dist);
9292
if (!bytes) return undefined;
93-
return Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes);
93+
// if bytes is Uint8Array, should use zero copy to create a new Buffer
94+
// https://nodejs.org/docs/latest-v24.x/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length
95+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
9496
}
9597

9698
async readDistBytesToJSONBuilder(dist: Dist): Promise<JSONBuilder | undefined> {

0 commit comments

Comments
 (0)