node package manager

range-parser

Range header field string parser

range-parser

Range header field parser.

$ npm install range-parser
var parseRange = require('range-parser')

Parse the given header string where size is the maximum size of the resource. An array of ranges will be returned or negative numbers indicating an error parsing.

  • -2 signals a malformed header string
  • -1 signals an unsatisfiable range
// parse header from request 
var range = parseRange(req.headers.range)
 
// the type of the range 
if (range.type === 'bytes') {
  // the ranges 
  range.forEach(function (r) {
    // do something with r.start and r.end 
  })
}

MIT