range-parser
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The range-parser is a Node.js module that is specifically designed for parsing Range header field strings. With its efficient algorithm, it can parse given header strings and return an array of ranges or negative numbers that signal an error during parsing. This makes the range-parser an incredibly valuable tool for any programmer working with HTTP range requests. The ability to discern the type of range, if it's 'bytes' for instance, and properly index the start and end points of the range is a key feature of this module.
To use the range-parser module, it first has to be installed via npm with the command $ npm install range-parser
. After it's been added to your project, you begin by requiring it in your JavaScript file with var parseRange = require('range-parser')
. Then you can parse headers from your request using var range = parseRange(size, req.headers.range)
. If you need to work with the actual ranges, you can use them like this:
if (range.type === 'bytes') {
// the ranges
range.forEach(function (r) {
// do something with r.start and r.end
})
}
The range-parser also provides an option to combine overlapping & adjacent ranges. Check out this example on how to use it:
parseRange(100, 'bytes=50-55,0-10,5-10,56-60',
{ combine: true })
// Outputs:
// [
// { start: 0, end: 10 },
// { start: 50, end: 60 }
// ]
The official documentation of the range-parser, which include details of its API and options, can be found in the readme content of the package published at the official GitHub repository: https://github.com/jshttp/range-parser. You can always refer back to this readme for advanced usage examples and the latest updates.