| commit | 5e6221390ff0f68f1569b3119a4404227257c4cc | [log] [tgz] |
|---|---|---|
| author | Xuanwo <github@xuanwo.io> | Tue Mar 08 14:37:45 2022 +0800 |
| committer | GitHub <noreply@github.com> | Tue Mar 08 14:37:45 2022 +0800 |
| tree | da1a2516727c15e8a38700897e1259fe3d739b45 | |
| parent | 3a8181c02c90476f36225433489da599559860d4 [diff] |
examples: Add more examples for services and operations (#113) * examples: Add more examples for services and operations Signed-off-by: Xuanwo <github@xuanwo.io> * Make rustfmt happy Signed-off-by: Xuanwo <github@xuanwo.io>
Open Data Access Layer that connect the whole world together.
OpenDAL is in alpha stage and has been early adopted by databend. Welcome any feedback at Discussions!
use anyhow::Result; use futures::AsyncReadExt; use futures::StreamExt; use opendal::services::fs; use opendal::ObjectMode; use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { let op = Operator::new(fs::Backend::build().root("/tmp").finish().await?); let o = op.object("test_file"); // Write data info file; let w = o.writer(); let n = w .write_bytes("Hello, World!".to_string().into_bytes()) .await?; // Read data from file; let mut r = o.reader(); let mut buf = vec![]; let n = r.read_to_end(&mut buf).await?; // Read range from file; let mut r = o.range_reader(10, 1); let mut buf = vec![]; let n = r.read_to_end(&mut buf).await?; // Get file's Metadata let meta = o.metadata().await?; // List current dir. let mut obs = op.objects("").map(|o| o.expect("list object")); while let Some(o) = obs.next().await { let meta = o.metadata().await?; let path = meta.path(); let mode = meta.mode(); let length = meta.content_length(); } // Delete file. o.delete().await?; Ok(()) }
More examples could be found at examples.
Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this project.
OpenDAL is licensed under Apache 2.0.