How riadizur/mac-parallel-downloader works
Project Type and Purpose
• This is a standalone, command-line interface (CLI) tool written in Go for high-performance parallel file downloading.
• It leverages HTTP range requests to split a large file into N parts, downloads them concurrently, then merges them into a single output file while displaying real-time progress metrics.
Key Components
a. CLI Layer
• Parses command-line arguments: <url>, <output_filename>, <part_count>.
• Invokes the download coordinator.
b. Download Coordinator (main.go)
• Issues an HTTP HEAD request to retrieve Content-Length.
• Calculates byte ranges for each part.
• Spawns N goroutines (one per part).
c. Concurrent Download Workers (goroutines)
• Each worker performs an HTTP GET with the appropriate Range header.
• Streams data directly to a temporary .partX file on disk.
• Reports per-part progress updates via a channel.
d. Progress Bar Aggregator (mpb library)
• Listens for progress updates.
• Renders aligned, real-time progress bars for each part in the console.
e. Merger
• Waits for all workers to complete.
• Opens each .partX in sequence; writes/concatenates into the final <output_filename>.
• Cleans up intermediate files.
f. Metrics Reporter
• Calculates total download time and average speed.
• Prints final summary to stdout.
External Dependencies and Interactions
• HTTP Server(s): hosting the target file (supports Range requests).
• Local File System: for writing parts and final merged file.
• mpb Go library: for console‐based progress bars.
Relationships and Data Flow
• User → CLI Layer → Coordinator
• Coordinator → HTTP HEAD → HTTP Server → Coordinator
• Coordinator → Worker Goroutines → HTTP GET → HTTP Server
• Workers → Temp Files
• Workers → Progress Aggregator
• Coordinator → Merger → Temp Files → Final File
• Coordinator → Metrics Reporter → Console Output
Architectural Patterns and Principles
• Concurrency via goroutines and channels.
• Single responsibility per component (parsing, networking, progress UI, merging).
• Pipeline style: split → download → aggregate → merge → report.
• Clean separation between I/O (network/disk) and UI (progress display).
Essential Elements Checklist
• Concurrency note: annotate the worker container with “N goroutines”.