Skip to content

Commit

Permalink
public buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
zjregee committed Apr 14, 2024
1 parent c9f74e6 commit c40ccdf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ mod tests {
#[tokio::test]
async fn test_writer() {
let op = new_test_operator(Capability::default());
let res = op.write("path", vec![]).await;
let res = op.write("path", Vec::<u8>::new()).await;
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);

Expand Down
5 changes: 2 additions & 3 deletions core/src/types/operator/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use std::future::Future;
use std::time::Duration;

use bytes::Bytes;
use futures::stream;
use futures::Stream;
use futures::StreamExt;
Expand Down Expand Up @@ -622,7 +621,7 @@ impl Operator {
/// # Ok(())
/// # }
/// ```
pub async fn write(&self, path: &str, bs: impl Into<Bytes>) -> Result<()> {
pub async fn write(&self, path: &str, bs: impl Into<Buffer>) -> Result<()> {
let bs = bs.into();
self.write_with(path, bs).await
}
Expand Down Expand Up @@ -1111,7 +1110,7 @@ impl Operator {
pub fn write_with(
&self,
path: &str,
bs: impl Into<Bytes>,
bs: impl Into<Buffer>,
) -> FutureWrite<impl Future<Output = Result<()>>> {
let path = normalize_path(path);
let bs = bs.into();
Expand Down
3 changes: 1 addition & 2 deletions core/src/types/operator/operator_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::future::IntoFuture;
use std::ops::RangeBounds;
use std::time::Duration;

use bytes::Bytes;
use flagset::FlagSet;
use futures::Future;

Expand Down Expand Up @@ -243,7 +242,7 @@ impl<F> FutureReader<F> {
/// Future that generated by [`Operator::write_with`].
///
/// Users can add more options by public functions provided by this struct.
pub type FutureWrite<F> = OperatorFuture<(OpWrite, Bytes), F>;
pub type FutureWrite<F> = OperatorFuture<(OpWrite, Buffer), F>;

impl<F> FutureWrite<F> {
/// Set the append mode of op.
Expand Down
14 changes: 6 additions & 8 deletions core/src/types/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,13 @@ mod tests {

let content = gen_random_bytes();
let mut writer = op.writer(path).await.unwrap();
writer.write(content.clone())
writer
.write(content.clone())
.await
.expect("write must succeed");
writer.close().await.expect("close must succeed");

let buf = op.read(path)
.await
.expect("read to end mut succeed");
let buf = op.read(path).await.expect("read to end mut succeed");

assert_eq!(buf.to_bytes(), content);
}
Expand All @@ -441,14 +440,13 @@ mod tests {

let content = gen_random_bytes();
let mut writer = op.writer(path).await.unwrap();
writer.write_from(Bytes::from(content.clone()))
writer
.write_from(Bytes::from(content.clone()))
.await
.expect("write must succeed");
writer.close().await.expect("close must succeed");

let buf = op.read(path)
.await
.expect("read to end mut succeed");
let buf = op.read(path).await.expect("read to end mut succeed");

assert_eq!(buf.to_bytes(), content);
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/behavior/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub async fn test_write_with_empty_content(op: Operator) -> Result<()> {

let path = TEST_FIXTURE.new_file_path();

op.write(&path, vec![]).await?;
op.write(&path, Vec::<u8>::new()).await?;

let meta = op.stat(&path).await.expect("stat must succeed");
assert_eq!(meta.content_length(), 0);
Expand Down

0 comments on commit c40ccdf

Please sign in to comment.