API
Python, R and Julia share libcozip; JavaScript reads archives with fetch. This page covers their common rules. Each language page has types and examples.
How it works
A cozip is an ordinary ZIP with a small index at byte 0 that points to a Parquet manifest. The manifest lists each file's byte range and can carry your metadata. The figures below compare its size and read path with an ordinary ZIP.
The figures use one reference archive, measured on a laptop: a million files of 1,000 bytes, 000000.tif to 999999.tif, with six columns of metadata. The code examples further down use cities.zip, a small public archive on Hugging Face and Source Cooperative, so you can run them. Step through each figure with the names under it or the arrow keys.
A ZIP. Every cozip is an ordinary ZIP, so unzip lists and extracts it. Each file sits after its local header, stored as it is, and the Central Directory at the end lists every entry: 56 MB for these million files.
The index. The first entry, __cozip__, starts at byte 0. Its 41-byte payload at byte 51 gives the offset and size of the manifest, so a reader finds it without the Central Directory.
The manifest. __metadata__ is a Parquet file with one row per file: name, offset and size, then any columns you add. Here they are a split, a date, cloud cover, a position and a land cover class, 11.7 MB in all.
A file. A row gives the exact bytes of its file: 000002.tif is the 1,000 bytes at 2,212, one range request away.
The hash. Bytes 43 to 50 hold an FNV-1a hash of the index and the last 32 KiB, where the end records are, so a truncated upload or a rewritten end is caught before any offset is used. An archive under 32,819 bytes is padded to that size, so the tail never reaches the hash.
An ordinary ZIP keeps its table of contents, the Central Directory, at the end, so finding one file takes three requests one after another. The directory has a 46-byte record plus the name for every file, 56 MB for the reference archive, and no columns to choose files by.
First read. An ordinary ZIP reader starts with the end record, only to learn where the directory is. A cozip reader asks for the first 64 KiB, where the index is.
Second read. The ZIP reader needs the whole Central Directory, 56 MB for the million files. The cozip reader needs only the manifest, 11.7 MB with all its metadata, and skips this read when the manifest came in the first one.
Third read. Both now know where the file is. The cozip reader got there without the Central Directory, and its manifest has columns to choose files by.
A cozip reader never parses the Central Directory, which stays valid for ZIP tools. The index also holds a profile byte. These packages write and read Flat archives, whose only indexed file is the manifest, and the TACO package writes and reads TACO archives. The specification defines every byte.
What the reader fetches instead of the directory is the manifest, a Parquet table.
Smaller. For the same million files, the manifest is 11.7 MB against 56 MB of Central Directory, and it carries six columns of metadata the directory has no room for. With only name, offset and size, it is 0.5 MB.
Any metadata. A directory record holds what the ZIP format fixes: a name, sizes, a CRC and a date. A manifest row holds name, offset and size, then any column you add.
Queryable. The manifest is Parquet, so DuckDB, pandas or Polars filter it like any table. This query keeps 3,368 of the million files in 35 ms on the manifest itself, or in 0.19 s on the table cozip.read returns.
Listing the plain ZIP of the same million files with Python's zipfile takes 1.6 s and gives names and sizes only. cozip.read returns the whole manifest, with a location for every file, in 0.32 s. All timings are on a laptop, from local disk.
Python, R and Julia read through one C reader, in four steps.
- Both ends, at once. It asks for the first 64 KiB and the last 32 KiB together. The head holds the
__cozip__header and the index, and the tail holds the ZIP end records. - Checks. Before it trusts an offset, it checks the header, the index and the profile in the order of section 8.5, recomputes the integrity hash, and requires the end record to be the last 22 bytes. A failure stops the read with the code section 9 gives it.
- The manifest. If the manifest lies in either range, the reader already has it, as with any archive up to 64 KiB. Otherwise one more request fetches it with its local header, which must match the index.
- Your files. The manifest is now a table in memory, so filtering it costs no request. Each file you open is one range request, or one for a run of neighbouring files.
| archive | requests before the first file |
|---|---|
| The manifest lies in the first 64 KiB or the last 32 KiB | 2, sent at once |
| Any other Flat archive, however many files it holds, such as the reference archive | 3, the two ends, then the manifest |
If the server sends a strong ETag, the later requests carry it in If-Match, so an archive replaced between two requests fails the read. Without one, the check of the manifest's local header can still catch a replaced archive, but not every replacement of the same size.
The JavaScript reader makes the same checks. It sends its ranges one at a time and skips the ones the first response already covers, so a small archive takes one request. Its page lists them.
Languages
| language | install | tables |
|---|---|---|
| Python | pip install cozip | pyarrow in, pandas out |
| R | install.packages("cozip", repos = "https://asterisk-labs.r-universe.dev") | Arrow in, tibble out |
| Julia | Pkg.add("Cozip"), after adding the Asterisk registry | any Tables.jl table in, DataFrame out |
| C | vendor core/, or a release library | entry arrays in, manifest bytes out |
| JavaScript | npm install @asterisk-labs/cozip | reads only, plain objects out |
Calls
| call | Python, R, Julia | C | does |
|---|---|---|---|
| write | write, also named create | cozip_write_flat | Writes an archive from a table of names, paths and your columns. |
| plan | stage_metadata | cozip_plan_flat | Computes every offset without writing, and returns the manifest table. |
| build | stage_create | cozip_write_flat | Writes an archive around a manifest Parquet you wrote yourself. |
| read | read | cozip_read_flat_metadata, cozip_location_base | Verifies the index, returns the manifest and builds the locations. |
| verify | verify | cozip_verify | Checks the index and the integrity hash of an archive of any profile, without fetching the manifest. |
JavaScript has read and verify. The TACO package writes TACO archives through cozip_plan_taco and cozip_write_taco, a contract between the two projects outlined on the C page.
Write
The writer takes a table with one row per file. name is the file's name in the archive, path is where it is on disk, and every other column goes into the manifest, in its order.
Your table. One row per file: its name in the archive, its path on disk, and any columns you want in the manifest.
Plan. Before it writes a byte, the planner computes every offset from the names and the file sizes, and drops path. stage_metadata stops here and gives you this table.
Files. The index goes first, then the files in table order, each after its local header and stored as it is.
Manifest. The table goes after the last file as Parquet, so its size never moves an offset. With stage_create it is the Parquet file you wrote. The Central Directory and the end record close the ZIP.
Check. Under a temporary name, the writer reads the archive back, compares it with the plan, patches the hash into bytes 43 to 50 and renames it over the output.
Files are stored in table order. Sort the table first, by split, tile or date, so that files read together sit next to each other and can come back in one request.
Before it writes a byte, the writer refuses:
- a table with no rows, or without
nameandpath; - a column named
offset,size,cozip:locationortaco:locationin any letter case, since the writer and the reader compute them; - two columns whose names differ only in case, which DuckDB cannot tell apart when it reads the manifest;
- a name that breaks the name rules, or one of the reserved names
__cozip__,__metadata__and__cozip_padding__; - a missing or empty file, and an output that is also one of the sources.
The archive is written under a temporary name, checked against the plan, hashed, then renamed over the output, so a failed write leaves an existing file untouched. A source whose size changes during the write is an error. The C page lists every check.
In two stages
write writes a compressed manifest with the Parquet writer of each language. To choose your own writer or options, such as GeoPandas for a GeoParquet manifest or a set row group size, split the call in two.
stage_metadataplans the archive without writing anything. It returns the manifest table, withname, thenoffsetandsizeas uint64, then your columns, and the(name, path)pairs in the same order.pathis dropped, and the schema metadata of the input is kept, so a GeoParquetgeokey survives.- Write that table as a Parquet file with any library.
stage_createwrites the archive with that file stored byte for byte as__metadata__. It never rewrites it, so its compression, row groups and key-value metadata stay as you wrote them.
The Parquet must keep name as a string and offset and size as uint64 (spec 13.3), and must not hold path, a location column or two names that differ only in case. With validation on, the default, stage_create plans the paths again and stops at the first row whose name, offset or size differs. Turning it off skips only that comparison: a wrong manifest then makes a valid ZIP whose rows point at the wrong bytes.
Keep the pairs in the manifest's row order. If you sort or filter the table between the two calls, apply the same order to the pairs, or plan again. Each call reads the sizes from disk, so with validation on, a file that changed in between shows up as a mismatch.
Read
read returns the Flat manifest with one row per file: name, offset, size, your columns and cozip:location. Native reads take two or three requests; JavaScript takes one to three. Other profiles fail with PROFILE in the native bindings and UNKNOWN_PROFILE in JavaScript. Read TACO archives with the TACO package.
| source | An ASCII path or URL in the native bindings; an ASCII HTTP(S) URL in JavaScript. |
|---|---|
| columns | The extra columns to return. name, offset and size always come back. Names are matched with case, and one the manifest does not have is an error. cozip:location, taco:location and cozip:gdal_vsi in the list are ignored. Left out, every column comes back. |
| location | False leaves out cozip:location. |
Python, R and Julia decode the manifest with DuckDB. Extension autoloading and autoinstall are off, so DuckDB downloads and loads nothing, and Hive partitioning is off, so a key=value folder in the path adds no column. A stored cozip:location, taco:location or cozip:gdal_vsi column, which no conforming writer produces, is dropped in any case and the location is computed again. A manifest with two columns that differ only in case is refused.
Sources
cozip:location joins the byte range of a row with the source of the archive.
The range. offset and size come from the row, so /vsisubfile/2212_1000, means 1,000 bytes from byte 2,212 of what follows.
The archive. The rest is the source you passed to read, wrapped for GDAL. The table below gives the wrapping for each kind of source.
Open. GeoPandas, rasterio, terra and ogrinfo open the path and read only those bytes. Nothing is extracted, and the path is built at read time, never stored.
Python, R, Julia and C read through Karu, which takes these sources. The archive part of the location repeats the source as given, wrapped for GDAL.
| source | archive part of the location |
|---|---|
data/tiles.zip | data/tiles.zip, relative as given |
~/tiles.zip | the same path under the home directory |
file:///data/tiles.zip | /data/tiles.zip |
https://host/tiles.zip | /vsicurl/https://host/tiles.zip |
s3://bucket/tiles.zip, also s3a://, s3n:// | /vsis3/bucket/tiles.zip |
gs://bucket/tiles.zip, also gcs:// | /vsigs/bucket/tiles.zip |
az://container/tiles.zip, also azure:// | /vsiaz/container/tiles.zip |
abfs://container/tiles.zip, also abfss:// | /vsiadls/container/tiles.zip |
hf://datasets/org/repo@v1/tiles.zip | /vsicurl/https://huggingface.co/datasets/org/repo/resolve/v1/tiles.zip, with main when no revision is given and the path percent-encoded |
source://account/product/tiles.zip | /vsicurl/https://data.source.coop/account/product/tiles.zip |
/vsis3/bucket/tiles.zip and the other /vsi prefixes Karu knows | unchanged |
A relative path stays relative, so read with an absolute path or a URL when the locations will be used from another directory or machine. The JavaScript reader takes http:// and https:// URLs only.
Credentials
Karu looks for credentials where the usual tools keep them, and its configuration page lists every option. DuckDB secrets are not used.
| store | credentials |
|---|---|
| Hugging Face | HF_TOKEN, or the token file huggingface-cli login writes |
| S3 | AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, AWS_PROFILE with ~/.aws, web identity, container or instance credentials |
| GCS | GOOGLE_APPLICATION_CREDENTIALS, gcloud's application default credentials, or metadata credentials |
| Azure | AZURE_STORAGE_CONNECTION_STRING, or AZURE_STORAGE_ACCOUNT with a key, a SAS token or a client secret |
GDAL needs credentials of its own to open a private location. The JavaScript reader uses fetch, so it reads public and presigned URLs.
Verify
verify checks the access path of any profile, TACO included, without decoding its manifest. It accepts unknown profile values, as spec 7.1 allows. Native bindings accept the sources below; JavaScript accepts HTTP(S). It returns nothing when its checks pass and names the first rule that fails.
| check | error |
|---|---|
the 51-byte __cozip__ header | INVALID_LFH |
| an archive of at least 32,819 bytes | ARCHIVE_TOO_SMALL |
| the index magic and version | INVALID_MAGIC, UNSUPPORTED_VERSION |
| the integrity hash over the index and the last 32 KiB | HASH_MISMATCH |
| a comment-free end record | INVALID_ZIP_STRUCTURE |
| index sections that fill its payload exactly | TRUNCATED_INDEX, INVALID_INDEX |
indexed names that follow the name rules, none of them __cozip__, __cozip_padding__ or repeated | INVALID_NAME, DUPLICATE_NAME |
| indexed ranges that are non-empty and lie inside the archive | INVALID_OFFSET |
It uses the first 64 KiB, the last 32 KiB and any missing index bytes. JavaScript reuses the first response when it holds the whole archive. The check does not parse the Central Directory, compare indexed names with ZIP entries, enforce profile rules or check payloads. A changed payload outside the hash window can pass.
cozip.verify("https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip") # None
Open a file
A row's file is the size bytes that start at offset, stored as they were. GDAL opens it through cozip:location, so rasterio, terra, GeoPandas and other GDAL-based readers need no extraction:
ogrinfo -ro -so -al "/vsisubfile/1092_172,/vsicurl/https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip"
Any client that reads a byte range reads it too. HTTP ranges include their last byte, so the range is offset to offset + size - 1, and this returns the 172 bytes of cities/paris.geojson:
curl -L -r 1092-1263 https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip
Files next to each other come back in one request. Fetch from the first offset to the end of the last file and slice. The bytes between two files are a local header, 30 bytes plus the name, and 20 more for a ZIP64 entry.
GeoParquet manifests
A manifest with a geometry column and the geo key is a GeoParquet file (spec 13.6). Readers that know GeoParquet, such as DuckDB, GeoPandas and the playground map, can pick files by location before fetching any. The others see an ordinary manifest.
Without crs in the geo key, the coordinates are longitude and latitude, OGC:CRS84. Python, R and Julia return the geometry as WKB without the CRS, and JavaScript returns a GeoJSON geometry. Each language page shows how to write one.
Errors
Each binding checks its arguments and tables before it calls C, and raises its own error type. libcozip reports the rest with a status name, which is the code from section 9 of the specification where it has one. Each language page shows how the two look.
| error | cause | fix |
|---|---|---|
| missing required column(s) | The input has no name or no path. | Add both. |
| reserved column(s) | The input has offset, size or a location column, in any case. | Drop it. The writer computes it. |
| columns that differ only in case | Such as label and Label. | Rename one. |
| duplicate name | Two rows have the same name. | Make the names unique. |
| source not found | A path does not point at a file. | Check the paths. |
| name mismatch at row | The pairs passed to stage_create are not in the manifest's order. | Reorder them, or plan again. |
| unknown column(s) | columns names a column the manifest does not have. | Ask only for columns it has. |
INVALID_ARGUMENT | The C writer refused an input: an empty file, a non-ASCII or absolute name, an output that is also a source. | Fix the input the message names. |
IO, NOT_FOUND | A missing file, a failed transfer, or a remote object that does not exist. | Check the path, the URL and the credentials. |
ARCHIVE_TOO_SMALL | Fewer than 32,819 bytes, often an HTML error page. | The source is not a cozip. |
INVALID_LFH | The first 51 bytes are not the __cozip__ header. | The source is not a cozip. |
INVALID_MAGIC, UNSUPPORTED_VERSION | The index does not start with CZIP, or has a version other than 1. | The source is not a cozip, or a newer one. |
PROFILE | The archive is not Flat. JavaScript and the specification call it UNKNOWN_PROFILE. | Read a TACO archive with the TACO package. |
HASH_MISMATCH | The hash does not match the index and the last 32 KiB. | The archive was modified, truncated or re-encoded after it was written. |
INVALID_ZIP_STRUCTURE | The archive does not end with a comment-free end record. | Remove the ZIP comment, or the bytes appended after the archive. |
TRUNCATED_INDEX, INVALID_INDEX, INVALID_OFFSET | The index does not fit or fill its payload, is not one entry named __metadata__ for read, or points outside the archive. | The archive is damaged. Write it again. |
INVALID_NAME, DUPLICATE_NAME | verify found an indexed name that breaks the name rules or repeats. | The archive is damaged or came from a writer that does not follow the specification. |
MISSING_ENTRY | The local header before the manifest does not match the index. | The index points at the wrong bytes, or the archive changed during the read. |
Hosting
Upload the .zip to a bucket, Hugging Face or Source Cooperative. Publish a new version at a new key or revision, because readers may hold offsets from the old one, and pin revisions in tests and training runs. For a collection that changes in parts, use several archives. Their manifests concatenate, because each cozip:location names its archive.
The server must answer range requests with the stored bytes.
| requirement | why |
|---|---|
Answer Range with 206 and a valid Content-Range: bytes start-end/total. | Readers fetch a few small ranges. The JavaScript reader takes the archive size from Content-Range and checks every response against the range it asked for, accepting an end clamped to the last byte. |
Apply no Content-Encoding on the fly. | Offsets, sizes and the hash refer to the stored bytes. |
| Keep the object unchanged during a read. | A 412, a new ETag or a new size between two responses fails the read. |
For browsers, allow the Range header across origins and expose Content-Range with Access-Control-Expose-Headers. | Otherwise the browser hides the header and the read fails with range response has no valid Content-Range header. |
For browsers, allow If-Match when ETag is exposed. | The reader sends a strong ETag back as If-Match, and the preflight would refuse it. |
Hugging Face and Source Cooperative do this for public files. An S3, GCS or Azure bucket serves ranges as stored, unless the object was uploaded with a Content-Encoding, and needs a CORS rule only for browsers. To check an upload, run verify on its URL, or paste a public URL into the playground.
SQL with DuckDB
The optional cozip_reader extension reads manifests in SQL and queries a Parquet file stored inside an archive in place. It lives in its own repository with its own versions, and nothing in these packages installs or loads it. Its README lists its functions.
INSTALL cozip FROM community;
LOAD cozip;
SELECT name, offset, size
FROM read_flat('https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip')
WHERE continent = 'Europe';