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

heatshrink-ts

v0.1.0

Published

A typescript implementation of the heatshrink compression library

Downloads

828

Readme

Typescript Decoder for Heatshrink

Travis Coverage Status GitHub license

Introduction

Heatshrink is a compression library that can be used in very low resource microcontroller devices. It is based on LZSS encoding, which looks for repeated strings of characters and replaces them with references to a previous occurence rather than repeating them.

You can read more details at the repository for the original C implementation of heatshrink.

This typescript package only implements the heatshrink decoding process so it can decode compressed data that it receives from a device using the heatshrink library. It is written in typescript and distributed on NPM for easy installation and usage.

Installation and Basic Usage

npm install heatshrink-ts

The primary class is the HeatshrinkDecoder object that can take in compressed data and turn it back into uncompressed data.


import { HeatshrinkDecoder } from "heatshrink-ts";

const WINDOW_BITS = 8;
const LOOKAHEAD_BITS = 4;
const INPUT_BUFFER_LENGTH = 64;

// Heatshrink Encoded form of the ASCII string 'this is a test'
let encodedInput = new Uint8Array([0xba, 0x5a, 0x2d, 0x37, 0x39, 0x00, 0x08, 0xac, 0x32, 0x0b, 0xa5, 0x96, 0xe7, 0x74]);

let decoder = new HeatshrinkDecoder(WINDOW_BITS, LOOKAHEAD_BITS, INPUT_BUFFER_LENGTH);
decoder.process(encodedInput);

let output = decoder.getOutput();

// This will print 'Decoded output: this is a test'
let outputString = String.fromCharCode(...output);
console.log("Decoded output: " + outputString);

There are 2 key parameters that need to match between the encoder and decoder:

  • The window size (WINDOW_BITS), which is a number between 4 and 15, inclusive that sets how large of a sliding window is used to look for repeated strings. It is internally considered as a power of 2, so the value 8 would be 2**8 or 256 bytes for the sliding window.

  • The lookahead size (LOOKAHEAD_BITS), which is a number between 2 and 15, always strictly smaller than the window size. This sets how long of a repeated pattern the encoder can see and therefore compress. According to the heatshrink documentation, a good size is WINDOW_BITS / 2.

Important: Neither of these two parameters are transferred with heatshrink compressed data but they are required to decode it properly. You must magically know the right values for the encoder that was used to produce your encoded data or the decoding process will not produce the correct output.

The input buffer length can be whatever you want but a larger input buffer is a little more time efficient. 64 bytes is a reasonable value. This parameter will probably go away in the future since it is not so meaningful in a non-embedded context.

API Documentation

API Documentation can be found at: https://iotile.github.io/heatshrink-ts/