mirror of
https://github.com/nushell/nushell.git
synced 2024-12-26 00:50:03 +01:00
Bytestream
touchup (#12886)
# Description Adds some docs and a small fix to `Chunks`.
This commit is contained in:
parent
1c00a6ca5e
commit
2a09dccc11
@ -59,6 +59,13 @@ impl Read for SourceReader {
|
||||
|
||||
/// A potentially infinite, interruptible stream of bytes.
|
||||
///
|
||||
/// To create a [`ByteStream`], you can use any of the following methods:
|
||||
/// - [`read`](ByteStream::read): takes any type that implements [`Read`].
|
||||
/// - [`file`](ByteStream::file): takes a [`File`].
|
||||
/// - [`from_iter`](ByteStream::from_iter): takes an [`Iterator`] whose items implement `AsRef<[u8]>`.
|
||||
/// - [`from_result_iter`](ByteStream::from_result_iter): same as [`from_iter`](ByteStream::from_iter),
|
||||
/// but each item is a `Result<T, ShellError>`.
|
||||
///
|
||||
/// The data of a [`ByteStream`] can be accessed using one of the following methods:
|
||||
/// - [`reader`](ByteStream::reader): returns a [`Read`]-able type to get the raw bytes in the stream.
|
||||
/// - [`lines`](ByteStream::lines): splits the bytes on lines and returns an [`Iterator`]
|
||||
@ -626,14 +633,18 @@ impl Iterator for Chunks {
|
||||
if nu_utils::ctrl_c::was_pressed(&self.ctrlc) {
|
||||
None
|
||||
} else {
|
||||
match self.reader.fill_buf() {
|
||||
Ok(buf) => {
|
||||
self.leftover.extend_from_slice(buf);
|
||||
let len = buf.len();
|
||||
self.reader.consume(len);
|
||||
}
|
||||
Err(err) => return Some(Err(err.into_spanned(self.span).into())),
|
||||
};
|
||||
loop {
|
||||
match self.reader.fill_buf() {
|
||||
Ok(buf) => {
|
||||
self.leftover.extend_from_slice(buf);
|
||||
let len = buf.len();
|
||||
self.reader.consume(len);
|
||||
break;
|
||||
}
|
||||
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
|
||||
Err(err) => return Some(Err(err.into_spanned(self.span).into())),
|
||||
};
|
||||
}
|
||||
|
||||
if self.leftover.is_empty() {
|
||||
return None;
|
||||
|
Loading…
Reference in New Issue
Block a user