Skip to content

Commit

Permalink
feat: add removeDirectory{Sync}, rename remove{Sync} to `removeFi…
Browse files Browse the repository at this point in the history
…le{Sync}`
  • Loading branch information
Im-Beast committed Sep 2, 2023
1 parent 47f4e45 commit 1317ef3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
22 changes: 22 additions & 0 deletions ext/fs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,25 @@ pub fn op_remove_file_sync(path: String) -> Result<(), AnyError> {
std::fs::remove_file(path)?;
Ok(())
}

#[op]
pub async fn op_remove_dir(path: String, recursive: bool) -> Result<(), AnyError> {
if recursive {
tokio::fs::remove_dir_all(path).await?;
} else {
tokio::fs::remove_dir(path).await?;
}

Ok(())
}

#[op]
pub fn op_remove_dir_sync(path: String, recursive: bool) -> Result<(), AnyError> {
if recursive {
std::fs::remove_dir_all(path)?;
} else {
std::fs::remove_dir(path)?;
}

Ok(())
}
50 changes: 36 additions & 14 deletions ext/fs/mod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const core = Bueno.core;

/**
* Reads a file asyncronously
* Reads a file asynchronously
* @param {string} path
* @returns {Promise<Uint8Array>}
*/
Expand All @@ -10,7 +10,7 @@ function readFile(path) {
}

/**
* Reads a file syncronously
* Reads a file synchronously
* @param {string} path
* @returns {Uint8Array}
*/
Expand All @@ -19,7 +19,7 @@ function readFileSync(path) {
}

/**
* Reads a text file asyncronously
* Reads a text file synchronously
* @param {string} path
* @returns {Promise<string>}
*/
Expand All @@ -28,7 +28,7 @@ function readTextFile(path) {
}

/**
* Reads a text file syncronously
* Reads a text file synchronously
* @param {string} path
* @returns {string}
*/
Expand All @@ -37,7 +37,7 @@ function readTextFileSync(path) {
}

/**
* Writes a file asyncronously
* Writes a file asynchronously
* @param {string} path
* @param {Uint8Array} contents
* @returns {Promise<void>}
Expand All @@ -47,7 +47,7 @@ function writeFile(path, contents) {
}

/**
* Writes a file syncronously
* Writes a file synchronously
* @param {string} path
* @param {Uint8Array} contents
* @returns {void}
Expand All @@ -57,7 +57,7 @@ function writeFileSync(path, contents) {
}

/**
* Writes a text file asyncronously
* Writes a text file asynchronously
* @param {string} path
* @param {string} contents
* @returns {Promise<void>}
Expand All @@ -67,7 +67,7 @@ function writeTextFile(path, contents) {
}

/**
* Writes a text file syncronously
* Writes a text file synchronously
* @param {string} path
* @param {string} contents
* @returns {void}
Expand All @@ -77,23 +77,43 @@ function writeTextFileSync(path, contents) {
}

/**
* Deletes file asyncronously
* Deletes file asynchronously
* @param {string} path
* @returns {Promise<void>}
*/
function remove(path) {
function removeFile(path) {
core.ops.op_remove_file(path);
}

/**
* Deletes file syncronously
* Deletes file synchronously
* @param {string} path
* @returns {void}
*/
function removeSync(path) {
function removeFileSync(path) {
core.ops.op_remove_file_sync(path);
}

/**
* Deletes directory asynchronously
* @param {string} path
* @param {boolean} recursive
* @returns {Promise<void>}
*/
function removeDirectory(path, recursive) {
core.ops.op_remove_dir(path, recursive);
}

/**
* Deletes directory synchronously
* @param {string} path
* @param {boolean} recursive
* @returns {void}
*/
function removeDirectorySync(path, recursive) {
core.ops.op_remove_dir_sync(path, recursive);
}

Bueno.fs = {
readFile,
readFileSync,
Expand All @@ -103,6 +123,8 @@ Bueno.fs = {
writeFileSync,
writeTextFile,
writeTextFileSync,
remove,
removeSync,
removeFile,
removeFileSync,
removeDirectory,
removeDirectorySync,
};

0 comments on commit 1317ef3

Please sign in to comment.