npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zarrextra

v0.2.3

Published

Extra utilities for working with zarr stores using zarrita

Readme

zarrextra

Extra utilities for working with zarr stores using zarrita.

This package provides helper functions and types for:

  • Parsing zarr store contents into a tree structure
  • Working with consolidated metadata
  • Serializing zarr tree structures
  • Registering additional Zarrita codecs, including JP2K (imagecodecs_jpeg2k)
  • Loading OME-Zarr multiscales from an existing Zarrita store for Viv-compatible viewers
  • Result type for explicit error handling

Result Type

This package includes a Result<T, E> type inspired by Rust for explicit error handling. This is a custom implementation for simplicity and to avoid dependencies. We may review using an existing Result library (such as neverthrow) in the future, but for now this provides a lightweight solution.

Installation

npm install zarrextra

Usage

import { openExtraConsolidated } from 'zarrextra';
import * as zarr from 'zarrita';

const result = await openExtraConsolidated('https://example.com/store.zarr');
// or:
// const result = await openExtraConsolidated(new zarr.FetchStore('https://example.com/store.zarr'));
if (result.ok) {
  const { zarritaStore, tree } = result.value;
  ...
  profit();
} else {
  alert(result.error);
}

API

See the TypeScript definitions for full API documentation.

Codec registration

registerJpeg2kCodec() registers decode support for the standard imagecodecs_jpeg2k codec id from the Zarr codecs registry. The default decoder uses the optional @cornerstonejs/codec-openjpeg package.

import { registerJpeg2kCodec } from 'zarrextra';

registerJpeg2kCodec();

Applications can pass a custom decoder for alternate WASM loading or tests:

import OpenJPEGJS from '@cornerstonejs/codec-openjpeg/decode';
import { createOpenJpegDecoder, registerJpeg2kCodec } from 'zarrextra';

registerJpeg2kCodec({ decoder: createOpenJpegDecoder(OpenJPEGJS) });

registerExperimentalHtj2kCodec() registers decode for experimental.openjph_htj2k (new writes) and legacy experimental.imagecodecs_htj2k fixtures. Keep datasets using either id clearly labelled until there is community/registry alignment.

import OpenJPHJS from '@cornerstonejs/codec-openjph';
import { createOpenJphDecoder, registerExperimentalHtj2kCodec } from 'zarrextra';

registerExperimentalHtj2kCodec({ decoder: createOpenJphDecoder(OpenJPHJS) });

For offline encode (fixtures, recompress), use encodeHtj2kPlane() or createOpenJphEncoder() from the same package. Python spatialdata-codec-writer uses vendored OpenJPH WASM with a persistent Node worker pool; new stores use codec id experimental.openjph_htj2k.

import { encodeHtj2kPlane } from 'zarrextra';

const plane = new Uint16Array(width * height);
// ... fill plane ...
const encoded = await encodeHtj2kPlane(plane, { width, height }, {
  reversible: false,
  quality: 75,
});

Worker-backed chunk decode (browser)

Decoding and marshalling chunk data can block the main thread for a long time. If you use @spatialdata/vis, its renderer path enables the bundled codec worker automatically in browsers. You do not need to call this API for normal vis usage.

If we find that users get unexpected results or need more control we may revise this pattern.

For lower-level browser apps using zarrextra directly, use the optional zarrextra/workers entry with @fideus-labs/fizarrita to offload chunk decode to a Web Worker pool:

import { enableWorkerChunkDecode, disableWorkerChunkDecode } from 'zarrextra/workers';

enableWorkerChunkDecode();
// ... load JP2K-backed SpatialData and render tiles ...
disableWorkerChunkDecode();

This uses a thin custom codec worker that registers zarrextra image codecs (including OpenJPEG for imagecodecs_jpeg2k and OpenJPH for experimental HTJ2K) into zarrita.registry inside the worker before fizarrita's codec handler runs. Built-in zarrita codecs (bytes, zstd, blosc, …) are also adapted to fizarrita's worker metadata shape via wrapZarrRegistryForFizarritaWorker(). Main-thread registerJpeg2kCodec() is not required for that path.

| Context | Setup | |---------|-------| | Node / CI | registerJpeg2kCodec() / registerExperimentalHtj2kCodec() on the main thread | | Browser with @spatialdata/vis | no setup for normal SpatialCanvas usage; optional ensureCodecWorkers() for eager activation | | Browser without @spatialdata/vis | enableWorkerChunkDecode() from zarrextra/workers before loading JP2K or HTJ2K data |

Optional dependencies: @fideus-labs/fizarrita, @fideus-labs/worker-pool, @cornerstonejs/codec-openjpeg, and @cornerstonejs/codec-openjph (bundled into the default worker script). Future worker entries may let applications opt into lighter worker bundles when JP2K or HTJ2K codecs are not needed.

Contributor note: new worker-backed entry points should follow the documented worker bundling pattern so consumers can use package APIs without passing private worker URLs.