tool: support fractions for --limit-rate and --max-filesize

Allow 2.5k or 3.7M etc. Add mention in documentation.

Verify in test case 1623.

Closes #20266
This commit is contained in:
Daniel Stenberg 2026-01-17 23:11:07 +01:00
parent 6aaac9dd38
commit 6d6899c2f0
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 250 additions and 48 deletions

View file

@ -12,7 +12,7 @@ See-also:
- speed-limit
- speed-time
Example:
- --limit-rate 100K $URL
- --limit-rate 123.45K $URL
- --limit-rate 1000 $URL
- --limit-rate 10M $URL
- --limit-rate 200K --max-time 60 $URL
@ -27,8 +27,8 @@ otherwise would be.
The given speed is measured in bytes/second, unless a suffix is appended.
Appending 'k' or 'K' counts the number as kilobytes, 'm' or 'M' makes it
megabytes, while 'g' or 'G' makes it gigabytes. The suffixes (k, M, G, T, P)
are 1024 based. For example 1k is 1024. Examples: 200K, 3m and 1G.
megabytes etc. The supported suffixes (k, M, G, T, P) are 1024-based. For
example 1k is 1024. Examples: 200K, 3m and 1G.
The rate limiting logic works on averaging the transfer speed to no more than
the set threshold over a period of multiple seconds.
@ -36,3 +36,7 @@ the set threshold over a period of multiple seconds.
If you also use the --speed-limit option, that option takes precedence and
might cripple the rate-limiting slightly, to help keep the speed-limit
logic working.
Starting in curl 8.19.0, the rate can be specified using a fraction as in
`2.5M` for two and a half megabytes per second. It only works with a period
(`.`) delimiter, independent of what your locale might prefer.

View file

@ -12,6 +12,7 @@ See-also:
- limit-rate
Example:
- --max-filesize 100K $URL
- --max-filesize 2.6M $URL
---
# `--max-filesize`
@ -22,9 +23,9 @@ transfer does not start and curl returns with exit code 63.
Setting the maximum value to zero disables the limit.
A size modifier may be used. For example, Appending 'k' or 'K' counts the
number as kilobytes, 'm' or 'M' makes it megabytes, while 'g' or 'G' makes it
gigabytes. Examples: 200K, 3m and 1G. (Added in 7.58.0)
A unit suffix letter can be used. Appending 'k' or 'K' counts the number as
kilobytes, 'm' or 'M' makes it megabytes etc. The supported suffixes (k, M, G,
T, P) are 1024-based. Examples: 200K, 3m and 1G. (Added in 7.58.0)
**NOTE**: before curl 8.4.0, when the file size is not known prior to
download, for such files this option has no effect even if the file transfer
@ -32,3 +33,7 @@ ends up being larger than this given limit.
Starting with curl 8.4.0, this option aborts the transfer if it reaches the
threshold during transfer.
Starting in curl 8.19.0, the maximum size can be specified using a fraction as
in `2.5M` for two and a half megabytes. It only works with a period (`.`)
delimiter, independent of what your locale might prefer.