pub struct SqliteFs { /* private fields */ }
Expand description
Holds the path of the FS file and the DB Pool
Implementations§
Source§impl SqliteFs
impl SqliteFs
Sourcepub async fn init(mode: FsMode) -> Result<(), FsStatus>
pub async fn init(mode: FsMode) -> Result<(), FsStatus>
Init the SQLite Filesystem. Must be called one time before anything can be used!
Args:
mode
- Mode how to create the FS
Return:
()
- Init was successfulFsStatus::ErrorFsAlreadyInit
- FS is already initializedFsStatus::ErrorCreateFs
- Could not create FSFsStatus::ErrorSetupFs
- Could not setup FSFsStatus::ErrorInsertFsMeta
- Could not insert FS metadata into FS
Behavior:
-
If
mode == FsMode::Memory
the FS will be created in memory only. Nothing will be written to disk automatically. If you want to save your memory FS you need to call [SqliteFs::save_memory_fs_to_disk
]. -
If
mode == FsMode::Persist(fs_path)
and the FS specified byfs_path
does not exist then the FS will be created. When the FS already exist it will be loaded.
Sourcepub async fn copy(from: &str, to: &str) -> Result<(), FsStatus>
pub async fn copy(from: &str, to: &str) -> Result<(), FsStatus>
Copies the contents of one file to another.
This function will overwrite the contents of to.
Args:
from
- actual file nameto
- new file name
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorFileNotFound
- Filefrom
does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn exists(path: &str) -> Result<bool, FsStatus>
pub async fn exists(path: &str) -> Result<bool, FsStatus>
Given a path, queries the file system to get information about a file
Args:
path
- Name of the File
Return:
Ok(true)
- file existOk(true)
- file does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn metadata(path: &str) -> Result<SqliteFsFileMeta, FsStatus>
pub async fn metadata(path: &str) -> Result<SqliteFsFileMeta, FsStatus>
Given a path, queries the file system to get information about a file
Args:
path
- Name of the File
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorFileNotFound
- Filefrom
does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn read(path: &str) -> Result<Vec<u8>, FsStatus>
pub async fn read(path: &str) -> Result<Vec<u8>, FsStatus>
Reads the entire contents of a file into a bytes vector.
Args:
path
- Name of the File
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorFileNotFound
- Filefrom
does not existFsStatus::ErrorInvalidCompressionLevel
- compression level is invalidFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn read_all(path: &str) -> Result<Vec<String>, FsStatus>
pub async fn read_all(path: &str) -> Result<Vec<String>, FsStatus>
Read all FS entry names where name starts with path
.
(std::fs::read_dir
)
Args:
path
- Name of the dir
Return:
Ok(Vec<String>)
- list with the entry names within a directoryFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorDirNotFound
- Filefrom
does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn read_to_string(path: &str) -> Result<String, FsStatus>
pub async fn read_to_string(path: &str) -> Result<String, FsStatus>
Reads the entire contents of a file into a string.
Args:
path
- Name of the File
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorFileNotFound
- Filefrom
does not existFsStatus::ErrorInvalidCompressionLevel
- compression level is invalidFsStatus::ErrorDb
- DB Transaction ErrorFsStatus::ErrorReadToString
- Could not convert file data to string
Sourcepub async fn remove_all(path: &str) -> Result<Vec<String>, FsStatus>
pub async fn remove_all(path: &str) -> Result<Vec<String>, FsStatus>
Removes all FS entries where name starts with path
.
Think of it like rm -rf /my/path/my_fi*
(std::fs::remove_dir
)
Args:
path
- Name of the dir
Return:
Ok(Vec<String>)
- list with names of deleted filesFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorDirNotFound
- Filefrom
does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn remove_file(path: &str) -> Result<(), FsStatus>
pub async fn remove_file(path: &str) -> Result<(), FsStatus>
Removes a file from the filesystem.
Args:
path
- Name of the File
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorFileNotFound
- Filefrom
does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn rename(from: &str, to: &str) -> Result<(), FsStatus>
pub async fn rename(from: &str, to: &str) -> Result<(), FsStatus>
Writes a slice as the entire contents of a file.
This function will create a file if it does not exist, and will entirely replace its contents if it does.
Args:
from
- actual file nameto
- new file name
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorFileNotFound
- Filefrom
does not existFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn write(path: &str, data: &[u8]) -> Result<(), FsStatus>
pub async fn write(path: &str, data: &[u8]) -> Result<(), FsStatus>
Writes a slice as the entire contents of a file.
This function will create a file if it does not exist, and will entirely replace its contents if it does.
Args:
path
- Name of the Filedata
- data to write to file
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorDb
- DB Transaction Error
Sourcepub async fn write_compressed(
path: &str,
data: &[u8],
compression_level: i64,
) -> Result<(), FsStatus>
pub async fn write_compressed( path: &str, data: &[u8], compression_level: i64, ) -> Result<(), FsStatus>
Writes a slice as the entire contents of a file.
This function will create a file if it does not exist, and will entirely replace its contents if it does.
Args:
path
- Name of the Filedata
- data to compress to write to filecompression_level
- Range:>= 1 && <= 9
(1: lowest compression level -> 9: highest compression level)
Return:
Ok(())
- Operation was successfulFsStatus::ErrorFsNotInit
- FS is not initializedFsStatus::ErrorInvalidCompressionLevel
- Compression level is out of rangeFsStatus::ErrorDb
- DB Transaction Error
Auto Trait Implementations§
impl Freeze for SqliteFs
impl !RefUnwindSafe for SqliteFs
impl Send for SqliteFs
impl Sync for SqliteFs
impl Unpin for SqliteFs
impl !UnwindSafe for SqliteFs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more