heatshrink-compression-ts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +78 -0
  3. package/package.json +83 -0
package/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2018, Tim Burke <tim@arch-iot.com>
2
+ All rights reserved.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted, provided that the above
6
+ copyright notice and this permission notice appear in all copies.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Typescript Decoder for Heatshrink
2
+
3
+ [![Travis](https://img.shields.io/travis/iotile/heatshrink-ts.svg)](https://travis-ci.org/iotile/heatshrink-ts)
4
+ [![Coverage Status](https://coveralls.io/repos/github/iotile/heatshrink-ts/badge.svg?branch=master)](https://coveralls.io/github/iotile/heatshrink-ts?branch=master)
5
+ [![GitHub license](https://img.shields.io/github/license/iotile/heatshrink-ts.svg)](https://github.com/iotile/heatshrink-ts/blob/master/LICENSE)
6
+ [![npm](https://img.shields.io/npm/v/heatshrink-ts.svg)](https://www.npmjs.com/package/heatshrink-ts)
7
+
8
+ ### Introduction
9
+
10
+ Heatshrink is a compression library that can be used in very low resource microcontroller devices. It is based on LZSS encoding, which
11
+ looks for repeated strings of characters and replaces them with references to a previous occurence rather than repeating them.
12
+
13
+ You can read more details at the repository for the original C implementation of [heatshrink](https://github.com/atomicobject/heatshrink/).
14
+
15
+ This typescript package only implements the heatshrink decoding process so it can decode compressed data that it receives from
16
+ a device using the heatshrink library. It is written in typescript and distributed on NPM for easy installation and usage.
17
+
18
+ ### Installation and Basic Usage
19
+
20
+ ```shell
21
+ npm install heatshrink-ts
22
+ ```
23
+
24
+ The primary class is the `HeatshrinkDecoder` object that can take in compressed data and turn it back into uncompressed data.
25
+
26
+ ```typescript
27
+
28
+ import { HeatshrinkDecoder } from "heatshrink-ts";
29
+
30
+ const WINDOW_BITS = 8;
31
+ const LOOKAHEAD_BITS = 4;
32
+ const INPUT_BUFFER_LENGTH = 64;
33
+
34
+ // Heatshrink Encoded form of the ASCII string 'this is a test'
35
+ let encodedInput = new Uint8Array([0xba, 0x5a, 0x2d, 0x37, 0x39, 0x00, 0x08, 0xac, 0x32, 0x0b, 0xa5, 0x96, 0xe7, 0x74]);
36
+
37
+ let decoder = new HeatshrinkDecoder(WINDOW_BITS, LOOKAHEAD_BITS, INPUT_BUFFER_LENGTH);
38
+ decoder.process(encodedInput);
39
+
40
+ let output = decoder.getOutput();
41
+
42
+ // This will print 'Decoded output: this is a test'
43
+ let outputString = String.fromCharCode(...output);
44
+ console.log("Decoded output: " + outputString);
45
+ ```
46
+
47
+ There are 2 key parameters that need to match between the encoder and decoder:
48
+
49
+ - The window size (WINDOW_BITS), which is a number between 4 and 15, inclusive
50
+ that sets how large of a sliding window is used to look for repeated strings.
51
+ It is internally considered as a power of 2, so the value 8 would be 2**8 or
52
+ 256 bytes for the sliding window.
53
+
54
+ - The lookahead size (LOOKAHEAD_BITS), which is a number between 2 and 15, always
55
+ strictly smaller than the window size. This sets how long of a repeated pattern
56
+ the encoder can see and therefore compress. According to the heatshrink
57
+ documentation, a good size is WINDOW_BITS / 2.
58
+
59
+ **Important:** Neither of these two parameters are transferred with heatshrink compressed
60
+ data but they are required to decode it properly. You must magically know the
61
+ right values for the encoder that was used to produce your encoded data or the
62
+ decoding process will not produce the correct output.
63
+
64
+ The input buffer length can be whatever you want but a larger input buffer is
65
+ a little more time efficient. 64 bytes is a reasonable value. This parameter
66
+ will probably go away in the future since it is not so meaningful in a
67
+ non-embedded context.
68
+
69
+ ### Next Steps
70
+
71
+ - See [example usage](https://runkit.com/timburke/runkit-npm-heatshrink-ts-example-1) run
72
+ immediately on Runkit.
73
+
74
+ - [Try out the libary](https://npm.runkit.com/heatshrink-ts) yourself on Runkit.
75
+
76
+ ### API Documentation
77
+
78
+ API Documentation can be found at: https://iotile.github.io/heatshrink-ts/
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "heatshrink-compression-ts",
3
+ "version": "0.1.0",
4
+ "description": "A typescript implementation of the heatshrink compression library",
5
+ "keywords": [],
6
+ "main": "dist/heatshrink-ts.umd.js",
7
+ "module": "dist/heatshrink-ts.es5.js",
8
+ "typings": "dist/types/heatshrink-ts.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "author": "491239 <lzx491378583@gmail.com>",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/491239/heatshrink-ts.git"
16
+ },
17
+ "license": "ISC",
18
+ "engines": {
19
+ "node": ">=6.0.0"
20
+ },
21
+ "scripts": {
22
+ "lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
23
+ "prebuild": "rimraf dist",
24
+ "build": "tsc --module commonjs --outDir dist/lib && rollup -c rollup.config.ts && typedoc --name Heatshrink-TS --out dist/docs --target es6 --theme minimal --mode file src",
25
+ "start": "rollup -c rollup.config.ts -w",
26
+ "test": "jest",
27
+ "test:watch": "jest --watch",
28
+ "test:prod": "npm run lint && npm run test -- --coverage --no-cache",
29
+ "deploy-docs": "ts-node tools/gh-pages-publish",
30
+ "report-coverage": "cat ./coverage/lcov.info | coveralls"
31
+ },
32
+ "jest": {
33
+ "transform": {
34
+ ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
35
+ },
36
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
37
+ "moduleFileExtensions": [
38
+ "ts",
39
+ "tsx",
40
+ "js"
41
+ ],
42
+ "coveragePathIgnorePatterns": [
43
+ "/node_modules/",
44
+ "/test/"
45
+ ],
46
+ "coverageThreshold": {
47
+ "global": {
48
+ "branches": 90,
49
+ "functions": 95,
50
+ "lines": 95,
51
+ "statements": 95
52
+ }
53
+ },
54
+ "collectCoverage": true,
55
+ "mapCoverage": true
56
+ },
57
+ "devDependencies": {
58
+ "@types/jest": "^22.0.0",
59
+ "@types/node": "^9.3.0",
60
+ "colors": "^1.1.2",
61
+ "coveralls": "^3.0.0",
62
+ "cross-env": "^5.0.1",
63
+ "husky": "^0.14.0",
64
+ "jest": "^22.0.2",
65
+ "lint-staged": "^6.0.0",
66
+ "lodash.camelcase": "^4.3.0",
67
+ "prompt": "^1.0.0",
68
+ "replace-in-file": "^3.0.0-beta.2",
69
+ "rimraf": "^2.6.1",
70
+ "rollup": "^0.54.0",
71
+ "rollup-plugin-commonjs": "^8.0.2",
72
+ "rollup-plugin-node-resolve": "^3.0.0",
73
+ "rollup-plugin-sourcemaps": "^0.4.2",
74
+ "rollup-plugin-typescript2": "^0.10.0",
75
+ "ts-jest": "^22.0.0",
76
+ "ts-node": "^4.1.0",
77
+ "tslint": "^5.8.0",
78
+ "tslint-config-prettier": "^1.1.0",
79
+ "tslint-config-standard": "^7.0.0",
80
+ "typedoc": "^0.10.0",
81
+ "typescript": "^2.6.2"
82
+ }
83
+ }