rqbit/crates/librqbit/src/storage/mod.rs

24 lines
739 B
Rust
Raw Normal View History

2024-04-30 09:09:17 +01:00
pub mod example;
pub mod filesystem;
2024-05-01 11:46:10 +01:00
pub mod mmap;
2024-04-30 09:09:17 +01:00
use std::{any::Any, path::Path};
2024-04-30 09:09:17 +01:00
use crate::torrent_state::ManagedTorrentInfo;
pub trait StorageFactory: Send + Sync + Any {
2024-04-30 09:09:17 +01:00
fn init_storage(&self, info: &ManagedTorrentInfo) -> anyhow::Result<Box<dyn TorrentStorage>>;
}
pub trait TorrentStorage: Send + Sync {
fn pread_exact(&self, file_id: usize, offset: u64, buf: &mut [u8]) -> anyhow::Result<()>;
fn pwrite_all(&self, file_id: usize, offset: u64, buf: &[u8]) -> anyhow::Result<()>;
fn remove_file(&self, file_id: usize, filename: &Path) -> anyhow::Result<()>;
fn ensure_file_length(&self, file_id: usize, length: u64) -> anyhow::Result<()>;
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>>;
}