Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A modified version of parseRange in connectjs to deal with range requests of the form bytes=a-b, c-d where a,b,c and d are all numbers, and while a < b and c < d, there is not necessarily a correspondence between a and c or b and d.
exports.parseRange = function(size, str){
var valid = true;
console.log('Requested range: ' + str);
var arr = str.substr(6).split(',').map(function(range){
console.log(range);
var range = range.split('-')
, start = parseInt(range[0], 10)
, end = parseInt(range[1], 10);
// -500
if (isNaN(start)) {
start = size - end;
end = size - 1;
// 500-
} else if (isNaN(end)) {
end = size - 1;
}
// Invalid
if (isNaN(start) || isNaN(end) || start > end || start < 0) {
valid = false;
}
return {
start: start,
end: end
};
});
if (valid) {
if (arr.length > 1) {
return [ {
start: Math.min(arr[0].start, arr[1].start),
end: Math.max(arr[0].end, arr[1].end)
} ];
} else {
return arr;
}
} else {
return null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.