]> git.proxmox.com Git - proxmox-backup.git/commitdiff
file download: avoid unnecessary copy
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Jun 2019 05:07:52 +0000 (07:07 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Jun 2019 05:07:52 +0000 (07:07 +0200)
src/api2/admin/datastore.rs
src/api2/reader.rs
src/server/rest.rs

index 9dd82f1595a6373faee5012adb31de55f5a63b45..6bc63afee88bbd32430490ac8ddfba8a268ea3d5 100644 (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 ?
index f4f78d60c320a6498676dbdf37bc437378f873ac..48045abfb0d0053ea334354ae523b5eef9717125 100644 (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 ?
index 445af4de9b016ab7fb19f33079155c3802aa7146..59237920745abf1ceda177139472a9c101bf43d8 100644 (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 ?