add file size to FileEngine (#2323)
This commit is contained in:
1 parent
9d55bfc1dc
commit
d0f0548776
3 files changed
+18
No files matched your search
@@ -20,6 +20,11 @@ impl FileEngine for SerializedFileEngine {
|
||||
self.files.keys().cloned().collect()
|
||||
}
|
||||
|
||||
async fn file_size(&self, file: &str) -> Option<u64> {
|
||||
let file = self.files.get(file)?;
|
||||
Some(file.len() as u64)
|
||||
}
|
||||
|
||||
async fn read_file(&self, file: &str) -> Option<Vec<u8>> {
|
||||
self.files.get(file).cloned()
|
||||
}
|
||||
@@ -42,6 +47,9 @@ pub trait FileEngine {
|
||||
// get a list of file names
|
||||
fn files(&self) -> Vec<String>;
|
||||
|
||||
// get the size of a file
|
||||
async fn file_size(&self, file: &str) -> Option<u64>;
|
||||
|
||||
// read a file to bytes
|
||||
async fn read_file(&self, file: &str) -> Option<Vec<u8>>;
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@ impl FileEngine for NativeFileEngine {
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn file_size(&self, file: &str) -> Option<u64> {
|
||||
let file = File::open(file).await.ok()?;
|
||||
Some(file.metadata().await.ok()?.len())
|
||||
}
|
||||
|
||||
async fn read_file(&self, file: &str) -> Option<Vec<u8>> {
|
||||
let mut file = File::open(file).await.ok()?;
|
||||
|
||||
|
||||
@@ -42,6 +42,11 @@ impl FileEngine for WebFileEngine {
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn file_size(&self, file: &str) -> Option<u64> {
|
||||
let file = self.find(file)?;
|
||||
Some(file.size() as u64)
|
||||
}
|
||||
|
||||
// read a file to bytes
|
||||
async fn read_file(&self, file: &str) -> Option<Vec<u8>> {
|
||||
let file = self.find(file)?;
|
||||
|
||||
Reference in new issue
Block a user