Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add service doc for fs #2337

Merged
merged 3 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 1 addition & 49 deletions core/src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,55 +36,7 @@ use crate::*;

/// POSIX file system support.
///
/// # Capabilities
///
/// This service can be used to:
///
/// - [x] stat
/// - [x] read
/// - [x] write
/// - [x] append
/// - [x] create_dir
/// - [x] delete
/// - [x] copy
/// - [x] rename
/// - [x] list
/// - [ ] ~~scan~~
/// - [ ] ~~presign~~
/// - [x] blocking
///
/// # Configuration
///
/// - `root`: Set the work dir for backend.
///
/// Refer to [`FsBuilder`]'s public API docs for more information.
///
/// # Example
///
/// ## Via Builder
///
/// ```
/// use std::sync::Arc;
///
/// use anyhow::Result;
/// use opendal::services::Fs;
/// use opendal::Operator;
///
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// // Create fs backend builder.
/// 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)?.finish();
///
/// Ok(())
/// }
/// ```
#[doc = include_str!("docs.md")]
#[derive(Default, Debug)]
pub struct FsBuilder {
root: Option<PathBuf>,
Expand Down
50 changes: 50 additions & 0 deletions core/src/services/fs/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Capabilities

This service can be used to:

- [x] stat
- [x] read
- [x] write
- [x] append
- [x] create_dir
- [x] delete
- [x] copy
- [x] rename
- [x] list
- [ ] ~~scan~~
- [ ] ~~presign~~
- [x] blocking

# Configuration

- `root`: Set the work dir for backend.

Refer to public API docs for more information.

# Example

### Via Builder


```rust
use std::sync::Arc;

use anyhow::Result;
use opendal::services::Fs;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
// Create fs backend builder.
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)?.finish();

Ok(())
}
```
6 changes: 5 additions & 1 deletion website/docs/services/azdfs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import TabItem from '@theme/TabItem';

```rust
use std::sync::Arc;

use anyhow::Result;
use opendal::services::Azdfs;
use opendal::Scheme;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
Expand All @@ -31,6 +32,7 @@ async fn main() -> Result<()> {
map.insert("endpoint".to_string(), "https://accountname.dfs.core.windows.net".to_string());
map.insert("account_name".to_string(), "account_name".to_string());
map.insert("account_key".to_string(), "account_key".to_string());

let op: Operator = Operator::via_map(Scheme::Azdfs, map)?;
Ok(())
}
Expand All @@ -41,6 +43,7 @@ async fn main() -> Result<()> {

```javascript
import { Operator } from "opendal";

async function main() {
const op = new Operator("azdfs", {
root: "/path/to/dir",
Expand All @@ -57,6 +60,7 @@ async function main() {

```python
import opendal

op = opendal.Operator("azdfs",
root="/path/to/dir",
filesystem="test",
Expand Down
63 changes: 63 additions & 0 deletions website/docs/services/fs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Fs
---

POSIX file system support.

import Docs from '../../../core/src/services/fs/docs.md'

<Docs components={props.components} />

### Via Config

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="rust" label="Rust" default>

```rust
use std::sync::Arc;

use anyhow::Result;
use opendal::Scheme;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("root".to_string(), "/path/to/dir".to_string());

let op: Operator = Operator::via_map(Scheme::Fs, map)?;
Ok(())
}
```

</TabItem>
<TabItem value="node.js" label="Node.js">

```javascript
import { Operator } from "opendal";

async function main() {
const op = new Operator("fs", {
root: "/path/to/dir",
});
}
```

</TabItem>
<TabItem value="python" label="Python">

```python
import opendal

op = opendal.Operator("fs",
root="/path/to/dir",
)
```

</TabItem>
</Tabs>