index.js
function rangeParser (size, str, options) {
  if (typeof str !== 'string') {
    throw new TypeError('argument str must be a string')
  }

  var index = str.indexOf('=')

  if (index === -1) {
    return -2
  }

  // split the range string
  var arr = str.slice(index + 1).split(',')
  var ranges = []

  // add ranges type
  ranges.type = str.slice(0, index)

  // parse all ranges
  for (var i = 0; i < arr.length; i++) {
    var range = arr[i].split('-')
    var start = parseInt(range[0], 10)
    var 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 or unsatisifiable
    if (isNaN(start) || isNaN(end) || start > end || start < 0) {
      continue
    }

    // add range
    ranges.push({
      start: start,
      end: end
    })
  }

  if (ranges.length < 1) {
    // unsatisifiable
    return -1
  }

  return options && options.combine
    ? combineRanges(ranges)
    : ranges
}
function rangeParser (size, str, options) {
  if (typeof str !== 'string') {
    throw new TypeError('argument str must be a string')
  }

  var index = str.indexOf('=')

  if (index === -1) {
    return -2
  }

  // split the range string
  var arr = str.slice(index + 1).split(',')
  var ranges = []

  // add ranges type
  ranges.type = str.slice(0, index)

  // parse all ranges
  for (var i = 0; i < arr.length; i++) {
    var range = arr[i].split('-')
    var start = parseInt(range[0], 10)
    var 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 or unsatisifiable
    if (isNaN(start) || isNaN(end) || start > end || start < 0) {
      continue
    }

    // add range
    ranges.push({
      start: start,
      end: end
    })
  }

  if (ranges.length < 1) {
    // unsatisifiable
    return -1
  }

  return options && options.combine
    ? combineRanges(ranges)
    : ranges
}
function rangeParser ( size , str , options ) { if ( typeof str !== 'string' ) { throw new TypeError ( 'argument str must be a string' ) } var index = str . indexOf ( '=' ) if ( index === - 1 ) { return - 2 } // split the range string var arr = str . slice ( index + 1 ) . split ( ',' ) var ranges = [ ] // add ranges type ranges . type = str . slice ( 0 , index ) // parse all ranges for ( var i = 0 ; i < arr . length ; i ++ ) { var range = arr [ i ] . split ( '-' ) var start = parseInt ( range [ 0 ] , 10 ) var 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 or unsatisifiable if ( isNaN ( start ) || isNaN ( end ) || start > end || start < 0 ) { continue } // add range ranges . push ( { start : start , end : end } ) } if ( ranges . length < 1 ) { // unsatisifiable return - 1 } return options && options . combine ? combineRanges ( ranges ) : ranges }
Parse "Range" header `str` relative to the given file `size`.

@param {Number} size
@param {String} str
@param {Object} [options]
@return {Array}
@public
Parse Range header str relative to the given file size .