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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@manzt/zarr-lite

v0.2.0

Published

A partial Zarr Implementation for reading array chunks.

Downloads

69

Readme

zarr-lite

A minimal (& very incomplete) Zarr implementation for the browser.

Description

Here be dragons. This project is not intended to be a feature-complete implementation of Zarr, but rather an experiment to define a minimal subset of interfaces that are useful for loading Zarr in web-applications. Please use zarr.js unless you know what you are doing!

Usage

zarr-lite supports only reading array chunks and slices directly from a valid Store interface. To mimic the zarr.js API, zarr-lite exports a top-level openArray util which returns an ZarrArray object with only getRaw and getRawChunk implemented. If your use case only requires reading chunks, you should just use the /core submodule which does not support any slicing/indexing logic, and instead relies on the user to request array chunks by key directly.

Client

// ~3.6kB min + gzip
import { openArray, HTTPStore, slice } from 'https://cdn.skypack.dev/@manzt/zarr-lite';

// ~ 1.75kB min + gzip
// import { openArray, HTTPStore } from 'https://cdn.skypack.dev/@manzt/zarr-lite/core';

// open an array
(async () => {
  const store = new HTTPStore('http://localhost:8080/data.zarr');
  const z = await openArray({ store });
  console.log(z.dtype);
  // "<i4"

  console.log(z.shape); // Array shape
  // [10, 1000, 1000]

  console.log(z.chunks); // Chunk shape
  // [5, 500, 500]

  console.log(z.compressor); // Initialized compressor (null, Blosc, GZip, or Zlib)
  // Blosc { blocksize: 0, clevel: 5, cname: 'lz4', shuffle: 1 }

  // Load decoded chunk (Same API as zarr.js)
  const chunk = await z.getRawChunk('0.0.0'); // get chunk by key; can also use [0, 0, 0];
  console.log(chunk);
  // {
  //   data: Int32Array(1250000),
  //   shape: [5, 500, 500],
  //   stride: [250000, 500, 1],
  // }

  const arr = await z.getRaw([0, slice(0, 200, 2), null]); // not implemented for `/core` submodule
  console.log(arr);
  // {
  //   data: Int32Array(50000),
  //   shape: [100, 500],
  //   stride: [500, 1],
  // }
})();

Server

import numpy as np
import zarr
from simple_zarr_server import serve

arr = np.arange(10 * 1000 * 1000, dtype='i4').reshape(10, 1000, 1000)
z = zarr.array(arr, chunks=[5, 500, 500])
serve(z, port=8080, name='data.zarr', allowed_origins=["*"])

Codecs

Chunk compression is an important aspect Zarr, but you shouldn't have to pay for a codec you don't use! Ultimately array compression might not be known until runtime, so by default zarr-lite contains a codec registry the dynamically imports (numcodecs.js) codecs from a CDN. The registry is just an ES6 Map, and you can override this default behavior (e.g. host your own modules or use your own codecs) using addCodec.

import { addCodec, openArray } from '@manzt/zarr-lite';
import MyCustomCodec from './myCustomCodec';

// override CDN codec
addCodec('blosc', () => MyCustomCodec);

// add new codec
addCodec(MyCustomCodec.id, () => MyCustomCodec);

const z = await openArray({ store });

For more information about the Codec interface, checkout numcodecs.js.

Development

$ git clone https://github.com/manzt/zarr-lite.git
$ cd zarr-lite && npm install
$ npm run dev # builds source in watch mode

You can serve the contents of dist/ via an http server and test in the browser. I've just been using https://observablehq.com/@manzt/using-zarr-lite to experiment since most of the library is imported from zarrita.

Publishing

$ npm version [<newversion> | major | minor | patch]
$ npm run build # bundles source & copies README.md + package.json to dist/
$ cd dist
$ npm publish