pub struct Optimizer {
pub speed_limit: Option<u64>,
/* private fields */
}
Expand description
Structure responsible for optimizing download operations through compression and caching
Fields§
§speed_limit: Option<u64>
Implementations§
Source§impl Optimizer
impl Optimizer
Sourcepub fn new(config: OptimizationConfig) -> Self
pub fn new(config: OptimizationConfig) -> Self
Make a new Optimizer instance with the provided configuration
Sourcepub fn compress(&self, data: &[u8]) -> Result<Vec<u8>, Box<dyn Error>>
pub fn compress(&self, data: &[u8]) -> Result<Vec<u8>, Box<dyn Error>>
Compress data using different algorithms based on the configured compression level
Levels 1-3: Gzip Levels 4-6: LZ4 Levels 7-9: Brotli
Sourcepub fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, Box<dyn Error>>
pub fn decompress(&self, data: &[u8]) -> Result<Vec<u8>, Box<dyn Error>>
Decompress data using the appropriate algorithm based on the file header
Supports Gzip, Brotli, and LZ4
Sourcepub fn get_cached_file(
&self,
url: &str,
) -> Result<Option<Vec<u8>>, Box<dyn Error>>
pub fn get_cached_file( &self, url: &str, ) -> Result<Option<Vec<u8>>, Box<dyn Error>>
Retrieve a file from the cache if it exists
Returns None if caching is disabled or the file does not exist
Sourcepub fn cache_file(&self, url: &str, data: &[u8]) -> Result<(), Box<dyn Error>>
pub fn cache_file(&self, url: &str, data: &[u8]) -> Result<(), Box<dyn Error>>
Store a file in the cache
Does nothing if caching is disabled
pub fn get_peer_limit(&self) -> usize
pub fn is_compression_enabled(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Optimizer
impl RefUnwindSafe for Optimizer
impl Send for Optimizer
impl Sync for Optimizer
impl Unpin for Optimizer
impl UnwindSafe for Optimizer
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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