Xuanwo commented on code in PR #4482:
URL: https://github.com/apache/opendal/pull/4482#discussion_r1563630611
##########
core/src/types/writer.rs:
##########
@@ -90,14 +91,22 @@ impl Writer {
Ok(Writer { inner: w })
}
- /// Write into inner writer.
- pub async fn write(&mut self, bs: impl Into<Bytes>) -> Result<()> {
- let mut bs = bs.into();
+ pub async fn write(&mut self, bs: Buffer) -> Result<()> {
+ let mut bs = bs;
while !bs.is_empty() {
- let n = self.inner.write(bs.clone().into()).await?;
+ let n = self.inner.write_dyn(bs.clone()).await?;
bs.advance(n);
}
+ Ok(())
+ }
+ pub async fn write_from(&mut self, bs: &mut impl Buf) -> Result<()> {
+ while bs.has_remaining() {
+ let chunk_ref: &[u8] = bs.chunk();
+ let static_ref: &'static [u8] = unsafe { mem::transmute(chunk_ref)
};
+ let n = self.inner.write_dyn(static_ref.into()).await?;
Review Comment:
We can call `bs.copy_to_bytes()` and build `Buffer` from that.
--
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]