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 metalink;
78pub mod optimization;
79pub mod progress;
80pub mod queue;
81pub mod utils;
82
83// Protocol modules
84pub mod ftp;
85pub mod sftp;
86pub mod torrent;
87
88// Re-exports: Configuration
89pub use config::{Config, ProxyConfig, ProxyType};
90
91// Re-exports: Core download functionality
92pub use advanced_download::AdvancedDownloader;
93pub use download::{download, verify_file_sha256, verify_iso_integrity};
94pub use optimization::Optimizer;
95pub use progress::create_progress_bar;
96
97// Re-exports: Torrent types (when available)
98pub use torrent::{TorrentCallbacks, download_magnet};
99
100// Re-exports: Utilities
101pub use utils::{get_filename_from_url_or_default, print, resolve_output_path};
102
103/// Options for configuring a download operation.
104///
105/// # Example
106///
107/// ```rust
108/// use kget::DownloadOptions;
109///
110/// let options = DownloadOptions {
111/// quiet_mode: true,
112/// output_path: Some("./downloads/file.zip".to_string()),
113/// verify_iso: false,
114/// expected_sha256: None,
115/// };
116/// ```
117#[derive(Debug, Clone)]
118pub struct DownloadOptions {
119 /// Suppress progress output to stdout
120 pub quiet_mode: bool,
121 /// Custom output path (uses URL filename if None)
122 pub output_path: Option<String>,
123 /// Automatically verify SHA-256 for ISO files
124 pub verify_iso: bool,
125 /// Expected SHA-256 hash for automatic integrity comparison
126 pub expected_sha256: Option<String>,
127}
128
129impl Default for DownloadOptions {
130 fn default() -> Self {
131 Self {
132 quiet_mode: false,
133 output_path: None,
134 verify_iso: false,
135 expected_sha256: None,
136 }
137 }
138}
139
140/// Type alias for progress callbacks (0.0 to 1.0)
141pub type ProgressCallback = std::sync::Arc<dyn Fn(f32) + Send + Sync>;
142
143/// Type alias for status message callbacks
144pub type StatusCallback = std::sync::Arc<dyn Fn(String) + Send + Sync>;
145
146/// Prelude module for convenient imports
147pub mod prelude {
148 pub use crate::torrent::{TorrentCallbacks, download_magnet};
149 pub use crate::{
150 AdvancedDownloader, Config, DownloadOptions, Optimizer, ProgressCallback, ProxyConfig,
151 ProxyType, StatusCallback, download, verify_iso_integrity,
152 };
153}