Parallel Downloader (pd) ๐ฆ
A robust, concurrent file downloader built in Rust. It is designed to be resilient, supporting automatic retries, crash recovery, and download verification.
๐ Table of Contents
- ๐ Features
- ๐ง How It Works
- ๐ฆ Installation
- ๐ Usage
- Options
- Commands
- Configuration
- ๐ Library Usage
- ๐งช Testing
- ๐ Examples
- ๐ง Troubleshooting
- ๐ค Contributing
- ๐ License
๐ Features
- Concurrency: Downloads files in parallel chunks to maximize bandwidth.
- Resiliency: Automatically retries failed chunks on network timeouts.
- Crash Recovery: Saves progress to a state file (
.state.json). If the program crashes or is interrupted, simply run the command again to resume exactly where it left off. - Rate Limiting: Optional token-bucket throttling to limit bandwidth usage.
- Integrity Check: Verifies the final file against a SHA-256 hash.
- Library Support: Logic is separated from the CLI, allowing you to use the core downloader in your own Rust applications.
- Batch Processing: Supports input files (
-i list.txt) for bulk downloads. - Background Daemon: Run downloads in the background with job management.
- Interactive TUI: Terminal-based dashboard for monitoring downloads.
- Job Control: Pause and resume individual downloads in daemon mode.
- Authentication: Optional server secret for securing daemon access.
๐ง How It Works
Parallel Downloader uses a chunk-based parallel downloading approach:
- File Analysis: First, it determines the total file size using HTTP HEAD requests
- Chunk Division: The file is divided into equal-sized chunks (typically based on thread count)
- Parallel Download: Each chunk is downloaded concurrently using HTTP Range requests
- Progress Tracking: Individual progress bars show download status for each chunk
- State Persistence: Download progress is saved to
*.state.jsonfiles for resumability - Integrity Verification: Optional SHA-256 verification ensures file correctness
This approach maximizes bandwidth utilization while providing robust error recovery and resumability.
๐ฆ Installation
Pre-built Binaries
Download the latest release for Windows, Linux, or macOS from the Releases Page.
Build from Source
Note: The CLI binary is provided in src/bin/pd/main.rs (the CLI glue is in src/bin/pd/). When developing from source you can run the binary directly with:
# Run the library's CLI binary from source
๐ Usage
1. Standalone Mode (CLI)
Best for quick, one-off downloads.
# Simple download (defaults to 4 threads)
# Advanced Usage
2. Batch Mode
Download a list of URLs (one per line).
# Download files from list.txt, 3 files at a time
3. Daemon Mode (Background Service)
Best for long-running servers or managing queues.
# 1. Start the daemon in a separate terminal
# 2. Add downloads from any terminal
# 3. Check status
# 4. Control downloads
# 5. Interactive dashboard
# 6. Shutdown
Options
| Flag | Description | Default |
|---|---|---|
--url, -u |
The URL to download | Required |
--output, -o |
Output filename | output.bin |
--threads, -t |
Number of concurrent threads | 4 |
--rate-limit |
Max speed in bytes/sec (e.g., 1048576 = 1MB/s) | Unlimited |
--verify-sha256 |
Hash string to verify file integrity | None |
--dir, -d |
Directory to store downloads | Current Dir |
--input, -i |
Input file with list of URLs (one per line) | None |
--concurrent_files, -c |
Number of concurrent downloads in batch mode | 3 |
Commands
| Command | Description |
|---|---|
pd run |
Download a single file or batch of files |
pd start |
Start the background daemon |
pd add |
Add a download to the running daemon |
pd status |
List active downloads |
pd pause |
Pause a specific download by ID |
pd resume |
Resume a specific download by ID |
pd tui |
Open interactive terminal dashboard |
pd stop |
Stop the daemon |
Configuration
This project supports reading settings from a config.toml file or from
environment variables prefixed with PD.
-
File locations (platform-specific):
- Linux:
~/.config/pd/config.toml - macOS:
~/Library/Application Support/pd/config.toml - Windows:
%APPDATA%\pd\config.toml
- Linux:
-
Example: copy
config.example.tomlto one of the locations above and edit values such asthreads,rate_limit,default_dir,concurrent_files,server_secret, andserver_addr. -
Environment variables: you can override values via environment variables using
__as a separator. For example:
# set threads to 8
# set global rate limit to 1 MiB/s
# set server secret for daemon authentication
# set server bind address
Environment variables take precedence over values found in config.toml.
๐ Library Usage
You can use parallel_downloader as a library in your own project.
Add to your Cargo.toml:
[dependencies]
parallel_downloader = { version = "0.3.0", default-features = false }
Use the modules in your code:
use prepare_download;
use download_chunk;
๐งช Testing
We use wiremock to simulate HTTP failures and chunk ranges without hitting real servers.
๐ Examples
The repository includes runnable examples in the examples/ folder to demonstrate how to use parallel_downloader programmatically in your own applications.
Simple Download
This example demonstrates a complete workflow: creating a client, verifying file size, and downloading chunks with a progress bar.
To run the example:
You can view the full source code in examples/simple_download.rs.
๐ง Troubleshooting
Common Issues
Download fails with "Connection reset" errors
- Try reducing the number of threads:
pd run --threads 2 --url <URL> - Check your internet connection stability
- Some servers may not support concurrent connections
State file corruption
- Delete the
.state.jsonfile and restart the download - The state file is created alongside your download with the same name
Daemon connection refused
- Ensure the daemon is running:
pd start - Check if the port is available (default: 127.0.0.1:9090)
- Verify server address in config if changed
High CPU usage
- Reduce thread count or add rate limiting
- This is normal for parallel downloads
Permission denied errors
- Check write permissions in the target directory
- Use
sudoif downloading to system directories
Getting Help
- Check existing GitHub Issues
- Create a new issue with:
- Your OS and Rust version
- Command used and full error output
- URL (anonymized if needed)
๐ค Contributing
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Fork the repository
- Clone your fork:
git clone https://github.com/velumuruganr/parallel_downloader.git - Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run tests:
cargo test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.