@cotar/core

中文文档
6.0.1发布于 2023/12/12MITTypeScriptES Module近 30 天下载 2373

Given a .tar with a .index using HTTP range requests fetch only the portion of the tar that contains the bytes of the file.

原始使用文档

Cloud optimised TAR @cotar/core

Given a .tar with a .index using HTTP range requests fetch only the portion of the tar that contains the bytes of the file.

For example @cotar/core can fetch a 1KB file from a 100GB tar file with only 1 HTTP range request and only download 1KB. Assuming the tar index is loaded into memory.

Usage

To fetch a single tile, the index has to be loaded into memory then the cotar object provides a get(fileName) interface to access any file inside the tar

import { Cotar } from '@cotar/core';
import { SourceUrl } from '@chunkd/source-url';

const source = new SourceUrl('s3://linz-basemaps/topographic.tar.co');
const cotar = Cotar.fromTar(source);

// Fetch a gzipped PBF file from  a tar
const bytes = await cotar.get(`tiles/z10/5/5.pbf.gz`);

Creating indexes

Indexes can be created using the @cotar/cli package or programmatically using the CotarIndexBuilder

import { CotarIndexBuilder } from '@cotar/builder';
import * as fs from 'fs/promises';

const fd = await fs.open('tarFile.tar', 'r');
const res = await CotarIndexBuilder.create(fd, CotarIndex.Binary);
await fs.write('tarFile.tar.index', res.buffer);
await fd.close();

版本与发布记录

@cotar/core 共发布 15 个版本,首次发布于 2021/04/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.1latest2023/12/122 年前
5.5.02022/11/153 年前
5.4.02022/07/074 年前
5.3.02022/03/174 年前
5.2.02022/03/144 年前
5.1.12021/11/304 年前

关于 @cotar/core 的常见问题

@cotar/core 是什么?

Given a .tar with a .index using HTTP range requests fetch only the portion of the tar that contains the bytes of the file.

如何安装 @cotar/core?

在项目目录运行 npm install @cotar/core,或使用 pnpm add / yarn add / bun add。

@cotar/core 支持 TypeScript 吗?

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

@cotar/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cotar/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^12.20.0 || ^14.13.1 || >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cotar/core 可以商用吗?

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

@cotar/core 的下载量有多少?

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

@cotar/core 还在维护吗?

最新版本 6.0.1 发布于 2023/12/12(2 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。