diff options
Diffstat (limited to 'ext/fs/interface.rs')
-rw-r--r-- | ext/fs/interface.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 833f362bf..6e3c359bb 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -304,6 +304,35 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync { } } +pub struct DenoConfigFsAdapter<'a>(&'a dyn FileSystem); + +impl<'a> DenoConfigFsAdapter<'a> { + pub fn new(fs: &'a dyn FileSystem) -> Self { + Self(fs) + } +} + +impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> { + fn read_to_string(&self, path: &Path) -> Result<String, std::io::Error> { + use deno_io::fs::FsError; + use std::io::ErrorKind; + self + .0 + .read_text_file_lossy_sync(path, None) + .map_err(|err| match err { + FsError::Io(io) => io, + FsError::FileBusy => std::io::Error::new(ErrorKind::Other, "file busy"), + FsError::NotSupported => { + std::io::Error::new(ErrorKind::Other, "not supported") + } + FsError::PermissionDenied(name) => std::io::Error::new( + ErrorKind::PermissionDenied, + format!("requires {}", name), + ), + }) + } +} + // Like String::from_utf8_lossy but operates on owned values #[inline(always)] fn string_from_utf8_lossy(buf: Vec<u8>) -> String { |