Struct edjx::stream::ReadStream
source · pub struct ReadStream { /* private fields */ }
Expand description
ReadStream is used to receive streamed data.
Implementations§
source§impl ReadStream
impl ReadStream
sourcepub fn read_chunk(&mut self) -> Option<Result<Vec<u8>, StreamError>>
pub fn read_chunk(&mut self) -> Option<Result<Vec<u8>, StreamError>>
Reads a chunk of binary data from the stream.
Examples found in repository?
src/stream.rs (line 161)
158 159 160 161 162 163 164 165 166 167 168 169 170 171
pub fn read_all(&mut self) -> Result<Vec<u8>, StreamError> {
let mut all_bytes = Vec::new();
while let Some(bytes_res) = self.read_chunk() {
match bytes_res {
Ok(mut bytes) => all_bytes.append(&mut bytes),
Err(err) => {
return Err(err);
}
}
}
return Ok(all_bytes);
}
sourcepub fn pipe_to(&mut self, ws: &mut WriteStream) -> Result<(), StreamError>
pub fn pipe_to(&mut self, ws: &mut WriteStream) -> Result<(), StreamError>
Pipes a read stream into a write stream. After all data is transmitted, both streams are closed.
sourcepub fn read_all(&mut self) -> Result<Vec<u8>, StreamError>
pub fn read_all(&mut self) -> Result<Vec<u8>, StreamError>
Reads and returns all data from the stream until the end of stream.
This method does not close the stream.
Examples found in repository?
src/fetch_response.rs (line 51)
50 51 52 53 54 55 56 57 58 59 60 61 62 63
pub fn read_body(&mut self) -> Result<Vec<u8>, StreamError> {
let result = self.read_stream.read_all();
let closed = self.read_stream.close();
if result.is_err() {
return result;
}
if closed.is_err() {
return Err(closed.err().unwrap());
}
return result;
}
More examples
src/storage_response.rs (line 67)
66 67 68 69 70 71 72 73 74 75 76 77 78 79
pub fn read_body(&mut self) -> Result<Vec<u8>, StreamError> {
let result = self.read_stream.read_all();
let closed = self.read_stream.close();
if result.is_err() {
return result;
}
if closed.is_err() {
return Err(closed.err().unwrap());
}
return result;
}