获取range信息
@param  {String} str  request header range
@param  {Number} size file size
@return {Object}
183760
function getRange(str, size) {
  let index = str ? str.indexOf('=') : -1
  if (index === -1) {
    return -2
  }
  // 把range转换为数组
  let arr = str.slice(index + 1).split(',')
  let ranges = []
  // 记录range的类型
  ranges.AcceptRanges = str.slice(0, index)
  // 获取文件长度
  for (let i = 0; i < arr.length; i++) {
    let range = arr[i].split('-')
    let start = parseInt(range[0], 10)
    let end = parseInt(range[1], 10)
    // start为数字时
    if (isNaN(start)) {
      start = size - end
      end = size - 1
      // end为数字时
    } else if (isNaN(end)) {
      end = size - 1
    }
    // 结束不得大于文件大小
    if (end > size - 1) {
      end = size - 1
    }
    // start与end都为数字,且0<=start<=end
    if (!isNaN(start) && !isNaN(end) && start >= 0 && start <= end) {
      ranges.push({
        ContentRange:
          ranges.AcceptRanges + ' ' + start + '-' + end + '/' + size,
        ContentLength: end - start + 1,
        start: start,
        end: end
      })
    }
  }
  // 没有获取到有效的range值
  if (ranges.length < 1) {
    return -1
  }
  return ranges
}
563408
function getRange(start, limit, raw, store) {
      // Monitor values
      start = start || start === 0 ? parseInt(start) : null;
      limit = limit || limit === 0 ? parseInt(limit) : null;

      var data = raw == false ? store.data.asObject() : Object.assign({}, store.rootData.asObject());
      var rangeData = {};
      var isArray = store.data.__sorted && !raw;
      
      if (isArray) {
        data = raw == false ? store.data.asArray() : Object.assign({}, store.rootData.asObject());
        rangeData = [];
      }
      
      var size = Object.keys(data).length;

      if (
        start &&
        typeof start == "number" &&
        (limit || typeof limit == "number")
      ) {
        var index = 1;

        function rangeLoop(item) {
          // Check start item key
          if (index >= start && index <= limit) {
            if (isArray) {
              rangeData.push(data[item]);
            } else {
              rangeData[item] = data[item];
            }
          }
          index++;
        }
        // Loop through data object items
        if (isArray) {
          for (var i = 0; i < data.length; i++) {
            rangeLoop(i);
            if (index > limit) {
              break;
            }
          }
        } else {
          for (var key in data) {
            rangeLoop(key);
            if (index > limit) {
              break;
            }
          }
        }
      } else {
        vcomet.error.log("store", "Incorrect range values format");
      }
      // Update store data object
      store.rangeData = new Result(rangeData, store, store.data.__sorted);
      store.size = size;

    }
642666
def _read_range(self, start, end=0):
        
        # Get object part from S3
        try:
            with _handle_client_error():
                response = self._client.get_object(
                    Range=self._http_range(start, end), **self._client_kwargs)

        # Check for end of file
        except _ClientError as exception:
            if exception.response['Error']['Code'] == 'InvalidRange':
                # EOF
                return bytes()
            raise

        # Get object content
        return response['Body'].read()
62662
def handle_range_request!(length)
      if Rack.release >= "2.0"
        ranges = Rack::Utils.get_byte_ranges(request.headers["Range"], length)
      else
        ranges = Rack::Utils.byte_ranges(request.env, length)
      end

      # we support ranged requests
      response.headers["Accept-Ranges"] = "bytes"

      if ranges.nil? || ranges.length > 1
        # no ranges, or multiple ranges (which we don't support)
        response.status = 200
        range = 0..length-1
      elsif ranges.empty?
        # unsatisfiable range
        response.headers["Content-Range"] = "bytes */#{length}"
        error!(416, "Byte range unsatisfiable")
      else
        range = ranges[0]
        response.status = 206
        response.headers["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{length}"
      end

      response.headers["Content-Length"] = range.size.to_s

      range
    end
695895
function contentRange (type, size, range) {
  return type + ' ' + (range ? range.start + '-' + range.end : '*') + '/' + size
}
1048852
function getNumberingRanges(str) {
    return findUnescapedTokens(str || '', numberingToken)
    .reduce((out, range) => {
        // skip ranges that actually belongs to output placeholder or tabstops
        if (!/[#{]/.test(str[range[0] + 1] || '')) {
            const lastRange = out[out.length - 1];
            if (lastRange && lastRange[0] + lastRange[1] === range[0]) {
                lastRange[1] += range[1];
            } else {
                out.push(range);
            }
        }

        return out;
    }, []);
}
284802
function(size) {
		if (typeof(size) !== 'string') {
			return size;
		}
		
		var muls = {
				t: 1099511627776,
				g: 1073741824,
				m: 1048576,
				k: 1024
			},
			mul;

		size = /^([0-9]+)([mgk]?)$/.exec(size.toLowerCase().replace(/[^0-9mkg]/g, ''));
		mul = size[2];
		size = +size[1];
		
		if (muls.hasOwnProperty(mul)) {
			size *= muls[mul];
		}
		return size;
	}
531473
function vNumber(func, type, str, range) {
    let success   = true;
    let checkType = true;
    let errmsg;
    // 先验证类型
    if (!func(str)) {
      errmsg = localData.em_type({
        desc,
        str,
        type,
      });
      checkType = false;
      success = false;
    }
    // 再验证类型范围
    // if (range && range.min === undefined) {
    //   range.min = 0;
    // }
    if (range && (range.min === undefined || range.min < -NUMBER_MAX)) {
      range.min = -NUMBER_MAX;
    }
    if (range && (range.max === undefined || range.max > NUMBER_MAX)) {
      range.max = NUMBER_MAX;
    }
    if (success && checkType && range && (range.min !== undefined || range.max !== undefined)) {
      if (range && range.min !== undefined && range.min > Number(str)) {
        success = false;
      }
      if (success && range && range.max !== undefined && range.max < Number(str)) {
        success = false;
      }
      if (!success) {
        errmsg = localData.em_minmax({
          desc,
          type,
          opDesc: 'value',
          minOp : '>=',
          min   : range.min,
          maxOp : '<=',
          max   : range.max,
        });
      }
    }
    return { success, errmsg };
  }
801803
def _get_http(url, temp_file_name, initial_size, file_size, verbose_bool,
              progressbar, ncols=80):
    """"""
    # Actually do the reading
    req = urllib.request.Request(url)
    if initial_size > 0:
        req.headers['Range'] = 'bytes=%s-' % (initial_size,)
    try:
        response = urllib.request.urlopen(req)
    except Exception:
        # There is a problem that may be due to resuming, some
        # servers may not support the "Range" header. Switch
        # back to complete download method
        tqdm.write('Resuming download failed (server '
                   'rejected the request). Attempting to '
                   'restart downloading the entire file.')
        del req.headers['Range']
        response = urllib.request.urlopen(req)
    total_size = int(response.headers.get('Content-Length', '1').strip())
    if initial_size > 0 and file_size == total_size:
        tqdm.write('Resuming download failed (resume file size '
                   'mismatch). Attempting to restart downloading the '
                   'entire file.')
        initial_size = 0
    total_size += initial_size
    if total_size != file_size:
        raise RuntimeError('URL could not be parsed properly')
    mode = 'ab' if initial_size > 0 else 'wb'
    if progressbar is True:
        progress = tqdm(total=total_size, initial=initial_size, desc='file_sizes',
                        ncols=ncols, unit='B', unit_scale=True)

    chunk_size = 8192  # 2 ** 13
    with open(temp_file_name, mode) as local_file:
        while True:
            t0 = time.time()
            chunk = response.read(chunk_size)
            dt = time.time() - t0
            if dt < 0.005:
                chunk_size *= 2
            elif dt > 0.1 and chunk_size > 8192:
                chunk_size = chunk_size // 2
            if not chunk:
                break
            local_file.write(chunk)
            if progressbar is True:
                progress.update(len(chunk))
449165
function (req) {
    var keys = Object.keys(req.headers)

    var values = keys.map(function (key) {
      return req.headers[key]
    })

    var headers = req.method + req.url + keys.join() + values.join()

    // startline: [method] [url] HTTP/1.1\r\n = 12
    // endline: \r\n = 2
    // every header + \r\n = * 2
    // add 2 for each combined header
    return new Buffer(headers).length + (keys.length * 2) + 2 + 12 + 2
  }
32677
function header(length) {
                var res = [0x09, 0x09, 0x00, 0x00];
                res.push((length & 0x000000FF) >> 0);
                res.push((length & 0x0000FF00) >> 8);
                res.push((length & 0x00FF0000) >> 16);
                res.push((length & 0xFF000000) >> 24);
                return new Buffer(res);
            }
1195115
function getMatchRate(src, str) {
        if (typeof (src) === 'undefined' || typeof (str) === 'undefined') {
            return 0;
        }

        var maxLength = src.length > str.length ? src.length : str.length,
                matchCnt = 0;
        if (maxLength === 0) {
            return 1;
        }

        for (var i = 0; i < maxLength; i++) {
            if (str.charAt(i) === src.charAt(i)) {
                matchCnt++;
            }
        }

        if (matchCnt === 0) {
            return 0;
        }

        return matchCnt / maxLength;
    }
691529
def get_size_str(size):
    
    if size == 0:
        magnitude = 0
        level = 0
    else:
        magnitude = math.floor(math.log(size, 10))
        level = int(min(math.floor(magnitude // 3), 4))
    return ('%d' if level == 0 else '%.2f') % (float(size) / 2**(level*10)) + ' ' + SIZE_LEVEL[level]
105417
function(size) {
    var match;
    var buffer;
    if (match = size.match(/(\d+)KB/)) {
      buffer = new Buffer(parseInt(match[1]) * 1024);
    } else if (match = size.match(/(\d+)MB/)) {
      buffer = new Buffer(parseInt(match[1]) * 1024 * 1024);
    } else {
      switch (size) {
        case 'empty': buffer = new Buffer(0); break;
        case 'small': buffer = new Buffer(1024 * 1024); break;
        case 'large': buffer = new Buffer(1024 * 1024 * 20); break;
        default: return new Buffer(1024 * 1024);
      }
    }
    buffer.fill('x');
    return buffer;
  }
296073
def estimate_size_in_bytes(cls, key, value, headers):
        
        return (
            cls.HEADER_STRUCT.size + cls.MAX_RECORD_OVERHEAD +
            cls.size_of(key, value, headers)
        )
765514
function(message) {
  return {
    length: message.readInt32LE(0),
    requestId: message.readInt32LE(4),
    responseTo: message.readInt32LE(8),
    opCode: message.readInt32LE(12)
  };
}
1132950
function (string, size) {
  var start = (string.length - size)/2;
  return string.substring(start, start+size);
}