Skip to content

Commit

Permalink
Fix writeBinaryFile to call the correct command
Browse files Browse the repository at this point in the history
Fixes tauri-apps#1133

writeBinaryFile was reusing writeFile, which was happily saving
base64 encoded strings to the fs. This instead uses the correct
WriteBinaryFile command, which base64 decodes.

However why are we encoding and then decoding, why can we not just
send a raw byte array to be saved as a file? This is left for a later
PR.
  • Loading branch information
zakpatterson committed Jan 6, 2021
1 parent 5810bae commit 892d18b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .changes/writeBinaryFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"tauri.js": patch
"tauri": minor
---

fix writeBinaryFile in the js api to call the correct function
on the rust side. Before, files were sent in base64 encoding, but
the save-as-text `WriteFile` fs command was reused, without any
indication that the contents were base64 encoded. So the WriteFile
command had no way of checking and decoding when necessary.
WriteBinaryFile on the rust side expects a base64 encoded string, then
decodes it.

2 changes: 1 addition & 1 deletion cli/tauri.js/api-src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function writeBinaryFile(
}

return await promisified({
cmd: 'writeFile',
cmd: 'writeBinaryFile',
path: file.path,
contents: arrayBufferToBase64(file.contents),
options
Expand Down

0 comments on commit 892d18b

Please sign in to comment.