File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -445,24 +445,29 @@ impl FtpStream {
445
445
}
446
446
447
447
/// Consume a stream and return a vector of lines
448
- async fn get_lines_from_stream < R > ( mut data_stream : R ) -> Result < Vec < String > >
448
+ async fn get_lines_from_stream < R > ( data_stream : R ) -> Result < Vec < String > >
449
449
where
450
450
R : AsyncBufRead + Unpin ,
451
451
{
452
452
let mut lines: Vec < String > = Vec :: new ( ) ;
453
- let mut line = String :: new ( ) ;
453
+
454
+ let mut lines_stream = data_stream. lines ( ) ;
454
455
loop {
455
- match data_stream. read_to_string ( & mut line) . await {
456
- Ok ( 0 ) => break ,
457
- Ok ( _) => lines. extend (
458
- line. split ( "\r \n " )
459
- . map ( String :: from)
460
- . filter ( |s| !s. is_empty ( ) ) ,
461
- ) ,
462
- Err ( err) => return Err ( FtpError :: ConnectionError ( err) ) ,
463
- } ;
456
+ let line = lines_stream
457
+ . next_line ( )
458
+ . await
459
+ . map_err ( FtpError :: ConnectionError ) ?;
460
+
461
+ match line {
462
+ Some ( line) => {
463
+ if line. is_empty ( ) {
464
+ continue ;
465
+ }
466
+ lines. push ( line) ;
467
+ }
468
+ None => break Ok ( lines) ,
469
+ }
464
470
}
465
- Ok ( lines)
466
471
}
467
472
468
473
/// Execute `LIST` command which returns the detailed file listing in human readable format.
You can’t perform that action at this time.
0 commit comments