Skip to content

Instantly share code, notes, and snippets.

@jsmits
Forked from nuclearglow/convert-arraybuffer.js
Created November 8, 2021 08:18
Show Gist options
  • Save jsmits/fe67af22f0e472ea9aed647e49eeb4dc to your computer and use it in GitHub Desktop.
Save jsmits/fe67af22f0e472ea9aed647e49eeb4dc to your computer and use it in GitHub Desktop.
ArrayBuffer <-> JSON <-> ArrayBuffer
// array buffer to JSON
const dataString JSON.stringify(Array.from(new Uint8Array(arrayBuffer)));
// send around
// JSON to ArrayBuffer
new Uint8Array(JSON.parse(dataString)).buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment