amunra commented on issue #7003:
URL: https://github.com/apache/opendal/issues/7003#issuecomment-3657760643

   I'm not sure I'll be able to find cycles for an actual fix any time soon.
   That said, this seems to work in our code base now:
   
   ```rust
   pub struct AsyncReader {
       stream: opendal::BufferStream,
       current: opendal::Buffer,
       eof: bool,
   }
   
   impl AsyncReader {
       pub fn new(stream: opendal::BufferStream) -> Self {
           Self {
               stream,
               current: opendal::Buffer::new(),
               eof: false,
           }
       }
   }
   
   impl AsyncRead for AsyncReader {
       fn poll_read(
           mut self: Pin<&mut Self>,
           cx: &mut std::task::Context<'_>,
           buf: &mut [u8],
       ) -> Poll<io::Result<usize>> {
           if self.eof {
               return Poll::Ready(Ok(0));
           }
           loop {
               match Read::read(&mut self.current, buf) {
                   Ok(read) if read > 0 => return Poll::Ready(Ok(read)),
                   Ok(_) => (), // fetch next buffer
                   Err(err) => {
                       self.eof = true;
                       return Poll::Ready(Err(err));
                   }
               };
               let stream = Pin::new(&mut self.stream);
               match futures::stream::Stream::poll_next(stream, cx) {
                   Poll::Ready(Some(Ok(buf))) => {
                       self.current = buf;
                   }
                   Poll::Ready(Some(Err(err))) => {
                       self.eof = true;
                       let io_err: io::Error = err.into();
                       return Poll::Ready(Err(io_err));
                   }
                   Poll::Ready(None) => {
                       self.eof = true;
                       return Poll::Ready(Ok(0));
                   }
                   Poll::Pending => return Poll::Pending,
               }
           }
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to