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

Expose a Rust stream to JavaScript as a user-downloadable file #1

Closed
str4d opened this issue May 17, 2020 · 1 comment
Closed

Expose a Rust stream to JavaScript as a user-downloadable file #1

str4d opened this issue May 17, 2020 · 1 comment

Comments

@str4d
Copy link
Owner

str4d commented May 17, 2020

The wage::decryptor_for_file API takes a JavaScript File and returns a handle to an age::Decryptor that wraps File.stream(). It would be great if there were a way to similarly expose age::stream::StreamReader as a JavaScript ReadableStream that could be passed back out to the browser, giving it the option to stream-process the decrypted file instead of having the entire decrypted file read into memory.

One issue here is that the Rust handle stores a lifetime, and wasm-bindgen doesn't currently support returning objects with lifetimes (rustwasm/wasm-bindgen#1187). So we may need to hack around that with unsafe, or alternatively have an API that takes a JavaScript TransformStream and writes the decrypted file to it (which would make for a somewhat wonky JavaScript API, but should still enable building JS pipelines).

@str4d
Copy link
Owner Author

str4d commented May 17, 2020

It turns out that wasm-streams can convert a Box<dyn Stream<Item = Result<JsValue, JsValue>>> into a ReadableStream (source).

@str4d str4d closed this as completed in d1109cf May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant