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: Aad docs for batch operations #363

Merged
merged 1 commit into from
Jun 10, 2022
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
8 changes: 5 additions & 3 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
- [fs](services/fs.md)
- [hdfs](services/hdfs.md)
- [s3](services/s3.md)
- [Features](features/README.md)
- [Decompress](features/decompress.md)
- [Server Side Encrypt](features/server-side-encryption.md)
- [Examples](examples/README.md)
- [Walk Dir](examples/walk.md)
- [Remove a dir recursively](examples/remove_all.md)
- [Read compressed files](examples/decompress-read.md)
- [Enable Server Side Encrypt](examples/server-side-encryption.md)
- [Upgrade](upgrade.md)

# Reference Guide
Expand Down
2 changes: 1 addition & 1 deletion docs/features/README.md → docs/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Features
# Examples

This section will demonstrate how to use OpenDAL provided features.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Decompress
# Read compressed files

OpenDAL has native decompress support.

Expand Down
9 changes: 9 additions & 0 deletions docs/examples/remove_all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Remove a dir recursively

OpenDAL has native support for remove a dir recursively via [`BatchOperator`](/opendal/struct.BatchOperator.html).

```rust
op.batch().remove_all("path/to/dir").await?
```

**Use this function in cautions to avoid unexpected data loss.**
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Server Side Encryption
# Enable Server Side Encryption

OpenDAL has native support for server side encryption.

Expand Down
98 changes: 98 additions & 0 deletions docs/examples/walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Walk Dir

OpenDAL has native walk dir support via [`BatchOperator`](/opendal/struct.BatchOperator.html).

OpenDAL supports two ways to walk a dir:

- bottom up
- top down

## Bottom up

`Bottom up` will list from the most inner dirs.

Given the following file tree:

```text
.
├── dir_x/
│ ├── dir_y/
│ │ ├── dir_z/
│ │ └── file_c
│ └── file_b
└── file_a
```

The output could be:

```text
dir_x/dir_y/dir_z/file_c
dir_x/dir_y/dir_z/
dir_x/dir_y/file_b
dir_x/dir_y/
dir_x/file_a
dir_x/
```

Refer to [`BottomUpWalker`](/opendal/io_util/struct.BottomUpWalker.html) for more information.

```rust
let mut ds = op.batch().walk_bottom_up();

while let Some(de) = ds.try_next().await? {
match de.mode() {
ObjectMode::FILE => {
println!("Handling file")
}
ObjectMode::DIR => {
println!("Handling dir like start a new list via meta.path()")
}
ObjectMode::Unknown => continue,
}
}
```

## Top down

`Top down` will list from the most outer dirs.

Given the following file tree:

```text
.
├── dir_x/
│ ├── dir_y/
│ │ ├── dir_z/
│ │ └── file_c
│ └── file_b
└── file_a
```

The output could be:

```text
dir_x/
dir_x/file_a
dir_x/dir_y/
dir_x/dir_y/file_b
dir_x/dir_y/dir_z/
dir_x/dir_y/dir_z/file_c
```

Refer to [`TopDownWalker`](/opendal/io_util/struct.TopDownWalker.html) for more information.

```rust
let mut ds = op.batch().walk_top_down();

while let Some(de) = ds.try_next().await? {
match de.mode() {
ObjectMode::FILE => {
println!("Handling file")
}
ObjectMode::DIR => {
println!("Handling dir like start a new list via meta.path()")
}
ObjectMode::Unknown => continue,
}
}
```
4 changes: 2 additions & 2 deletions src/io_util/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::ObjectMode;
/// └── file_a
/// ```
///
/// WalkTopDown will output entries like:
/// TopDownWalker will output entries like:
///
/// ```txt
/// dir_x/
Expand Down Expand Up @@ -139,7 +139,7 @@ impl futures::Stream for TopDownWalker {
/// └── file_a
/// ```
///
/// WalkTopDown will output entries like:
/// BottomUpWalker will output entries like:
///
/// ```txt
/// dir_x/dir_y/dir_z/file_c
Expand Down