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

writeBinaryFile **DOES NOT WORK** even though correct USAGE! [2021 ISSUE] #1133

Closed
copyandexecute opened this issue Jan 4, 2021 · 2 comments · Fixed by #1136
Closed

writeBinaryFile **DOES NOT WORK** even though correct USAGE! [2021 ISSUE] #1133

copyandexecute opened this issue Jan 4, 2021 · 2 comments · Fixed by #1136

Comments

@copyandexecute
Copy link

Dear Tauri Team,
I am trying to download a jar file and then save it with your provided funcation "writeBinaryFile". Unfortunately it does not work.

await axios({
         url: '/downloads/client/latest.jar',
         method: "GET",
         responseType: "blob", // important
         onDownloadProgress: (progressEvent) => {
           setProgress(Math.round((progressEvent.loaded * 100) / progressEvent.total));
         }
       }).then(async value => {
         const mcDir = await promisified({cmd: "minecraftDir"});
         console.log(mcDir)
         console.log(value)
         console.log(value.data)
         await writeBinaryFile({contents: value.data, path: mcDir + "/norisk/test.jar"}, {});
       })

It creates an EMPTY + CORRUPTED File.
Whats the correct use?

Your sincerely,
Max

@zakpatterson
Copy link
Contributor

zakpatterson commented Jan 5, 2021

The issue is basically that writeBinaryFile in the JS api does not call WriteBinaryFile in the rust API, but instead calls WriteFile in the Rust API with the file contents base64 encoded. So you may find, that your jar file that is saved in your filesystem is fine, it just needs to be base64 decoded, as base64 -d corrupted_file > good_file.

I am working on a fix now.

zakpatterson added a commit to zakpatterson/tauri that referenced this issue Jan 5, 2021
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.
zakpatterson added a commit to zakpatterson/tauri that referenced this issue Jan 6, 2021
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.
nothingismagick pushed a commit that referenced this issue Jan 6, 2021
* Fix writeBinaryFile to call the correct command

Fixes #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.

* Shorten changelog line per review
@zakpatterson
Copy link
Contributor

@copyandexecute You might try pulling down the dev branch and making sure your issue is resolved? Otherwise I think a new release is coming out soon with this fix. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants