Skip to main content

kget/
lib.rs

1//! # KGet - A Powerful Download Library for Rust
2//!
3//! `kget` provides robust downloading capabilities for modern applications:
4//!
5//! - **HTTP/HTTPS downloads** with parallel connections (up to 32x speed)
6//! - **FTP/SFTP support** for legacy and secure file transfers  
7//! - **BitTorrent** via magnet links with native client (requires `torrent-native` feature)
8//! - **ISO verification** with automatic SHA-256 integrity checking
9//! - **Auto-optimization** based on file type and network conditions
10//!
11//! ## Quick Start
12//!
13//! ```rust,no_run
14//! use kget::{download, DownloadOptions, Config, ProxyConfig, Optimizer};
15//!
16//! // Simple download
17//! let config = Config::default();
18//! let proxy = ProxyConfig::default();
19//! let optimizer = Optimizer::new();
20//! download("https://example.com/file.zip", false, None, &config, proxy, optimizer).unwrap();
21//! ```
22//!
23//! ## Advanced Download with Progress
24//!
25//! ```rust,no_run
26//! use kget::{AdvancedDownloader, ProxyConfig, Optimizer};
27//! use std::sync::Arc;
28//!
29//! let mut downloader = AdvancedDownloader::new(
30//!     "https://example.com/large.iso".to_string(),
31//!     "large.iso".to_string(),
32//!     false,
33//!     ProxyConfig::default(),
34//!     Optimizer::new(),
35//! );
36//!
37//! // Set progress callback
38//! downloader.set_progress_callback(Arc::new(|progress| {
39//!     println!("Progress: {:.1}%", progress * 100.0);
40//! }));
41//!
42//! downloader.download().unwrap();
43//! ```
44//!
45//! ## Torrent Downloads
46//!
47//! ```rust,no_run
48//! use kget::torrent::{download_magnet, TorrentCallbacks};
49//! use kget::{ProxyConfig, Optimizer};
50//! use std::sync::Arc;
51//!
52//! let callbacks = TorrentCallbacks {
53//!     status: Some(Arc::new(|msg| println!("Status: {}", msg))),
54//!     progress: Some(Arc::new(|p| println!("Progress: {:.1}%", p * 100.0))),
55//! };
56//!
57//! download_magnet(
58//!     "magnet:?xt=urn:btih:...",
59//!     "./downloads",
60//!     false,
61//!     ProxyConfig::default(),
62//!     Optimizer::new(),
63//!     callbacks,
64//! ).unwrap();
65//! ```
66//!
67//! ## Features
68//!
69//! - `gui` - Cross-platform GUI using egui (includes `torrent-native`)
70//! - `torrent-native` - Native BitTorrent client using librqbit
71//! - `torrent-transmission` - Transmission RPC integration
72
73// Core modules
74pub mod config;
75pub mod download;
76pub mod advanced_download;
77pub mod optimization;
78pub mod progress;
79pub mod utils;
80
81// Protocol modules
82pub mod ftp;
83pub mod sftp;
84pub mod torrent;
85
86// Re-exports: Configuration
87pub use config::{Config, ProxyConfig, ProxyType};
88
89// Re-exports: Core download functionality
90pub use download::{download, verify_iso_integrity};
91pub use advanced_download::AdvancedDownloader;
92pub use optimization::Optimizer;
93pub use progress::create_progress_bar;
94
95// Re-exports: Torrent types (when available)
96pub use torrent::{download_magnet, TorrentCallbacks};
97
98// Re-exports: Utilities
99pub use utils::{get_filename_from_url_or_default, resolve_output_path, print};
100
101/// Options for configuring a download operation.
102///
103/// # Example
104///
105/// ```rust
106/// use kget::DownloadOptions;
107///
108/// let options = DownloadOptions {
109///     quiet_mode: true,
110///     output_path: Some("./downloads/file.zip".to_string()),
111///     verify_iso: false,
112/// };
113/// ```
114#[derive(Debug, Clone)]
115pub struct DownloadOptions {
116    /// Suppress progress output to stdout
117    pub quiet_mode: bool,
118    /// Custom output path (uses URL filename if None)
119    pub output_path: Option<String>,
120    /// Automatically verify SHA-256 for ISO files
121    pub verify_iso: bool,
122}
123
124impl Default for DownloadOptions {
125    fn default() -> Self {
126        Self {
127            quiet_mode: false,
128            output_path: None,
129            verify_iso: false,
130        }
131    }
132}
133
134/// Type alias for progress callbacks (0.0 to 1.0)
135pub type ProgressCallback = std::sync::Arc<dyn Fn(f32) + Send + Sync>;
136
137/// Type alias for status message callbacks
138pub type StatusCallback = std::sync::Arc<dyn Fn(String) + Send + Sync>;
139
140/// Prelude module for convenient imports
141pub mod prelude {
142    pub use crate::{
143        Config, ProxyConfig, ProxyType,
144        AdvancedDownloader, Optimizer,
145        DownloadOptions, ProgressCallback, StatusCallback,
146        download, verify_iso_integrity,
147    };
148    pub use crate::torrent::{download_magnet, TorrentCallbacks};
149}