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

wasm-zfp

v3.0.0

Published

[![npm version](https://img.shields.io/npm/v/wasm-zfp)](https://www.npmjs.com/package/wasm-zfp)

Downloads

6

Readme

wasm-zfp

npm version

ZFP decompression compiled to WebAssembly

Introduction

This package provides a WebAssembly build of https://computing.llnl.gov/projects/zfp, the official ZFP library. A high-level API is provided to compress and decompress ZFP data with a prefixed ZFP_HEADER_FULL header.

Usage

Create ZFP compressed data. An example is given in the test/ directory generated with the following command:

# Take the 2x3x4 array of float32s in uncompressed.raw and compress it to compressed.zfp with a header
zfp -i uncompressed.raw -h -f -3 2 3 4 -a 1 -z compressed.zfp

Create the same output using this library (node.js example, browsers are also supported):

import { readFileSync } from "fs";
import Zfp from "wasm-zfp";

const uncompressed = readFileSync("uncompressed.raw");

// Wait for the WebAssembly module to load
await Zfp.isLoaded;
// Create an internal allocation for compression. This can be reused for
// multiple compressions
const zfpBuffer = Zfp.createBuffer();

try {
  // Create a ZfpInput object describing the uncompressed data
  const input = {
    data: new Float32Array(uncompressed.buffer, uncompressed.byteOffset, uncompressed.byteLength / 4),
    shape: [2, 3, 4, 0],
    strides: [1, 2, 6, 0],
    dimensions: 3,
  };

  // Compress the data using `tolerance` mode with a value of 1 and return an
  // Uint8Array containing the compressed data. `rate` and `precision` modes are
  // also available, and lossless compression will be used if no mode is set
  const result = Zfp.compress(zfpBuffer, input, { tolerance: 1 });
  console.log(result);
} catch (error) {
  console.error(error);
}

// Free the internal allocation when it is no longer needed
Zfp.freeBuffer(zfpBuffer);

Decompress the data:

import { readFileSync } from "fs";
import Zfp from "wasm-zfp";

const compressed = readFileSync("compressed.zfp");

// Wait for the WebAssembly module to load
await Zfp.isLoaded;
// Create an internal allocation for decompression. This can be reused for
// multiple decompressions
const zfpBuffer = Zfp.createBuffer();

try {
  // Decompress the Uint8Array `compressed` and return an object containing
  // metadata about the type and shape of the array, as well as the decompressed
  // typed array
  const result = Zfp.decompress(zfpBuffer, compressed);
  console.log(result);
} catch (error) {
  console.error(error);
}

// Free the internal allocation when it is no longer needed
Zfp.freeBuffer(zfpBuffer);

For the test/compressed.zfp file in this repository, the output is:

{
  data: Float32Array(24) [
     0,  1,  2,  3,  4,  5,  6,  7,
     8,  9, 10, 11, 12, 13, 14, 15,
    16, 17, 18, 19, 20, 21, 22, 23
  ],
  dataPointer: 1052800,
  bufferSize: 96,
  size: 96,
  scalarSize: 4,
  shape: [ 2, 3, 4, 0 ],
  stride: [ 1, 2, 6, 0 ],
  dimensions: 3,
  type: 3
}

The dataPointer field is an opaque pointer. The remaining fields come from the ZFP header and decompressed data.

Development

Docker is required to build the WebAssembly module.

  1. yarn install
  2. yarn build
  3. yarn test

License

wasm-zfp is licensed under MIT License.

Releasing

  1. Run yarn version --[major|minor|patch] to bump version
  2. Run git push && git push --tags to push new tag
  3. GitHub Actions will take care of the rest

Stay in touch

Join our Slack channel to ask questions, share feedback, and stay up to date on what our team is working on.