File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
crates/core/tedge_agent/src/http_server Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ use tokio::io;
2626use tokio:: io:: AsyncBufReadExt ;
2727use tokio:: io:: AsyncWriteExt ;
2828use tokio:: io:: BufReader ;
29+ use tokio:: io:: BufWriter ;
2930use tokio_util:: io:: ReaderStream ;
3031
3132pub ( crate ) fn file_transfer_router ( file_transfer_dir : Utf8PathBuf ) -> Router {
@@ -128,17 +129,23 @@ async fn stream_request_body_to_path(
128129 path : & Utf8Path ,
129130 body_stream : & mut Body ,
130131) -> anyhow:: Result < ( ) > {
131- let mut buffer = File :: create ( path)
132- . await
133- . with_context ( || format ! ( "creating {path:?}" ) ) ?;
132+ let mut buffer = BufWriter :: new (
133+ File :: create ( path)
134+ . await
135+ . with_context ( || format ! ( "creating {path:?}" ) ) ?,
136+ ) ;
134137 while let Some ( data) = body_stream. next ( ) . await {
135138 let data =
136139 data. with_context ( || format ! ( "reading body of uploaded file (destined for {path:?})" ) ) ?;
137- let _bytes_written = buffer
138- . write ( & data)
140+ buffer
141+ . write_all ( & data)
139142 . await
140143 . with_context ( || format ! ( "writing to {path:?}" ) ) ?;
141144 }
145+ buffer
146+ . flush ( )
147+ . await
148+ . with_context ( || format ! ( "writing to {path:?}" ) ) ?;
142149 Ok ( ( ) )
143150}
144151
You can’t perform that action at this time.
0 commit comments