pub struct Optimizer {
pub speed_limit: Option<u64>,
/* private fields */
}Expand description
Download optimizer for compression, caching, and speed limiting.
The Optimizer manages download performance features:
- Compression: Reduces storage size using configurable algorithms
- Caching: Stores files locally to avoid re-downloading
- Speed limits: Controls maximum download speed
§Compression Levels
| Level | Algorithm | Speed | Ratio |
|---|---|---|---|
| 1-3 | Gzip | Fast | Moderate |
| 4-6 | LZ4 | Balanced | Good |
| 7-9 | Brotli | Slow | Best |
§Example
use kget::{Optimizer, Config};
// From config
let config = Config::default();
let optimizer = Optimizer::from_config(config.optimization);
// Or with defaults
let optimizer = Optimizer::new();Fields§
§speed_limit: Option<u64>Speed limit in bytes per second (None = unlimited)
Implementations§
Source§impl Optimizer
impl Optimizer
Sourcepub fn from_config(config: OptimizationConfig) -> Self
pub fn from_config(config: OptimizationConfig) -> Self
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 the configured algorithm.
The algorithm is selected based on compression_level:
- Levels 1-3: Gzip (fast)
- Levels 4-6: LZ4 (balanced)
- Levels 7-9: Brotli (high compression)
Returns the original data unchanged if compression is disabled.
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 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
Sourcepub fn get_peer_limit(&self) -> usize
pub fn get_peer_limit(&self) -> usize
Get the peer connection limit for torrent downloads.
Uses the speed limit as a proxy for connection capacity. Returns 50 if no speed limit is set.
Sourcepub fn is_compression_enabled(&self) -> bool
pub fn is_compression_enabled(&self) -> bool
Check if compression is enabled.
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 UnsafeUnpin 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