WIP create a handler to download a file chunk by chunk.

This commit is contained in:
Florian THIERRY
2026-07-14 00:13:47 +02:00
parent 850dbca6cf
commit c24df944c5
14 changed files with 413 additions and 83 deletions
+17
View File
@@ -0,0 +1,17 @@
use actix_web::{get, HttpResponse};
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};
use futures_util::stream::StreamExt;
#[get("/download")]
pub async fn download_file() -> HttpResponse {
HttpResponse::Ok()
.content_type("application/octet-stream")
.streaming(async_stream::stream! {
let file = File::open("/home/florian/Video/2019-06-02 17-09-30.flv").await.expect("Failed to open file");
let mut stream = FramedRead::new(file, BytesCodec::new());
while let Some(chunk) = stream.next().await {
yield chunk.map(|bytes| bytes.freeze());
}
})
}