mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
feat(api): add support to ArrayBuffer (#4579)
This commit is contained in:
committed by
GitHub
parent
b02fc90f45
commit
92aca55a6f
5
.changes/api-support-array-buffer.md
Normal file
5
.changes/api-support-array-buffer.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Add support to `ArrayBuffer` in `Body.bytes` and `writeBinaryFile`.
|
||||
File diff suppressed because one or more lines are too long
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user