src/api2/reader.rs: use tokio::fs::read() to read file async
This commit is contained in:
parent
7123ff7d43
commit
f7aa6f15d3
@ -227,20 +227,25 @@ fn download_chunk(
|
|||||||
let digest = proxmox::tools::hex_to_digest(digest_str)?;
|
let digest = proxmox::tools::hex_to_digest(digest_str)?;
|
||||||
|
|
||||||
let (path, _) = env.datastore.chunk_path(&digest);
|
let (path, _) = env.datastore.chunk_path(&digest);
|
||||||
|
let path2 = path.clone();
|
||||||
|
|
||||||
env.debug(format!("download chunk {:?}", path));
|
env.debug(format!("download chunk {:?}", path));
|
||||||
|
|
||||||
let data = proxmox::tools::fs::file_get_contents(&path)?; // todo: blocking()
|
let response_future = tokio::fs::read(path)
|
||||||
let body = Body::from(data);
|
.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 ?
|
// fixme: set other headers ?
|
||||||
Ok(Box::new(futures::future::ok(
|
futures::future::ok(
|
||||||
Response::builder()
|
Response::builder()
|
||||||
.status(StatusCode::OK)
|
.status(StatusCode::OK)
|
||||||
.header(header::CONTENT_TYPE, "application/octet-stream")
|
.header(header::CONTENT_TYPE, "application/octet-stream")
|
||||||
.body(body)
|
.body(body)
|
||||||
.unwrap())
|
.unwrap())
|
||||||
))
|
});
|
||||||
|
|
||||||
|
Ok(Box::new(response_future))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is too slow
|
/* this is too slow
|
||||||
|
Loading…
Reference in New Issue
Block a user