Skip to content

fix: support deserializing Node.js Buffer typed arrays - #365

Open
feritcemkahraman wants to merge 1 commit into
ravionhq:mainfrom
feritcemkahraman:fix/deserialize-node-buffer
Open

feritcemkahraman wants to merge 1 commit into
ravionhq:mainfrom
feritcemkahraman:fix/deserialize-node-buffer

Conversation

@feritcemkahraman

@feritcemkahraman feritcemkahraman commented Oct 23, 2026 •

Copy link
Copy Markdown
  • In merge queue
  • Prioritize

Problem

In Node.js runtimes, Buffer is an instance of Uint8Array (ArrayBuffer.isView(buf) is true), which matches isTypedArray.
When serialized, v.constructor.name evaluates to 'Buffer', resulting in the metadata annotation ['typed-array', 'Buffer'].

However, during deserialization in typedArrayRule.untransform:

const ctor = constructorToName[a[1]];
if (!ctor) {
  throw new Error('Trying to deserialize unknown typed array');
}

constructorToName['Buffer'] is undefined, causing deserialization to throw:
Error: Trying to deserialize unknown typed array

Solution

Support 'Buffer' in typedArrayRule.untransform:

  • If typeof Buffer !== 'undefined', deserialize via Buffer.from(values).
  • Otherwise (such as in browser environments), safely deserialize as new Uint8Array(values).

Verification

  • Added unit test in src/index.test.ts verifying serialization and deserialization of a Node.js Buffer.
  • All 87 unit tests pass (npm test).
  • TypeScript build succeeds cleanly (npm run build).

@greptile-apps

greptile-apps Bot commented Oct 23, 2026

Copy link
Copy Markdown

This PR does not match any of the 1 configured review trigger rule.

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.

1 participant