Cannot get JS -> Rust -> JS `WritableStream` to work on all browsers
My app https://rage-encry.pt/ has two workflows:
1. Encryption
- Get `ReadableStream` for file to encrypt.
- Create output `WritableStream` using StreamSaver.js (`outputStream`).
- Pass `outputStream` to Rust, where we:
- `wasm_streams::writable::WritableStream::from_raw(output).into_async_write()`
- Use that to set up an encryptor object.
- Return `WritableStream::from_sink(shim::WriteSinker::new(encryptor)).into_raw()` to JS.
- `shim::WriteSinker` is my own type to make up for missing `WritableStream::from_async_write` (I previously had a `SinkWriter` as well before `WritableStream::into_async_write` was added).
- Pipe the `ReadableStream` from the file to encrypt into the `WritableStream` returned from Rust.
2. Decryption
- Get `File` for file to decrypt (`encryptedFile`).
- Create output `WritableStream` using StreamSaver.js (`outputStream`).
- Pass `encryptedFile` to Rust, where we:
- `wasm_streams::readable::ReadableStream::from_raw(file.stream().unchecked_into()).into_async_read()`
- Use that to set up a decryptor object, and start decryption.
- Return `ReadableStream::from_async_read(decryptor, CHUNK_SIZE).into_raw()` to JS.
- Pipe the `ReadableStream` returned from Rust into `outputStream`.
Back in March 2021 (using `wasm-streams 0.1`), the decryption workflow worked on all browsers I tested with (Firefox and Chrome on Windows), and encryption worked with Firefox on Windows, but encryption with Chrome failed with the error:
```
Failed to execute 'pipeTo' on 'ReadableStream': parameter 1 is not of type 'WritableStream'.
```
I just updated the app, and it is now using `wasm-streams 0.3`. I now observe the same behaviour in Firefox on macOS Ventura 13.0.1 (decryption works, encryption fails as above):
```
Uncaught (in promise) TypeError: ReadableStream.pipeTo: Argument 1 does not implement interface WritableStream.
```
To be clear, argument 1 in both of these cases is the JavaScript variable corresponding to the Rust value `WritableStream::from_sink(shim::WriteSinker::new(encryptor)).into_raw()`.
Full tracebacks for these are in https://github.com/str4d/wage/issues/29. I originally figured it was a side-effect of the in-progress implementations, but now that Firefox has apparently regressed, I'm opening this issue here.
关闭于 2023-10-31 1 条评论