@gmod/http-range-fetcher

中文文档
5.0.7发布于 2026/01/15MITTypeScriptESM + CJS近 30 天下载 1.8万

caching, aggregating fetch manager for doing lots of HTTP range requests

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Table of Contents
  4. Academic Use
  5. License
  6. Note

@gmod/http-range-fetcher

NPM version Build Status

Cache/manager for HTTP byte-range requests that merges requests together and caches results. Designed for applications that request lots of small byte ranges over HTTP that are often adjacent to each other.

Works both in node or webpack/browserify. Respects HTTP caching semantics, with the exception of setting a default minimum TTL of 1 second on requests that are not really supposed to be cached (e.g. Cache-Control: no-cache). You can turn that behavior off by setting minimumTTL to 0 though.

Install

$ npm install --save http-range-fetcher

Usage

const { HttpRangeFetcher } = require('http-range-fetcher')

const cache = new HttpRangeFetcher({})
cache.getRange('http://foo.bar/baz.bam', 20, 10).then(response => {
  assert(response.buffer.length === 10)
  assert(response.headers['content-range'] === '20-29/23422')
  // response objects contain `headers` and `buffer`.  the `headers` object
  // contains the original headers that came from the server in response to the
  // aggregated call, except the Content-Range header has been overwritten
  // to match the requested range, and it adds a X-Resource-Length header that
  // conveniently gives the total length of the remote resource so you don't
  // have to parse the Content-Range header.
  assert(response.headers['x-resource-length'] === '23422')
})

// these will be aggregated behind the scenes
// as a single request for a big chunk of the remote file,
// which will be cached to satisfy subsequent requests
Promise.all([
  cache.getRange('http://foo.bar/baz.bam', 20, 10),
  cache.getRange('http://foo.bar/baz.bam', 30, 10),
  cache.getRange('http://foo.bar/baz.bam', 40, 10),
  cache.getRange('http://foo.bar/baz.bam', 50, 10),
  cache.getRange('http://foo.bar/baz.bam', 60, 10),
  cache.getRange('http://foo.bar/baz.bam', 70, 10),
]).then(fetchResults => {
  fetchResults.forEach(res => assert(res.buffer.length === 10))
})

Table of Contents

Academic Use

This package was written with funding from the NHGRI as part of the JBrowse project. If you use it in an academic project that you publish, please cite the most recent JBrowse paper, which will be linked from jbrowse.org.

License

MIT © Robert Buels

Note

Renamed http-range-fetcher -> @gmod/http-range-fetcher in 2024

版本与发布记录

@gmod/http-range-fetcher 共发布 11 个版本,首次发布于 2024/06/21;过去 12 个月发布了 4 个版本。

版本发布日期距今
5.0.7latest2026/01/1510 个月前
5.0.62025/12/2110 个月前
5.0.52025/12/1810 个月前
5.0.32025/12/1810 个月前
5.0.12025/05/141.5 年前
5.0.02025/04/301.5 年前

关于 @gmod/http-range-fetcher 的常见问题

@gmod/http-range-fetcher 是什么?

caching, aggregating fetch manager for doing lots of HTTP range requests

如何安装 @gmod/http-range-fetcher?

在项目目录运行 npm install @gmod/http-range-fetcher,或使用 pnpm add / yarn add / bun add。

@gmod/http-range-fetcher 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gmod/http-range-fetcher 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gmod/http-range-fetcher 可以商用吗?

@gmod/http-range-fetcher 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gmod/http-range-fetcher 的下载量有多少?

根据 npm 官方下载统计,@gmod/http-range-fetcher 在 2026/10/17 – 2026/11/15 这 30 天内被下载 18,122 次,日均约 604 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gmod/http-range-fetcher 还在维护吗?

最新版本 5.0.7 发布于 2026/01/15(10 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 4 个;首次发布于 2024/06/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。