range-parser
范围报头字段解析器。
安装
这是一个 node . js 模块可通过
npm注册表. 安装是使用
npm install 命令:
$ npm install range-parser
API
var parseRange = require('range-parser')
parseRange(大小,标题,选项)
解析给定的 header 字符串, size 尺寸是否被选中
将被划分为子范围的表示。子范畴的一组
将返回或表示解析错误的负数。
-2表示格式错误的报头字符串-1表示不满意的范围
// parse header from request
var subranges = parseRange(size, req.headers.range)
// the type of the subranges
if (subranges.type === 'bytes') {
// the ranges
subranges.forEach(function (r) {
// do something with r.start and r.end
})
}
选项
这些属性在options对象中被接受。
结合
指定是否合并重叠和相邻的子区域,默认为
false. 当 true,范围将被组合并返回,就像它们一样
在header中以这种方式指定。
parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
// => [
// { start: 0, end: 10 },
// { start: 50, end: 60 }
// ]