Browse Source

feat(api): add support to ArrayBuffer (#4579)

Lucas Fernandes Nogueira 3 năm trước cách đây
mục cha
commit
92aca55a6f

+ 5 - 0
.changes/api-support-array-buffer.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Add support to `ArrayBuffer` in `Body.bytes` and `writeBinaryFile`.

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
core/tauri/scripts/bundle.js


+ 6 - 2
tooling/api/src/fs.ts

@@ -112,7 +112,7 @@ interface FsTextFileOption {
   contents: string
 }
 
-type BinaryFileContents = Iterable<number> | ArrayLike<number>
+type BinaryFileContents = Iterable<number> | ArrayLike<number> | ArrayBuffer
 
 /** Options object used to write a binary data to a file. */
 interface FsBinaryFileOption {
@@ -352,7 +352,11 @@ async function writeBinaryFile(
     message: {
       cmd: 'writeFile',
       path: file.path,
-      contents: Array.from(file.contents),
+      contents: Array.from(
+        file.contents instanceof ArrayBuffer
+          ? new Uint8Array(file.contents)
+          : file.contents
+      ),
       options: fileOptions
     }
   })

+ 7 - 2
tooling/api/src/http.ts

@@ -173,9 +173,14 @@ class Body {
    *
    * @return The body object ready to be used on the POST and PUT requests.
    */
-  static bytes(bytes: Iterable<number> | ArrayLike<number>): Body {
+  static bytes(
+    bytes: Iterable<number> | ArrayLike<number> | ArrayBuffer
+  ): Body {
     // stringifying Uint8Array doesn't return an array of numbers, so we create one here
-    return new Body('Bytes', Array.from(bytes))
+    return new Body(
+      'Bytes',
+      Array.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes)
+    )
   }
 }
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác