fix: serialize Uint8Array and ArrayBuffer as number[], closes #10336 (#10797)

This commit is contained in:
Lucas Fernandes Nogueira 2024-08-27 12:49:18 -03:00 committed by GitHub
parent 83ed090bfa
commit fbe76a955a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 9 deletions

View File

@ -0,0 +1,6 @@
---
"tauri": patch:bug
"@tauri-apps/api": patch:bug
---
Uint8Arrays and ArrayBuffers are now properly serialized as an array of numbers.

File diff suppressed because one or more lines are too long

View File

@ -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'

View File

@ -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
}