Bytestream touchup (#12886)

# Description
Adds some docs and a small fix to `Chunks`.
This commit is contained in:
Ian Manske 2024-05-16 21:15:20 +00:00 committed by GitHub
parent 1c00a6ca5e
commit 2a09dccc11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;