mithril_client/utils/
stream_reader.rs1use flume::Receiver;
2use std::io;
3
4pub struct StreamReader {
8 receiver: Receiver<Vec<u8>>,
9 current: io::Cursor<Vec<u8>>,
10}
11
12impl StreamReader {
13 pub fn new(receiver: Receiver<Vec<u8>>) -> Self {
15 Self {
16 receiver,
17 current: io::Cursor::new(vec![]),
18 }
19 }
20}
21
22impl io::Read for StreamReader {
23 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
24 if self.current.position() == self.current.get_ref().len() as u64 {
25 if let Ok(vec) = self.receiver.recv() {
27 self.current = io::Cursor::new(vec);
28 }
29 }
33 self.current.read(buf)
34 }
35}