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, ProxyConfig, Optimizer};
15//!
16//! // Simple download
17//! let proxy = ProxyConfig::default();
18//! let optimizer = Optimizer::new();
19//! let options = DownloadOptions::default();
20//! download("https://example.com/file.zip", proxy, optimizer, options, None).unwrap();
21//! ```
22//!
23//! ## Advanced Download with Progress
24//!
25//! ```rust,no_run
26//! use kget::{AdvancedDownloader, ProxyConfig, Optimizer};
27//!
28//! let mut downloader = AdvancedDownloader::new(
29//!     "https://example.com/large.iso".to_string(),
30//!     "large.iso".to_string(),
31//!     false,
32//!     ProxyConfig::default(),
33//!     Optimizer::new(),
34//! );
35//!
36//! // Set progress callback
37//! downloader.set_progress_callback(|progress| {
38//!     println!("Progress: {:.1}%", progress * 100.0);
39//! });
40//!
41//! downloader.download().unwrap();
42//! ```
43//!
44//! ## Torrent Downloads
45//!
46//! ```rust,no_run
47//! use kget::torrent::{download_magnet, TorrentCallbacks};
48//! use kget::{ProxyConfig, Optimizer};
49//! use std::sync::Arc;
50//!
51//! let callbacks = TorrentCallbacks {
52//!     status: Some(Arc::new(|msg| println!("Status: {}", msg))),
53//!     progress: Some(Arc::new(|p| println!("Progress: {:.1}%", p * 100.0))),
54//! };
55//!
56//! download_magnet(
57//!     "magnet:?xt=urn:btih:...",
58//!     "./downloads",
59//!     false,
60//!     ProxyConfig::default(),
61//!     Optimizer::new(),
62//!     callbacks,
63//! ).unwrap();
64//! ```
65//!
66//! ## Features
67//!
68//! - `gui` - Cross-platform GUI using egui (includes `torrent-native`)
69//! - `torrent-native` - Native BitTorrent client using librqbit
70//! - `torrent-transmission` - Transmission RPC integration
71
72// Core modules
73pub mod advanced_download;
74pub mod app;
75pub mod config;
76pub mod 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 advanced_download::AdvancedDownloader;
91pub use download::{download, verify_file_sha256, verify_iso_integrity};
92pub use optimization::Optimizer;
93pub use progress::create_progress_bar;
94
95// Re-exports: Torrent types (when available)
96pub use torrent::{TorrentCallbacks, download_magnet};
97
98// Re-exports: Utilities
99pub use utils::{get_filename_from_url_or_default, print, resolve_output_path};
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///     expected_sha256: None,
113/// };
114/// ```
115#[derive(Debug, Clone)]
116pub struct DownloadOptions {
117    /// Suppress progress output to stdout
118    pub quiet_mode: bool,
119    /// Custom output path (uses URL filename if None)
120    pub output_path: Option<String>,
121    /// Automatically verify SHA-256 for ISO files
122    pub verify_iso: bool,
123    /// Expected SHA-256 hash for automatic integrity comparison
124    pub expected_sha256: Option<String>,
125}
126
127impl Default for DownloadOptions {
128    fn default() -> Self {
129        Self {
130            quiet_mode: false,
131            output_path: None,
132            verify_iso: false,
133            expected_sha256: None,
134        }
135    }
136}
137
138/// Type alias for progress callbacks (0.0 to 1.0)
139pub type ProgressCallback = std::sync::Arc<dyn Fn(f32) + Send + Sync>;
140
141/// Type alias for status message callbacks
142pub type StatusCallback = std::sync::Arc<dyn Fn(String) + Send + Sync>;
143
144/// Prelude module for convenient imports
145pub mod prelude {
146    pub use crate::torrent::{TorrentCallbacks, download_magnet};
147    pub use crate::{
148        AdvancedDownloader, Config, DownloadOptions, Optimizer, ProgressCallback, ProxyConfig,
149        ProxyType, StatusCallback, download, verify_iso_integrity,
150    };
151}