From fcfb84fedfdbbf9ed35fe1d5529213d04d060c26 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 28 Jun 2019 07:07:52 +0200 Subject: [PATCH] file download: avoid unnecessary copy --- src/api2/admin/datastore.rs | 5 +---- src/api2/reader.rs | 6 ++---- src/server/rest.rs | 5 +---- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 9dd82f15..6bc63afe 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -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 ? diff --git a/src/api2/reader.rs b/src/api2/reader.rs index f4f78d60..48045abf 100644 --- a/src/api2/reader.rs +++ b/src/api2/reader.rs @@ -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 ? diff --git a/src/server/rest.rs b/src/server/rest.rs index 445af4de..59237920 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -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 ? -- 2.39.2