Skip to content

Commit cb059ba

Browse files
committed
fix: use std::fs instead of tokio::fs
1 parent 5cab967 commit cb059ba

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ simdutf8 = { version = "0.1.4", features = ["aarch64_neon"] }
9292
pnp = { version = "0.9.0", optional = true }
9393

9494
document-features = { version = "0.2.8", optional = true }
95-
tokio = { version = "1.42.0", features = ["fs", "sync", "rt", "rt-multi-thread", "macros"] }
95+
tokio = { version = "1.42.0", features = ["sync", "rt", "rt-multi-thread", "macros"] }
9696
futures = "0.3.31"
9797

9898
[dev-dependencies]

src/file_system.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ impl Default for FileSystemOs {
106106
}
107107
}
108108

109-
// fn read_to_string(path: &Path) -> io::Result<String> {
110-
// // `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally
111-
// let bytes = std::fs::read(path)?;
112-
// if simdutf8::basic::from_utf8(&bytes).is_err() {
113-
// // Same error as `fs::read_to_string` produces (`io::Error::INVALID_UTF8`)
114-
// return Err(io::Error::new(
115-
// io::ErrorKind::InvalidData,
116-
// "stream did not contain valid UTF-8",
117-
// ));
118-
// }
119-
// // SAFETY: `simdutf8` has ensured it's a valid UTF-8 string
120-
// Ok(unsafe { String::from_utf8_unchecked(bytes) })
121-
// }
109+
fn read_to_string(path: &Path) -> io::Result<String> {
110+
// `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally
111+
let bytes = std::fs::read(path)?;
112+
if simdutf8::basic::from_utf8(&bytes).is_err() {
113+
// Same error as `fs::read_to_string` produces (`io::Error::INVALID_UTF8`)
114+
return Err(io::Error::new(
115+
io::ErrorKind::InvalidData,
116+
"stream did not contain valid UTF-8",
117+
));
118+
}
119+
// SAFETY: `simdutf8` has ensured it's a valid UTF-8 string
120+
Ok(unsafe { String::from_utf8_unchecked(bytes) })
121+
}
122122

123123
impl FileSystem for FileSystemOs {
124124
fn read_to_string<'a>(&'a self, path: &'a Path) -> BoxFuture<'a, io::Result<String>> {
@@ -129,11 +129,11 @@ impl FileSystem for FileSystemOs {
129129
VPath::Zip(info) => {
130130
self.pnp_lru.read_to_string(info.physical_base_path(), info.zip_path)
131131
}
132-
VPath::Virtual(info) => tokio::fs::read_to_string(&info.physical_base_path()).await,
133-
VPath::Native(path) => tokio::fs::read_to_string(&path).await,
132+
VPath::Virtual(info) => read_to_string(&info.physical_base_path()),
133+
VPath::Native(path) => read_to_string(&path),
134134
}
135135
} else {
136-
tokio::fs::read_to_string(path).await
136+
read_to_string(path)
137137
}
138138
}
139139
};
@@ -150,20 +150,20 @@ impl FileSystem for FileSystemOs {
150150
.file_type(info.physical_base_path(), info.zip_path)
151151
.map(FileMetadata::from),
152152
VPath::Virtual(info) => {
153-
tokio::fs::metadata(info.physical_base_path()).await.map(FileMetadata::from)
153+
fs::metadata(info.physical_base_path()).map(FileMetadata::from)
154154
}
155-
VPath::Native(path) => tokio::fs::metadata(path).await.map(FileMetadata::from),
155+
VPath::Native(path) => fs::metadata(path).map(FileMetadata::from),
156156
}
157157
} else {
158-
tokio::fs::metadata(path).await.map(FileMetadata::from)
158+
fs::metadata(path).map(FileMetadata::from)
159159
}
160160
}
161161
};
162162
Box::pin(fut)
163163
}
164164

165165
fn symlink_metadata<'a>(&'a self, path: &'a Path) -> BoxFuture<'a, io::Result<FileMetadata>> {
166-
let fut = async move { tokio::fs::symlink_metadata(path).await.map(FileMetadata::from) };
166+
let fut = async move { fs::symlink_metadata(path).map(FileMetadata::from) };
167167
Box::pin(fut)
168168
}
169169

@@ -184,7 +184,7 @@ impl FileSystem for FileSystemOs {
184184
use std::path::Component;
185185
let mut path_buf = path.to_path_buf();
186186
loop {
187-
let link = tokio::fs::read_link(&path_buf).await?;
187+
let link = fs::read_link(&path_buf)?;
188188
path_buf.pop();
189189
for component in link.components() {
190190
match component {
@@ -208,7 +208,7 @@ impl FileSystem for FileSystemOs {
208208
Component::CurDir | Component::Prefix(_) => {}
209209
}
210210
}
211-
if !tokio::fs::symlink_metadata(&path_buf).await?.is_symlink() {
211+
if !fs::symlink_metadata(&path_buf)?.is_symlink() {
212212
break;
213213
}
214214
}

0 commit comments

Comments
 (0)