Skip to content

Add _example/download CLI: curl-like downloader with SIGUSR1 rate toggle#13

Merged
fujiwara merged 6 commits into
masterfrom
add-download-example
May 22, 2026
Merged

Add _example/download CLI: curl-like downloader with SIGUSR1 rate toggle#13
fujiwara merged 6 commits into
masterfrom
add-download-example

Conversation

@fujiwara

Copy link
Copy Markdown
Owner

Summary

  • _example/download/main.go: a small CLI that downloads a URL to a file.
  • --default-rate-limit / --lower-rate-limit accept k/M/G units; 0 means "pause".
  • SIGUSR1 toggles between default and lower rates at runtime (demonstrates the new dynamic-rate API).
  • Single-line progress to stdout, refreshed every 200ms: downloaded/total (pct) @ inst-rate [mode set=N/s] ETA Ns.
  • README updated with an example invocation.

Why

The library now supports dynamic rate changes, paused state (rate=0), and ReadCloser. This example exercises all three end-to-end in a recognizable, curl-like shape, so users can copy the pattern.

fujiwara and others added 6 commits May 22, 2026 22:27
The CLI takes a URL, --default-rate-limit and --lower-rate-limit (k/M/G
units, 0 = pause), and an output file. It downloads the URL while
printing a single-line progress display (downloaded/total, percent,
instantaneous rate, current mode, ETA) updated every 200ms. SIGUSR1
flips the limit between the default and lower rates at runtime via
SetRateLimit, demonstrating the dynamic-rate API end-to-end.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
Make it obvious how to toggle the rate while a download is running.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
The previous snippet only showed SetRateLimit; users couldn't tell
that ReadCloser, SetRateLimitEvery, and dynamic rate changes (incl.
pausing with 0) existed without scrolling. Replace it with a single
short example that exercises all three, and point at example/download
for a runnable CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: fujiwara <fujiwara.shunichiro@gmail.com>
@fujiwara fujiwara merged commit eaa093d into master May 22, 2026
2 checks passed
@fujiwara fujiwara deleted the add-download-example branch May 22, 2026 13:42
@github-actions github-actions Bot mentioned this pull request May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant