range-parser

Range header field parser

Showing:

Popularity

Downloads/wk

19.6M

GitHub Stars

81

Maintenance

Last Commit

2yrs ago

Contributors

5

Package

Dependencies

0

Size (min+gzip)

0.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

range-parser

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Range header field parser.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install range-parser

API

var parseRange = require('range-parser')

parseRange(size, header, options)

Parse the given header string where size is the size of the selected representation that is to be partitioned into subranges. An array of subranges 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 subranges = parseRange(size, req.headers.range)

// the type of the subranges
if (subranges.type === 'bytes') {
  // the ranges
  subranges.forEach(function (r) {
    // do something with r.start and r.end
  })
}

Options

These properties are accepted in the options object.

combine

Specifies if overlapping & adjacent subranges should be combined, defaults to false. When true, ranges will be combined and returned as if they were specified that way in the header.

parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
// => [
//      { start: 0,  end: 10 },
//      { start: 50, end: 60 }
//    ]

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial