Skip to content

Commit 92aca55

Browse files
authored
feat(api): add support to ArrayBuffer (#4579)
1 parent b02fc90 commit 92aca55

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Add support to `ArrayBuffer` in `Body.bytes` and `writeBinaryFile`.

core/tauri/scripts/bundle.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.

tooling/api/src/fs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ interface FsTextFileOption {
112112
contents: string
113113
}
114114

115-
type BinaryFileContents = Iterable<number> | ArrayLike<number>
115+
type BinaryFileContents = Iterable<number> | ArrayLike<number> | ArrayBuffer
116116

117117
/** Options object used to write a binary data to a file. */
118118
interface FsBinaryFileOption {
@@ -352,7 +352,11 @@ async function writeBinaryFile(
352352
message: {
353353
cmd: 'writeFile',
354354
path: file.path,
355-
contents: Array.from(file.contents),
355+
contents: Array.from(
356+
file.contents instanceof ArrayBuffer
357+
? new Uint8Array(file.contents)
358+
: file.contents
359+
),
356360
options: fileOptions
357361
}
358362
})

tooling/api/src/http.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,14 @@ class Body {
173173
*
174174
* @return The body object ready to be used on the POST and PUT requests.
175175
*/
176-
static bytes(bytes: Iterable<number> | ArrayLike<number>): Body {
176+
static bytes(
177+
bytes: Iterable<number> | ArrayLike<number> | ArrayBuffer
178+
): Body {
177179
// stringifying Uint8Array doesn't return an array of numbers, so we create one here
178-
return new Body('Bytes', Array.from(bytes))
180+
return new Body(
181+
'Bytes',
182+
Array.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes)
183+
)
179184
}
180185
}
181186

0 commit comments

Comments
 (0)