You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by su...@apache.org on 2023/12/19 14:18:48 UTC
(incubator-opendal) 01/01: align list api
This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch suyan/nodejs-align-list-api
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit b6606bb1e9349e4408bc9261a4c2278021d51875
Author: suyanhanx <su...@gmail.com>
AuthorDate: Tue Dec 19 22:17:43 2023 +0800
align list api
Signed-off-by: suyanhanx <su...@gmail.com>
---
bindings/nodejs/src/lib.rs | 114 ++++++++++-----------------------------------
1 file changed, 24 insertions(+), 90 deletions(-)
diff --git a/bindings/nodejs/src/lib.rs b/bindings/nodejs/src/lib.rs
index ee05ee2cf..f5ed474ba 100644
--- a/bindings/nodejs/src/lib.rs
+++ b/bindings/nodejs/src/lib.rs
@@ -341,70 +341,6 @@ impl Operator {
.map_err(format_napi_error)
}
- /// List dir in flat way.
- ///
- /// This function will create a new handle to list entries.
- ///
- /// An error will be returned if given path doesn't end with /.
- ///
- /// ### Example
- ///
- /// ```javascript
- /// const lister = await op.scan("/path/to/dir/");
- /// while (true) {
- /// const entry = await lister.next();
- /// if (entry === null) {
- /// break;
- /// }
- /// let meta = await op.stat(entry.path);
- /// if (meta.is_file) {
- /// // do something
- /// }
- /// }
- /// `````
- #[napi]
- pub async fn scan(&self, path: String) -> Result<Lister> {
- Ok(Lister(
- self.0
- .lister_with(&path)
- .recursive(true)
- .await
- .map_err(format_napi_error)?,
- ))
- }
-
- /// List dir in flat way synchronously.
- ///
- /// This function will create a new handle to list entries.
- ///
- /// An error will be returned if given path doesn't end with /.
- ///
- /// ### Example
- /// ```javascript
- /// const lister = op.scan_sync(/path/to/dir/");
- /// while (true) {
- /// const entry = lister.next();
- /// if (entry === null) {
- /// break;
- /// }
- /// let meta = op.statSync(entry.path);
- /// if (meta.is_file) {
- /// // do something
- /// }
- /// }
- /// `````
- #[napi]
- pub fn scan_sync(&self, path: String) -> Result<BlockingLister> {
- Ok(BlockingLister(
- self.0
- .blocking()
- .lister_with(&path)
- .recursive(true)
- .call()
- .map_err(format_napi_error)?,
- ))
- }
-
/// Delete the given path.
///
/// ### Notes
@@ -460,18 +396,14 @@ impl Operator {
/// List given path.
///
- /// This function will create a new handle to list entries.
+ /// This function will return an array of entries.
///
/// An error will be returned if given path doesn't end with `/`.
///
/// ### Example
/// ```javascript
- /// const lister = await op.list("path/to/dir/");
- /// while (true) {
- /// const entry = await lister.next();
- /// if (entry === null) {
- /// break;
- /// }
+ /// const list = await op.list("path/to/dir/");
+ /// for (let entry of list) {
/// let meta = await op.stat(entry.path);
/// if (meta.isFile) {
/// // do something
@@ -479,26 +411,27 @@ impl Operator {
/// }
/// ```
#[napi]
- pub async fn list(&self, path: String) -> Result<Lister> {
- Ok(Lister(
- self.0.lister(&path).await.map_err(format_napi_error)?,
- ))
+ pub async fn list(&self, path: String) -> Result<Vec<Entry>> {
+ Ok(self
+ .0
+ .list(&path)
+ .await
+ .map_err(format_napi_error)?
+ .iter()
+ .map(|e| Entry(e.to_owned()))
+ .collect())
}
/// List given path synchronously.
///
- /// This function will create a new handle to list entries.
+ /// This function will return a array of entries.
///
/// An error will be returned if given path doesn't end with `/`.
///
/// ### Example
/// ```javascript
- /// const lister = op.listSync("path/to/dir/");
- /// while (true) {
- /// const entry = lister.next();
- /// if (entry === null) {
- /// break;
- /// }
+ /// const list = op.listSync("path/to/dir/");
+ /// for (let entry of list) {
/// let meta = op.statSync(entry.path);
/// if (meta.isFile) {
/// // do something
@@ -506,14 +439,15 @@ impl Operator {
/// }
/// ```
#[napi]
- pub fn list_sync(&self, path: String) -> Result<BlockingLister> {
- Ok(BlockingLister(
- self.0
- .blocking()
- .lister_with(&path)
- .call()
- .map_err(format_napi_error)?,
- ))
+ pub fn list_sync(&self, path: String) -> Result<Vec<Entry>> {
+ Ok(self
+ .0
+ .blocking()
+ .list(&path)
+ .map_err(format_napi_error)?
+ .iter()
+ .map(|e| Entry(e.to_owned()))
+ .collect())
}
/// Get a presigned request for read.