remozipsy 0.0.1

zip implementation independent structs and helpers
Documentation
use core::{fmt::Debug, future::Future};
use futures_lite::stream::Stream;
use std::ops::RangeInclusive;

use bytes::Bytes;

use crate::model::LocalFileInfo;

mod local_directory;
mod sync;

pub use local_directory::calculate_local_unix_path;
pub use sync::{Progress, State};

pub trait FileSystem {
    type Error: Debug + Send;
    type StorePrepare: Send;

    /// returns all files existing locally and thus might already be in sync/or
    /// out-of-sync with the remote files
    fn all_files(&self) -> impl Future<Output = Result<Vec<LocalFileInfo>, Self::Error>> + Send;

    /// This function is always called before any actually data is storred. you
    /// can assume it to be called exactly once per storage, EXCEPT an error
    /// occurs in the meantime. Its useful for opening a file in the
    /// meantime, or do some checks early^
    fn prepare_store_file(&self, path: &str) -> impl Future<Output = Result<Self::StorePrepare, Self::Error>> + Send;

    /// Write the data to disk
    fn store_file(
        &self,
        prepared: Self::StorePrepare,
        data: Bytes,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;

    /// File should be removed from FileSystem
    fn delete_file(&self, path: &str) -> impl Future<Output = Result<(), Self::Error>> + Send;
}

/// TODO: write about ensuring that file doesnt change between requests
pub trait RemoteZip {
    type Error: Debug + Send;

    fn get_zip_size(&self) -> impl Future<Output = Result<usize, Self::Error>> + Send;
    fn fetch_bytes(&self, range: RangeInclusive<usize>) -> impl Future<Output = Result<Bytes, Self::Error>> + Send;
    fn fetch_bytes_stream(
        &self,
        range: RangeInclusive<usize>,
    ) -> impl Future<Output = Result<impl Stream<Item = Result<Bytes, Self::Error>> + Send, Self::Error>> + Send;
}