Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add support to ArrayBuffer #4579

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/api-support-array-buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

Add support to `ArrayBuffer` in `Body.bytes` and `writeBinaryFile`.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions tooling/api/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
})
Expand Down
9 changes: 7 additions & 2 deletions tooling/api/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}

Expand Down