How gblach/imge works
Project type and purpose
• imge is a Rust-based CLI/TUI (text-user-interface) application for writing disk images to drives (and vice versa), with on-the-fly compression/decompression.
• It wraps low-level disk I/O, stream compression, and a curses-style UI to make dd-like workflows safer and more user-friendly.
File structure
• Top-level files:
• Cargo.toml / Cargo.lock: Rust package definition and dependencies
• README.md: project overview, CLI synopsis, screenshots
• .github/workflows: CI checks (Rust fmt, clippy)
• src/ directory:
• main.rs: entry point; CLI parsing (clap), configuration
• mainloop.rs: TUI event loop, rendering screens, handling keybindings
• imge.rs: core logic for reading/writing streams, compression/decompression, drive enumeration
README for additional insights
• Confirms use of TUI (screenshots), CLI options (—all-drives, —from-drive, —verify).
• Mentions gzip/bzip2/xz support → compression crates (flate2, bzip2, xz2).
• No external services; pure local, single-binary tool.
Main components
a. CLI Parser (main.rs)
• Reads command-line args via clap
• Builds a Config object
b. TUI Controller (mainloop.rs)
• Initializes terminal backend (tui-rs + crossterm/termion)
• Renders screens: drive list, warnings, progress, verification
• Dispatches user events (keypresses)
c. Core Engine (imge.rs)
• Drive enumeration & selection (platform-specific block-device discovery)
• Image ↔ Drive streaming pipeline
• Source (file or drive) → optional decompressor → I/O buffer → optional compressor → Destination (drive or file)
• Verification step (read-back & checksum compare)
d. OS / System Calls
• Block device read/write (std::fs or lower-level unsafe calls)
• File I/O for .img, .img.gz, .img.bz2, .img.xz
e. Third-party crates
• clap (CLI)
• tui-rs, crossterm (TUI)
• flate2, bzip2, xz2 (compression)
• indicatif or custom progress reporter
Relationships & interactions
• User invokes binary → main.rs
• main.rs → parse args → instantiate TuiController & ImgeEngine
• TuiController ↔ User I/O (keypress, selections)
• On “start copy” action: TuiController → ImgeEngine
• ImgeEngine → OS Block I/O & Compression layers → streams data → reports progress back to TuiController
• If --verify: ImgeEngine runs read-back & checksum → passes result to TuiController → final screen
Architectural patterns & design principles
• Modular layering: CLI layer → UI layer → Domain/Engine layer → System/OS layer
• Single-process, event-driven architecture
• Stream-based pipeline for on-the-fly (de)compression
• Separation of concerns: UI vs core logic vs I/O