-
Hello! In version ~ 0.45, there's a breaking change of the read api. Before that, it looks like (https://github.com/duyet/opendal-examples.git): let mut builder = Fs::default();
// Set the root for fs, all operations will happen under this root.
//
// NOTE: the root must be absolute path.
builder.root("/tmp");
// `Accessor` provides the low level APIs, we will use `Operator` normally.
let op: Operator = Operator::new(builder)?
// Init with logging layer enabled.
.layer(LoggingLayer::default())
.finish();
// Read the file
let content = op.read("/hello.txt").await?;
assert_eq!(&content, b"Hello"); where the However, this got changed.
I'm wondering the best practice to read remote file contents. Previously, I found some bug of my code: let mut remote_data_raw = operator.read(&remote_path).await?.current().to_vec(); where the I have a naive fix about this: let remote_data_raw = operator
.read(&remote_path)
.await?
.read_all() // any better method for serde_json::from_xxx?
.await?
.to_bytes();
let remote_data: T = serde_json::from_slice(&remote_data_raw)?; |
Beta Was this translation helpful? Give feedback.
Answered by
Xuanwo
Jun 26, 2024
Replies: 1 comment 1 reply
-
Hi, you can use opendal with serde_json in this way: let remote_data_raw = operator.read(&remote_path).await?;
let remote_data: T = serde_json::from_reader(remote_data_raw.reader())?; For more usage about our |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
imWildCat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, you can use opendal with serde_json in this way:
For more usage about our
Reader
andBuffer
API, please refer to: