pax_global_header00006660000000000000000000000064122044515600014511gustar00rootroot0000000000000052 comment=7d1cd72a1bd10c1b69d2fdde9863729e513ebe13 visionmedia-node-range-parser-7d1cd72/000077500000000000000000000000001220445156000177445ustar00rootroot00000000000000visionmedia-node-range-parser-7d1cd72/.gitignore000066400000000000000000000000151220445156000217300ustar00rootroot00000000000000node_modules visionmedia-node-range-parser-7d1cd72/.npmignore000066400000000000000000000000051220445156000217360ustar00rootroot00000000000000test visionmedia-node-range-parser-7d1cd72/History.md000066400000000000000000000003561220445156000217330ustar00rootroot00000000000000 0.0.4 / 2012-06-17 ================== * changed: ret -1 for unsatisfiable and -2 when invalid 0.0.3 / 2012-06-17 ================== * fix last-byte-pos default to len - 1 0.0.2 / 2012-06-14 ================== * add `.type` visionmedia-node-range-parser-7d1cd72/Makefile000066400000000000000000000001311220445156000213770ustar00rootroot00000000000000 test: @./node_modules/.bin/mocha \ --reporter spec \ --require should .PHONY: testvisionmedia-node-range-parser-7d1cd72/Readme.md000066400000000000000000000042601220445156000214650ustar00rootroot00000000000000 # node-range-parser Range header field parser. ## Example: ```js assert(-1 == parse(200, 'bytes=500-20')); assert(-2 == parse(200, 'bytes=malformed')); parse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }])); parse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }])); parse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }])); parse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }])); parse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }])); parse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }])); parse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }])); parse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }])); parse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }])); parse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }])); parse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }])); ``` ## Installation ``` $ npm install range-parser ``` ## License (The MIT License) Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.visionmedia-node-range-parser-7d1cd72/index.js000066400000000000000000000016301220445156000214110ustar00rootroot00000000000000 /** * Parse "Range" header `str` relative to the given file `size`. * * @param {Number} size * @param {String} str * @return {Array} * @api public */ module.exports = function(size, str){ var valid = true; var i = str.indexOf('='); if (-1 == i) return -2; var arr = str.slice(i + 1).split(',').map(function(range){ var range = range.split('-') , start = parseInt(range[0], 10) , end = parseInt(range[1], 10); // -nnn if (isNaN(start)) { start = size - end; end = size - 1; // nnn- } else if (isNaN(end)) { end = size - 1; } // limit last-byte-pos to current length if (end > size - 1) end = size - 1; // invalid if (isNaN(start) || isNaN(end) || start > end || start < 0) valid = false; return { start: start, end: end }; }); arr.type = str.slice(0, i); return valid ? arr : -1; };visionmedia-node-range-parser-7d1cd72/package.json000066400000000000000000000010021220445156000222230ustar00rootroot00000000000000{ "name": "range-parser", "author": "TJ Holowaychuk (http://tjholowaychuk.com)", "description": "Range header field string parser", "version": "0.0.4", "repository": { "type": "git", "url": "https://github.com/visionmedia/node-range-parser.git" }, "main": "index.js", "dependencies": {}, "devDependencies": { "mocha": "*", "should": "*" }, "licenses": [ { "type": "MIT", "url": "https://github.com/visionmedia/node-range-parser#license" } ] } visionmedia-node-range-parser-7d1cd72/test/000077500000000000000000000000001220445156000207235ustar00rootroot00000000000000visionmedia-node-range-parser-7d1cd72/test/range-parser.js000066400000000000000000000023361220445156000236530ustar00rootroot00000000000000 var parse = require('..') , assert = require('assert'); function arr(type, arr) { arr.type = type; return arr; } describe('parseRange(len, str)', function(){ it('should parse range strings', function(){ assert(-1 == parse(200, 'bytes=500-20')); assert(-2 == parse(200, 'malformed')); parse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }])); parse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }])); parse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }])); parse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }])); parse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }])); parse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }])); parse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }])); parse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }])); parse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }])); parse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }])); parse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }])); }) })