file download: avoid unnecessary copy

This commit is contained in:
Dietmar Maurer 2019-06-28 07:07:52 +02:00
parent 984a7c3502
commit fcfb84fedf
3 changed files with 4 additions and 12 deletions

View File

@ -424,10 +424,7 @@ fn download_file(
.map_err(|err| http_err!(BAD_REQUEST, format!("File open failed: {}", err)))
.and_then(move |file| {
let payload = tokio::codec::FramedRead::new(file, tokio::codec::BytesCodec::new()).
map(|bytes| {
//sigh - howto avoid copy here? or the whole map() ??
hyper::Chunk::from(bytes.to_vec())
});
map(|bytes| hyper::Chunk::from(bytes.freeze()));
let body = Body::wrap_stream(payload);
// fixme: set other headers ?

View File

@ -175,10 +175,8 @@ fn download_file(
.and_then(move |file| {
env2.log(format!("download {:?}", path3));
let payload = tokio::codec::FramedRead::new(file, tokio::codec::BytesCodec::new()).
map(|bytes| {
//sigh - howto avoid copy here? or the whole map() ??
hyper::Chunk::from(bytes.to_vec())
});
map(|bytes| hyper::Chunk::from(bytes.freeze()));
let body = Body::wrap_stream(payload);
// fixme: set other headers ?

View File

@ -420,10 +420,7 @@ fn chuncked_static_file_download(filename: PathBuf) -> BoxFut {
.map_err(|err| http_err!(BAD_REQUEST, format!("File open failed: {}", err)))
.and_then(move |file| {
let payload = tokio::codec::FramedRead::new(file, tokio::codec::BytesCodec::new()).
map(|bytes| {
//sigh - howto avoid copy here? or the whole map() ??
hyper::Chunk::from(bytes.to_vec())
});
map(|bytes| hyper::Chunk::from(bytes.freeze()));
let body = Body::wrap_stream(payload);
// fixme: set other headers ?