Node.js parser for Content-Range and Range HTTP header fields according to the HTTP/1.1 specifications.
$ npm install http-range
var ContentRange = require('http-range').ContentRange;
var Range = require('http-range').Range;
// Parsing and creating 'Content-Range' header
ContentRange.prototype.parse('bytes 0-49/50'); // Content-Range: bytes 0-49/50
new ContentRange('bytes', '0-49', 50).toString(); // => bytes 0-49/50
// Parsing and creating 'Range' header
Range.prototype.parse('bytes=0-49'); // Range: bytes=0-49
new Range('bytes', '0-49'); // => bytes=0-49
For more usages check the test files.
unit
{String} Usually 'bytes', but can be any tokenrange
{RangeSpec|String} A RangeSpec instance, a string like '0-49' or '*' if unknownlength
{Number|'*'} The total length of the full entity-body or '*' if this length is unknown or difficult to determine
Throws error if arguments are invalid.
unit
{String}range
{RangeSpec}length
{Number|null} Null if unknown
toString()
{String} Return a valid string valueparse(input)
{ContentRange} Parse an input string. Throws error if invalid
Content-Range: bytes 0-49/50
Content-Range: bytes 0-49/*
Content-Range: bytes */50
Content-Range: bytes */*
unit
{String} Usually 'bytes', but can be any tokenranges
{RangeSpec[]|String} An array of RangeSpec instances or a string like '0-49[,50-99][...]'
Throws error if arguments are invalid.
unit
{String}ranges
{RangeSpec[]}
toString()
{String} Return a valid string valueparse(input)
{Range} Parse an input string. Throws error if invalid
Range: bytes=0-49
Range: bytes=0-49,50-99,-30
Range: bytes=1-
Range: bytes=-50
low
{Number|undefined}high
{Number|undefined}size
{Number|undefined} For validation only, optional
Throws error if arguments are invalid.
low
{Number|undefined}high
{Number|undefined}
toString()
{String} Return a valid string valueparse(input)
{RangeSpec} Parse an input string. Throws error if invalid
*
0-49
-49
34-
$ make test