mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
chore: Cleaning up the stream to a regular stream (#2468)
This commit is contained in:
@@ -892,22 +892,13 @@ async fn buf_reader_to_lines(
|
|||||||
reader: impl AsyncBufRead + Unpin,
|
reader: impl AsyncBufRead + Unpin,
|
||||||
limit: impl Into<Option<usize>>,
|
limit: impl Into<Option<usize>>,
|
||||||
) -> Result<Vec<String>, Error> {
|
) -> Result<Vec<String>, Error> {
|
||||||
let lines = stream! {
|
let mut lines = reader.lines();
|
||||||
let mut lines = reader.lines();
|
let mut output = RingVec::new(limit.into().unwrap_or(1000));
|
||||||
while let Some(line) = lines.next_line().await? {
|
while let Ok(line) = lines.next_line().await {
|
||||||
yield Ok::<_, Report>(line);
|
if let Some(line) = line {
|
||||||
|
output.push(line);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
let output: RingVec<String> = lines
|
|
||||||
.try_fold(
|
|
||||||
RingVec::new(limit.into().unwrap_or(1000)),
|
|
||||||
|mut acc, line| async move {
|
|
||||||
acc.push(line);
|
|
||||||
Ok(acc)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.with_kind(crate::ErrorKind::Unknown)?;
|
|
||||||
let output: Vec<String> = output.value.into_iter().collect();
|
let output: Vec<String> = output.value.into_iter().collect();
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user