summaryrefslogtreecommitdiff
path: root/ext/fs/interface.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-05 12:44:24 -0400
committerGitHub <noreply@github.com>2023-05-05 16:44:24 +0000
commita6c47ee74023f6ef683988cabc8caa95406e3c99 (patch)
tree74026c558a175b9cf6f881ec7229499878dd6a1a /ext/fs/interface.rs
parent5270c43e412cc636cd9923182169d166d181f78a (diff)
refactor(ext/node): combine `deno_node::Fs` with `deno_fs::FileSystem` (#18991)
Diffstat (limited to 'ext/fs/interface.rs')
-rw-r--r--ext/fs/interface.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs
index 1847b5982..474089153 100644
--- a/ext/fs/interface.rs
+++ b/ext/fs/interface.rs
@@ -73,7 +73,7 @@ pub struct FsDirEntry {
}
#[async_trait::async_trait(?Send)]
-pub trait FileSystem: Send + Sync {
+pub trait FileSystem: std::fmt::Debug + Send + Sync {
fn cwd(&self) -> FsResult<PathBuf>;
fn tmp_dir(&self) -> FsResult<PathBuf>;
fn chdir(&self, path: &Path) -> FsResult<()>;
@@ -225,4 +225,26 @@ pub trait FileSystem: Send + Sync {
let buf = file.read_all_async().await?;
Ok(buf)
}
+
+ fn is_file(&self, path: &Path) -> bool {
+ self.stat_sync(path).map(|m| m.is_file).unwrap_or(false)
+ }
+
+ fn is_dir(&self, path: &Path) -> bool {
+ self
+ .stat_sync(path)
+ .map(|m| m.is_directory)
+ .unwrap_or(false)
+ }
+
+ fn exists(&self, path: &Path) -> bool {
+ self.stat_sync(path).is_ok()
+ }
+
+ fn read_to_string(&self, path: &Path) -> FsResult<String> {
+ let buf = self.read_file_sync(path)?;
+ String::from_utf8(buf).map_err(|err| {
+ std::io::Error::new(std::io::ErrorKind::InvalidData, err).into()
+ })
+ }
}