我正在try 将用reqwest下载的文件复制到Tokio文件中.此文件太大,无法存储在内存中,因此它需要存储到bytes_stream()
,而不是bytes()
我曾try 过以下几种方法
let mut tmp_file = tokio::fs::File::from(tempfile::tempfile()?);
let byte_stream = reqwest::get(&link).await?.bytes_stream();
tokio::io::copy(&mut byte_stream, &mut tmp_file).await?;
此操作失败的原因是
|
153 | tokio::io::copy(&mut byte_stream, &mut tmp_file).await?;
| --------------- ^^^^^^^^^^^^^^^^ the trait `tokio::io::AsyncRead` is not implemented for `impl Stream<Item = Result<bytes::bytes::Bytes, reqwest::Error>>`
| |
| required by a bound introduced by this call
有没有办法让特征AsyncRead on the Stream或者以其他方式将该数据复制到文件中?我之所以使用Tokio文件,是因为我稍后需要从它进行AsyncRead.也许将其复制到常规的std::文件,然后将其转换为Tokio::FS::文件是有意义的?