Sha256: 889610078a526f817b884cbb92ec787be17168902997a931c39243d2575c2372

Contents?: true

Size: 921 Bytes

Versions: 31

Compression:

Stored size: 921 Bytes

Contents

/**
 * 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;
};

Version data entries

31 entries across 31 versions & 4 rubygems

Version Path
webpack_rails-2.0.1 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-2.0.0 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.3.1 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.3.0 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.2.2 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.2.1 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.2.0 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-static/node_modules/send/node_modules/range-parser/index.js
webpack_rails-1.1.1 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.1.0 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.0.1 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
webpack_rails-1.0.0 lib/webpack_rails/node_modules/express/node_modules/range-parser/index.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-static/node_modules/send/node_modules/range-parser/index.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-static/node_modules/send/node_modules/range-parser/index.js
gulp_assets-1.0.0.pre.5 template/node_modules/webpack-dev-server/node_modules/express/node_modules/range-parser/index.js
gulp_assets-1.0.0.pre.4 template/node_modules/webpack-dev-server/node_modules/express/node_modules/range-parser/index.js
gulp_assets-1.0.0.pre.3 template/node_modules/webpack-dev-server/node_modules/express/node_modules/range-parser/index.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-static/node_modules/send/node_modules/range-parser/index.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-static/node_modules/send/node_modules/range-parser/index.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/serve-static/node_modules/send/node_modules/range-parser/index.js