From f7aa6f15d37d5793af4f0daaec0fc71d2b39d4e2 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 7 Oct 2019 12:24:06 +0200 Subject: [PATCH] src/api2/reader.rs: use tokio::fs::read() to read file async --- src/api2/reader.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/api2/reader.rs b/src/api2/reader.rs index 0f721d97..e93518fd 100644 --- a/src/api2/reader.rs +++ b/src/api2/reader.rs @@ -227,20 +227,25 @@ fn download_chunk( let digest = proxmox::tools::hex_to_digest(digest_str)?; let (path, _) = env.datastore.chunk_path(&digest); + let path2 = path.clone(); env.debug(format!("download chunk {:?}", path)); - let data = proxmox::tools::fs::file_get_contents(&path)?; // todo: blocking() - let body = Body::from(data); + let response_future = tokio::fs::read(path) + .map_err(move |err| http_err!(BAD_REQUEST, format!("redingfile {:?} failed: {}", path2, err))) + .and_then(move |data| { + let body = Body::from(data); - // fixme: set other headers ? - Ok(Box::new(futures::future::ok( - Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, "application/octet-stream") - .body(body) - .unwrap()) - )) + // fixme: set other headers ? + futures::future::ok( + Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "application/octet-stream") + .body(body) + .unwrap()) + }); + + Ok(Box::new(response_future)) } /* this is too slow