Skip to content

Commit fc90c3d

Browse files
committed
Make get_lines_from_stream work for unix newlines
1 parent 46d98f0 commit fc90c3d

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/ftp.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,29 @@ impl FtpStream {
445445
}
446446

447447
/// 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>>
449449
where
450450
R: AsyncBufRead + Unpin,
451451
{
452452
let mut lines: Vec<String> = Vec::new();
453-
let mut line = String::new();
453+
454+
let mut lines_stream = data_stream.lines();
454455
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+
}
464470
}
465-
Ok(lines)
466471
}
467472

468473
/// Execute `LIST` command which returns the detailed file listing in human readable format.

0 commit comments

Comments
 (0)