Expand description
POSIX file system support.
Configuration
root
: Set the work dir for backend.
Refer to Builder
’s public API docs for more information.
Environment
OPENDAL_FS_ROOT
Example
Via Environment
Set environment correctly:
export OPENDAL_FS_ROOT=/path/to/dir/
use std::sync::Arc;
use anyhow::Result;
use opendal::Object;
use opendal::Operator;
use opendal::Scheme;
#[tokio::main]
async fn main() -> Result<()> {
let op: Operator = Operator::from_env(Scheme::Fs)?;
// Create an object handle to start operation on object.
let _: Object = op.object("test_file");
Ok(())
}
Via Builder
use std::sync::Arc;
use anyhow::Result;
use opendal::services::fs;
use opendal::Accessor;
use opendal::Object;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// Create fs backend builder.
let mut builder = fs::Builder::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.build()?);
// Create an object handle to start operation on object.
let _: Object = op.object("test_file");
Ok(())
}
Structs
Builder for fs backend.