numcodecs.js
Buffer compression and transformation codecs for use in Zarr.js and beyond...
Installation
npm install numcodecs
Usage
import { Blosc, GZip, Zlib, LZ4, Zstd } from 'numcodecs';
const codec = new Blosc();
const size = 100000;
const arr = new Uint32Array(size);
for (let i = 0; i < size; i++) {
arr[i] = i;
}
const bytes = new Uint8Array(arr.buffer);
console.log(bytes);
const encoded = await codec.encode(bytes);
console.log(encoded);
const decoded = await codec.decode(encoded);
console.log(new Uint32Array(decoded.buffer));
Author's note
This project is intended as a Typescript implementation of the buffer compression library numcodecs
which supports
zarr-python
. Currently blosc
,
zlib
, gzip
, lz4
, and zstd
compressors are supported. No other compressors are
implemented, but contributions are welcome!
Conditional exports
Each compressor is bundled as a separate entrypoint and exported as a package submodule using Node's conditional exports. This means each compressor can be imported independently from code-split modules. I hope this will afford an option to have a more dynamic and configurable compressor registry in Zarr.js in the future, allowing users to define the codecs necessary for their applications.
const Zlib = require('numcodecs/zlib');
import Zlib from 'numcodecs/zlib';
Publishing
$ npm version [<newversion> | major | minor | patch]
$ npm run build
$ cd dist
$ npm publish