# req.range

Range 标头解析器。

# 概要

req.range(size[, options])

# 描述

Range 标头解析器。

size 参数是资源的最大大小。

options 参数是一个可以具有以下属性的对象。

属性 类型 描述
combine 布尔值 指定是否应合并重叠和相邻范围,默认为 false。当 true 时,范围将被组合并返回,就好像它们在标题中以这种方式指定一样。

将返回一个范围数组或指示解析错误的负数。

  • -2表示格式错误的标头字符串
  • -1表示无法满足的范围
// parse header from request
const range = req.range(1000)

// the type of the range
if (range.type === 'bytes') {
  // the ranges
  range.forEach((r) => {
    // do something with r.start and r.end
  })
}
Last Updated: 3/22/2023, 7:27:28 PM