要取出一块瓦片, 索引必须装入内存, 然后 cotar 对象提供 a get(fileName) 接口以访问 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`);
创建索引
索引可以使用 @cotar/cli 软件包或程序 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();