@@ -290,19 +290,12 @@ where
290290 add_pending ( PendingUpload :: new ( bucket, key, & upload_id) ) ;
291291
292292 let completed_parts = {
293- let mut parts: Vec < _ > = upload_request_stream (
294- s3,
295- bucket,
296- key,
297- & upload_id,
298- reader,
299- file_size,
300- Config :: global ( ) . upload_part_size ( ) ,
301- )
302- . await
303- . buffer_unordered ( Config :: global ( ) . concurrent_upload_tasks ( ) )
304- . try_collect ( )
305- . await ?;
293+ let mut parts: Vec < _ > =
294+ upload_request_stream ( s3, bucket, key, & upload_id, reader, file_size)
295+ . await
296+ . buffer_unordered ( Config :: global ( ) . concurrent_upload_tasks ( ) )
297+ . try_collect ( )
298+ . await ?;
306299 parts. sort_unstable_by_key ( |a| a. part_number ) ;
307300 parts
308301 } ;
@@ -323,19 +316,14 @@ where
323316 R : AsyncRead + AsyncSeek + Send + Unpin + ' static ,
324317{
325318 let chunk_size = Config :: global ( ) . upload_part_size ( ) ;
326-
327319 let seek = chunk_size * chunk_number;
328320 let read_size = u64:: min ( file_size - seek, chunk_size) ;
329-
330- let mut guard = reader. lock ( ) . await ;
331- guard. seek ( SeekFrom :: Start ( seek) ) . await ?;
332-
333321 let mut buf = BytesMut :: with_capacity ( read_size as usize ) ;
334322 buf. resize ( read_size as usize , 0 ) ;
335-
323+ let mut guard = reader. lock ( ) . await ;
324+ guard. seek ( SeekFrom :: Start ( seek) ) . await ?;
336325 let slice = buf. as_mut ( ) ;
337326 guard. read_exact ( & mut slice[ ..read_size as usize ] ) . await ?;
338-
339327 Ok ( ByteStream :: from ( buf. freeze ( ) ) )
340328}
341329
@@ -346,11 +334,11 @@ async fn upload_request_stream<'a, R>(
346334 upload_id : & ' a str ,
347335 reader : R ,
348336 file_size : u64 ,
349- part_size : u64 ,
350337) -> impl Stream < Item = impl Future < Output = Result < CompletedPart > > + ' a > + ' a
351338where
352339 R : AsyncRead + AsyncSeek + Unpin + Send + ' static ,
353340{
341+ let part_size = Config :: global ( ) . upload_part_size ( ) ;
354342 let last_part = {
355343 let remaining = file_size % part_size;
356344 if remaining > 0 {
0 commit comments