Browse Source

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

Lucas Fernandes Nogueira 11 months ago
parent
commit
fbe76a955a

+ 6 - 0
.changes/serialize-array-buffer.md

@@ -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 it is too large
+ 0 - 0
core/tauri/scripts/bundle.global.js


+ 5 - 1
core/tauri/scripts/process-ipc-message-fn.js

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

+ 3 - 7
tooling/api/src/image.ts

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

Some files were not shown because too many files changed in this diff