mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +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.
|
/// 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user