Expand description
This crate enables you to sync the content from a remote zip file to a local filesystem, WITHOUT fetching the entire file.
§Usage
use remozipsy::{Config, Statemachine, reqwest::ReqwestRemoteZip, tokio::TokioLocalStorage};
#[tokio::main(flavor = "current_thread")]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let remote =
ReqwestRemoteZip::with_url("https://getsamplefiles.com/download/zip/sample-1.zip")?;
let local = TokioLocalStorage::new("./extract".into(), Vec::new());
let mut state = Statemachine::new(remote, local, Config::default());
while let Some((progress, next_state)) = state.progress().await {
state = next_state;
println!("Progress: {progress:?}");
tokio::task::yield_now().await;
}
Ok(())
}Modules§
- reqwest
- Default implementations for RemoteZip that are only available with the
reqwestfeature enabled. - tokio
- Default implementations for FileSystem that are only available with the
tokiofeature enabled.
Structs§
- Config
- Configurations for the state machine
- File
Info - Used in this crate’s traits to interact with
FileSystemandRemoteZip - Progress
Details - Indicates progress based on bytes, e.g. for filesystem or remote operation
- Remote
File Info - Use this to provide internal zip information to this crate.
If you don’t want to go low-level and build this yourself, use the
fetch_remote_file_infohelper method. - Statemachine
- Main struct to sync remote with local via
Self::progress.
Enums§
Traits§
- File
System - This trait is used to access the local file system.
You can implement it according to your needs or use
the
crate::tokio::TokioLocalStoragestruct. Note: try to avoid parallel modifications to the Filesystem during execution time of the statemachine. - Remote
Zip - This trait is used to access the remote zip file.
You can implement it according to your needs or use
the
crate::reqwest::ReqwestRemoteZipstruct. Note: the zip MUST NOT change during execution time of the statemachine.
Functions§
- calculate_
local_ unix_ path - Helper function that can be used if you want to build your own
crate::FileSystem - fetch_
remote_ file_ info - Helper function to read
RemoteFileInfoif you can provide zip size and a fetch function.