node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Mr.Rager is a very relaxed parser written in Javascript for getting range representations from Content-Range headers. Mr.Rager won't yell about much, and if he does something went seriously wrong. If the parser experiences anything out of the ordinary it will gently degrade in behaviour of parsing, and in the instance of some really cooky headers, it will just give back a range representative of the whole file.


parse(rangeHeader, size)
returns an array where each element is an 2-element object of parsed values, the 'begining' key being the start of the range, and the 'end' key being the end of the range


var http = require('http');
var server = http.createServer(function(req, res){
    res.writeHead(200, {'content-type' : 'application/json'});
    var parsed = parse(req.headers['range'], 1000);
    console.log('Parsed "range" header as:', parsed);
    }, 3000);
}).listen(8000, function(){
    console.log('Listening on port 8000');
    host: 'localhost',
    method: 'GET',
    port: 8000,
    headers: {'range': 'bytes=500-'}}).end();