Skip to content

Commit

Permalink
fix: serialize Uint8Array and ArrayBuffer as number[], closes #10336 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 27, 2024
1 parent 83ed090 commit fbe76a9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/serialize-array-buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": patch:bug
"@tauri-apps/api": patch:bug
---

Uint8Arrays and ArrayBuffers are now properly serialized as an array of numbers.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion core/tauri/scripts/process-ipc-message-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
let o = {}
val.forEach((v, k) => (o[k] = v))
return o
} else if (
} else if (val instanceof Uint8Array) {
return Array.from(val)
} else if (val instanceof ArrayBuffer) {
return Array.from(new Uint8Array(val))
} else if (
val instanceof Object &&
'__TAURI_CHANNEL_MARKER__' in val &&
typeof val.id === 'number'
Expand Down
10 changes: 3 additions & 7 deletions tooling/api/src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ export function transformImage<T>(
? null
: typeof image === 'string'
? image
: image instanceof Uint8Array
? Array.from(image)
: image instanceof ArrayBuffer
? Array.from(new Uint8Array(image))
: image instanceof Image
? image.rid
: image
: image instanceof Image
? image.rid
: image

return ret as T
}

0 comments on commit fbe76a9

Please sign in to comment.