Module: net.extras
Source: ./net/extras.reef
Overview
net.extras - Extra utilities for HTTP downloads
Provides ready-to-use progress display functions for use with http.http_download_file_callback(). Two display styles are available:
Style 1: Detailed progress with speed Downloading: 45% (675 KB / 1500 KB) at 450 KB/s
Style 2: Visual progress bar (customizable) Downloading: filename.tar.gz (1500 KB) from https://example.com/... [▍▍▍▍▍▍▍▍▍▍▍▍ ] 45%
Usage: import net.http import net.extras
// Style 1: Detailed http.http_download_file_callback(url, path, fn(p: http.HttpDownloadProgress): bool => extras.progress_detailed(p))
// Style 2: Bar (call progress_bar_init first to set context) extras.progress_bar_init(url) http.http_download_file_callback(url, path, fn(p: http.HttpDownloadProgress): bool => extras.progress_bar(p))
// Customize the progress bar character and width: extras.progress_bar_set_char("*") // Use asterisks extras.progress_bar_set_char("▓") // Use block character extras.progress_bar_set_char("#") // Use hash extras.progress_bar_set_width(40) // Make bar 40 chars wide
Functions
fn progress_detailed(progress: http.HttpDownloadProgress): bool
Renders detailed progress: percentage, bytes downloaded, speed Example: Downloading: 45% (675 KB / 1500 KB) at 450 KB/s
fn progress_bar(progress: http.HttpDownloadProgress): bool
Renders visual progress bar with header Example: Downloading: file.tar.gz (1500 KB) from https://example.com/file.tar.gz [▍▍▍▍▍▍▍▍▍▍▍▍ ] 45%
fn url_filename(url: string): string
Extract filename from URL (everything after the last '/')
fn format_size(bytes: int): string
Format bytes as human-readable string (KB, MB, GB)
Procedures
proc progress_bar_init(url: string)
Initialize bar progress context with the URL Must be called before using progress_bar()
proc progress_bar_set_char(fill_char: string)
Set the character used to fill the progress bar Examples: "▍", "▓", "█", "#", "*", "=", "."
proc progress_bar_set_width(width: int)
Set the width of the progress bar (number of characters) Default is 26
Generated by reefc doc