fix(browser): decode binary writes and keep download blobs alive - #72
Open
Aikiooo wants to merge 1 commit into
Open
fix(browser): decode binary writes and keep download blobs alive#72Aikiooo wants to merge 1 commit into
Aikiooo wants to merge 1 commit into
Conversation
The browser file service ignored the third `write` argument — the `isBinary` flag that `file.writeBinary()` sets alongside its base64-encoded payload. The native handlers decode that payload, so ignoring the flag stored the base64 text itself instead of the file's contents and every binary write came out corrupted. `saveToDevice` also revoked the blob url on the next tick. The url is handed to the download manager, or to an external app on Android, after `click()` returns, so the revoke could kill the blob mid-handoff and the download failed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two defects in the browser
fileservice, both in the save/download path.1.
write()ignores theisBinaryflagsrc/bridge/file.tsimplementswriteBinary()by base64-encoding the bytes and passingtrueas the third argument:The native handlers decode that payload, but the browser service accepted the argument and never used it, so it wrote the base64 text into OPFS. Any binary write on the browser platform was stored corrupted.
The browser service now decodes it too, so the third argument means the same thing on every platform.
2.
saveToDevice()revokes the blob url too earlyclick()returns before the browser has handed theblob:url to the download manager, and on Android to an external app. Revoking on the next tick can kill the blob mid-handoff, so the download fails. The revoke is now delayed well past the handoff.Tests
src/platforms/browser/services/file.test.tscovers the base64 decode, the plain-text path, write-error reporting, and that the url outlives the click. The two regression tests fail against the current code and pass with the fix.pnpm typecheckpasses and the suite is green (120 tests).Notes
I left
getContentTypealone — it only maps a handful of extensions, and I did not want to widen the scope of this change. Happy to extend it in a separate PR if you want the common types mapped.