Skip to content

Commit fbe76a9

Browse files
authored
fix: serialize Uint8Array and ArrayBuffer as number[], closes #10336 (#10797)
1 parent 83ed090 commit fbe76a9

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

.changes/serialize-array-buffer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch:bug
3+
"@tauri-apps/api": patch:bug
4+
---
5+
6+
Uint8Arrays and ArrayBuffers are now properly serialized as an array of numbers.

core/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/scripts/process-ipc-message-fn.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
let o = {}
2121
val.forEach((v, k) => (o[k] = v))
2222
return o
23-
} else if (
23+
} else if (val instanceof Uint8Array) {
24+
return Array.from(val)
25+
} else if (val instanceof ArrayBuffer) {
26+
return Array.from(new Uint8Array(val))
27+
} else if (
2428
val instanceof Object &&
2529
'__TAURI_CHANNEL_MARKER__' in val &&
2630
typeof val.id === 'number'

tooling/api/src/image.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,9 @@ export function transformImage<T>(
102102
? null
103103
: typeof image === 'string'
104104
? image
105-
: image instanceof Uint8Array
106-
? Array.from(image)
107-
: image instanceof ArrayBuffer
108-
? Array.from(new Uint8Array(image))
109-
: image instanceof Image
110-
? image.rid
111-
: image
105+
: image instanceof Image
106+
? image.rid
107+
: image
112108

113109
return ret as T
114110
}

0 commit comments

Comments
 (0)