ammo
HTTP Range processing utilities.
Lead Maintainer - Gil Pedersen
Usage
// basic usageconst range = Ammo;// range --> [{ from: 1, to: 5 }] // multiple rangesconst range = Ammo;// range --> [{ from: 1, to: 5 }, { from: 7, to: 9 }] // streams (get range within a `source`)const range = Ammo;const stream = range0;const buffer = async Wreck; // buffer is the portion of source within range
API
header(header, length)
Parses the range from a HTTP header.
header
- A string in the form ofbytes=from-to
, wherefrom
andto
are integers specifying the range. Both are optional. Multiple ranges can be passed as a comma delimited list.length
- A positive integer specifying the maximum length the range can cover. If ato
value passed in theheader
string is greater thanlength
, theto
value is set aslength - 1
.
Returns an array of objects with the properties from
and to
, which specify
the beginning and ending of the range. Overlapping ranges are combined into one
object. Returns null
for invalid input.
new Ammo.Stream(range)
Creates a Transform Stream
that extracts
the portion of a piped in stream within range
.
range
- an object with the propertiesfrom
andto
that specify the range of the piped in stream to read. Objects returned byAmmo.header
can be passed intorange
.