Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
export function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
}
export function formatSpeed(bytesPerSec: number): string {
if (bytesPerSec <= 0) return "0 KB/s";
if (bytesPerSec < 1024 * 1024) return `${(bytesPerSec / 1024).toFixed(0)} KB/s`;
return `${(bytesPerSec / (1024 * 1024)).toFixed(1)} MB/s`;
}
export function formatEta(seconds: number | null | undefined): string {
if (seconds == null || seconds <= 0 || !Number.isFinite(seconds)) return "";
if (seconds < 60) return `${Math.round(seconds)}s`;
if (seconds < 3600) {
const m = Math.floor(seconds / 60);
const s = Math.round(seconds % 60);
return s > 0 ? `${m}m ${s}s` : `${m}m`;
}
const h = Math.floor(seconds / 3600);
const m = Math.round((seconds % 3600) / 60);
return m > 0 ? `${h}h ${m}m` : `${h}h`;
}