mirror of
https://github.com/curl/curl.git
synced 2026-07-27 05:17:17 +03:00
curl/var: change byte offset syntax for assignments
Follow-up to 40c264db61 after discussions on IRC.
The new style is
name[0-99]=contents
and
name[0-99]@filename
A) This does not cause the same problems with old curl versions trying
the new syntax as this way will cause old curls just fail with syntax
error and not risk using the wrong file.
B) Adds the same byte range support for "normal" assigns, which the
previous syntax did not. Thus lets a user get a partial content of a
variable etc.
Added test 790 and 791 to verify non-file assigns with ranges.
Closes #15862
This commit is contained in:
parent
e7b90dadb2
commit
c2d37463b9
11 changed files with 167 additions and 42 deletions
|
|
@ -36,14 +36,20 @@ the environment variable is not set, use --variable %name=content or
|
|||
--variable %name@content. Note that on some systems - but not all -
|
||||
environment variables are case insensitive.
|
||||
|
||||
Added in curl 8.12.0: when getting contents from a file, you can request to
|
||||
get a byte range from it by appending ";[start-end]" to the filename, where
|
||||
*start* and *end* are byte offsets to include from the file. For example,
|
||||
asking for offset "2-10" means offset two to offset ten, including the byte
|
||||
offset 10, meaning 9 bytes in total. "2-2" means a single byte at offset 2.
|
||||
Not providing a second number implies to the end of the file. The start offset
|
||||
cannot be larger than the end offset. Asking for a range that is outside of
|
||||
the file size makes the variable contents empty.
|
||||
Added in curl 8.12.0: you can get a byte range from the source by appending
|
||||
`[start-end]` to the variable name, where *start* and *end* are byte offsets
|
||||
to include from the contents. For example, asking for offset "2-10" means
|
||||
offset two to offset ten, inclusive, resulting in 9 bytes in total. `2-2`
|
||||
means a single byte at offset 2. Not providing a second number implies to the
|
||||
end of data. The start offset cannot be larger than the end offset. Asking for
|
||||
a range that is outside of the file size makes the variable contents empty.
|
||||
For example, getting the first one hundred bytes from a given file:
|
||||
|
||||
curl --variable "fraction[0-99]@filename"
|
||||
|
||||
Given a byte range that has no data results in an empty string. Asking for a
|
||||
range that is larger than the content makes curl use the piece of the data
|
||||
that exists.
|
||||
|
||||
To assign a variable using contents from another variable, use
|
||||
--expand-variable. Like for example assigning a new variable using contents
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue