Skip to content

fix: drop redundant TextEncoder copy in SDK file writes - #41

Open
KIRA-L001 wants to merge 1 commit into
BitMiracle-AI:mainfrom
KIRA-L001:fix/issue-36
Open

fix: drop redundant TextEncoder copy in SDK file writes#41
KIRA-L001 wants to merge 1 commit into
BitMiracle-AI:mainfrom
KIRA-L001:fix/issue-36

Conversation

@KIRA-L001

Copy link
Copy Markdown

Closes #36.

writeFiles and writeFile ran string content through new TextEncoder().encode(...) before Buffer.from, allocating and copying the full content twice on the file-push hot path. Buffer.from(string) is already UTF-8 encoding and Buffer.from(Uint8Array) is the same copy the code already makes, so both call sites now pass the string | Uint8Array union straight to Buffer.from(...) — exactly the deletion proposed in the issue. Byte output is identical (Node utf8 and TextEncoder both substitute U+FFFD for lone surrogates).

Verified locally in packages/sdk: pnpm typecheck (strict) clean; pnpm test — 31 passed, including the existing multi-byte round-trip test ('hello 文件') that pins the encoding behaviour.

…racle-AI#36)

Signed-off-by: KIRA-L001 <137947115+KIRA-L001@users.noreply.github.com>
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.

sdk: writeFiles double-encodes strings through TextEncoder + Buffer.from

1 participant