JavaScript
- Package
@asterisk-labs/cozipon npm, an ES module for Node 20 or newer and modern browsers - Reader only
npm install @asterisk-labs/cozip
The package reads Flat archives over HTTP. It has no writer and no native code. hyparquet decodes the manifest, with Snappy, gzip, Brotli, zstd and LZ4 compression. Types ship in types/index.d.ts. The rules every reader shares are on the API overview.
Reading
read
read(url, { columns, location = true } = {}) -> Promise<object[]>
Reads the manifest of a Flat archive and returns one plain object per file, in manifest order. The arguments are described under Read.
| url | A non-empty ASCII string that starts with http:// or https://. s3://, gs://, file:// and local paths are refused, so use a public or presigned HTTPS URL. Percent-encode any other character first. |
|---|---|
| columns | An array of non-empty strings. The listed columns come after name, offset and size and before cozip:location. An unknown name rejects the read. |
| location | A boolean. |
Options must be an object, not an array. Wrong types throw TypeError before any fetch.
import { read } from "@asterisk-labs/cozip";
const url = "https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip";
const rows = await read(url, { columns: ["label", "continent", "geometry"] });
rows[0];
{
name: 'cities/lima.geojson',
offset: 141n,
size: 181n,
label: 'Lima',
continent: 'South America',
geometry: { type: 'Point', coordinates: [ -77.04, -12.05 ] },
'cozip:location': '/vsisubfile/141_181,/vsicurl/https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip'
}
Requests
Unlike the native reader, which asks for both ends at once, this one sends its ranges in order and skips the ones an earlier response already covers.
Range: bytes=0-65535, for the local header, the 41-byte Flat index and the profile.- The last 32 KiB, for the integrity hash.
- The manifest and up to 1,066 bytes before it, for its local header.
cities.zip fits in the first request, and larger archives take two or three. The reader checks each Content-Range against the range it asked for, and sends a strong ETag back as If-Match, as How it works describes.
verify
verify(url) -> Promise<void>
Checks an archive of any profile, as described under Verify. Resolves to undefined, or rejects with an error whose code names the broken rule.
Rows
hyparquet decides the JavaScript type of each value.
- 64-bit integers are
BigInt,offsetandsizeincluded. Mixing aBigIntwith aNumberthrowsTypeError: Cannot mix BigInt and other types. - Doubles and 32-bit integers are numbers, and strings are strings.
- A GeoParquet geometry becomes a GeoJSON geometry object, such as
{ type: "Point", coordinates: [-77.04, -12.05] }. cozip:locationis/vsisubfile/{offset}_{size},/vsicurl/{url}, with the URL exactly as given.
Reading a file
const lima = rows.find((row) => row.name === "cities/lima.geojson");
const response = await fetch(url, {
headers: { Range: `bytes=${lima.offset}-${lima.offset + lima.size - 1n}` },
});
response.status; // 206
JSON.parse(await response.text()).properties.id; // "lima"
Keep the arithmetic in BigInt, as - 1n does, or convert once with Number(row.offset). Both are exact below 253, and the reader refuses a Content-Range beyond that, so every offset it returns is exact.
In the browser
The package needs no build step, and a page can import it from a CDN, as the playground does.
import { read } from "https://esm.sh/@asterisk-labs/cozip@2026.11.30";
The server must meet the hosting requirements, CORS included. A server that ignores Range and returns the whole object with 200 still works, because the reader takes everything from that one response.
Errors
Wrong argument types raise TypeError. Malformed archives raise Error with a code, the names on the API overview, with UNKNOWN_PROFILE for a profile other than Flat. HTTP and Parquet errors have no code. Messages omit URL credentials, queries and fragments. These come only from this reader:
| message, in part | cause |
|---|---|
only http(s) URLs are supported | A URL that is not HTTP or HTTPS. |
URL contains non-ASCII characters | Percent-encode the URL first. |
HTTP 403 Forbidden for ... | Any status other than 200 or 206, such as missing permissions or an expired presigned URL. |
columns not in the manifest: "missing" | A name in columns that the manifest does not have. |
range response has no valid Content-Range header | CORS does not expose Content-Range, or a proxy rewrote the response. |
archive changed while reading, archive size changed while reading | The object was replaced during the read. |
Development
cd javascript
npm install
npm run types # tsc, writes types/index.d.ts from the JSDoc
npm test # node --test; some tests fetch a fixture from GitHub
make javascript runs the same steps after make sync. The package version follows the repository's VERSION file.