range-parser
    Overview
    Documentation
    Tutorials
    Insights
    Code
    Dependencies
    Contributors
    Jobs

range-parser

Range header field string parser

1.2.1  •  Updated 1 years ago  •  by jshttp  •  MIT License

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 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(size, 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
  })
}

Options

These properties are accepted in the options object.

combine

Specifies if overlapping & adjacent ranges 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

Popularity

Weekly Downloads
10.8M
Stars
67

Maintenance

Development

Last ver 1 year ago
Created 8 years ago
Last commit 9 months ago
13 days between commits

Technology

Node version: 8.16.0
8.5K unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

8 contributors
Douglas Christopher Wilson
Maintainer, 138 commits
TJ Holowaychuk
Maintainer, 12 commits, 2 merges
Works at Apex
Jonathan Ong
Maintainer, 2 commits
Works at dollarshaveclub
Niggler
1 commits, 1 PRs
Renat Zubairov
1 commits, 1 PRs
Works at elastic.io GmbH
Nook Scheel
1 commits, 1 PRs
Works at Splytech

Tags

range
parser
http
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.