@hapi/ammo v6.0.1
console
npm install @hapi/ammo@6.0.1console
yarn add @hapi/ammo@6.0.1console
pnpm add @hapi/ammo@6.0.1HTTP Range processing utilities.
Compatibility
| Major version | License | Node.js |
|---|---|---|
| 6 | BSD | >= 16 |
Usage
js
// basic usage
const range = Ammo.header('bytes=1-5', 10);
// range --> [{ from: 1, to: 5 }]
// multiple ranges
const range = Ammo.header('bytes=1-5,7-10', 10);
// range --> [{ from: 1, to: 5 }, { from: 7, to: 9 }]
// streams (get range within a `source`)
const range = Ammo.header('bytes=1000-4000', 5000);
const stream = new Ammo.Stream(range[0]);
const buffer = await Wreck.read(source.pipe(stream));
// buffer is the portion of source within rangeMethods
header(header, length)
Parses the range from a HTTP header, where:
header- A string in the form ofbytes=from-to, wherefromandtoare 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 atovalue passed in theheaderstring is greater thanlength, thetovalue 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, where:
range- an object with the propertiesfromandtothat specify the range of the piped in stream to read. Objects returned byAmmo.headercan be passed intorange.