meilisearch/meilisearch-rust

Streaming in wasm doesn’t work

irevoire opened this issue · 0 comments

Currently, when streaming documents in wasm, we actually collect everything in RAM before sending it:

// TODO: Currently reqwest doesn't support streaming data in wasm so we need to collect everything in RAM
#[cfg(not(target_arch = "wasm32"))]
{
let stream = ReaderStream::new(body);
let body = reqwest::Body::wrap_stream(stream);
request = request
.header(header::CONTENT_TYPE, content_type)
.body(body);
}
#[cfg(target_arch = "wasm32")]
{
use futures::{pin_mut, AsyncReadExt};
let mut buf = Vec::new();
pin_mut!(body);
body.read_to_end(&mut buf)
.await
.map_err(|err| Error::Other(Box::new(err)))?;
request = request.header(header::CONTENT_TYPE, content_type).body(buf);
}

This is because reqwest doesn’t provide the wrap_stream method, see: seanmonstar/reqwest#2248