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. /// 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: /// 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. /// - [`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`] /// - [`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) { if nu_utils::ctrl_c::was_pressed(&self.ctrlc) {
None None
} else { } else {
match self.reader.fill_buf() { loop {
Ok(buf) => { match self.reader.fill_buf() {
self.leftover.extend_from_slice(buf); Ok(buf) => {
let len = buf.len(); self.leftover.extend_from_slice(buf);
self.reader.consume(len); let len = buf.len();
} self.reader.consume(len);
Err(err) => return Some(Err(err.into_spanned(self.span).into())), 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() { if self.leftover.is_empty() {
return None; return None;