heatshrink-compression-ts 0.1.0 → 1.0.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 (45) hide show
  1. package/README.md +20 -19
  2. package/dist/docs/assets/css/main.css +865 -0
  3. package/dist/docs/assets/css/main.css.map +7 -0
  4. package/dist/docs/assets/images/icons.png +0 -0
  5. package/dist/docs/assets/images/icons@2x.png +0 -0
  6. package/dist/docs/assets/images/widgets.png +0 -0
  7. package/dist/docs/assets/images/widgets@2x.png +0 -0
  8. package/dist/docs/assets/js/main.js +5 -0
  9. package/dist/docs/assets/js/search.js +3 -0
  10. package/dist/docs/classes/bitwriter.html +1265 -0
  11. package/dist/docs/classes/heatshrinkdecoder.html +1744 -0
  12. package/dist/docs/classes/heatshrinkencoder.html +1195 -0
  13. package/dist/docs/classes/hsconfigerror.html +1124 -0
  14. package/dist/docs/classes/hscorruptdataerror.html +1112 -0
  15. package/dist/docs/classes/hserror.html +1152 -0
  16. package/dist/docs/classes/hsinternalerror.html +1112 -0
  17. package/dist/docs/enums/hsstate.html +1151 -0
  18. package/dist/docs/globals.html +1271 -0
  19. package/dist/docs/index.html +1272 -0
  20. package/dist/docs/interfaces/hsbitstreamstate.html +1117 -0
  21. package/dist/heatshrink-basic.d.ts +42 -0
  22. package/dist/heatshrink-decoder.d.ts +66 -0
  23. package/dist/heatshrink-encoder.d.ts +11 -0
  24. package/dist/heatshrink-ts.d.ts +3 -0
  25. package/dist/heatshrink-ts.es5.js +568 -0
  26. package/dist/heatshrink-ts.es5.js.map +1 -0
  27. package/dist/heatshrink-ts.umd.js +582 -0
  28. package/dist/heatshrink-ts.umd.js.map +1 -0
  29. package/dist/heatshrink-utils.d.ts +29 -0
  30. package/dist/lib/heatshrink-basic.js +74 -0
  31. package/dist/lib/heatshrink-basic.js.map +1 -0
  32. package/dist/lib/heatshrink-decoder.js +274 -0
  33. package/dist/lib/heatshrink-decoder.js.map +1 -0
  34. package/dist/lib/heatshrink-encoder.js +146 -0
  35. package/dist/lib/heatshrink-encoder.js.map +1 -0
  36. package/dist/lib/heatshrink-ts.js +11 -0
  37. package/dist/lib/heatshrink-ts.js.map +1 -0
  38. package/dist/lib/heatshrink-utils.js +75 -0
  39. package/dist/lib/heatshrink-utils.js.map +1 -0
  40. package/dist/types/heatshrink-basic.d.ts +42 -0
  41. package/dist/types/heatshrink-decoder.d.ts +66 -0
  42. package/dist/types/heatshrink-encoder.d.ts +11 -0
  43. package/dist/types/heatshrink-ts.d.ts +3 -0
  44. package/dist/types/heatshrink-utils.d.ts +29 -0
  45. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Typescript Decoder for Heatshrink
1
+ # Typescript Encoder and Decoder for Heatshrink
2
2
 
3
3
  [![Travis](https://img.shields.io/travis/iotile/heatshrink-ts.svg)](https://travis-ci.org/iotile/heatshrink-ts)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/iotile/heatshrink-ts/badge.svg?branch=master)](https://coveralls.io/github/iotile/heatshrink-ts?branch=master)
@@ -6,42 +6,43 @@
6
6
  [![npm](https://img.shields.io/npm/v/heatshrink-ts.svg)](https://www.npmjs.com/package/heatshrink-ts)
7
7
 
8
8
  ### Introduction
9
+ Forked from [iotile/heatshrink-ts](https://github.com/iotile/heatshrink-ts)
10
+
11
+ Thank you [@Tim Burke](https://github.com/timburke)
9
12
 
10
13
  Heatshrink is a compression library that can be used in very low resource microcontroller devices. It is based on LZSS encoding, which
11
14
  looks for repeated strings of characters and replaces them with references to a previous occurence rather than repeating them.
12
15
 
13
16
  You can read more details at the repository for the original C implementation of [heatshrink](https://github.com/atomicobject/heatshrink/).
14
17
 
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.
18
+ ~~This typescript package only implements the heatshrink decoding process so it can decode compressed data that it receives from
19
+ a device using the heatshrink library. It is written in typescript and distributed on NPM for easy installation and usage.~~
20
+
21
+ **Now there is encoder too.**
17
22
 
18
23
  ### Installation and Basic Usage
19
24
 
20
25
  ```shell
21
- npm install heatshrink-ts
26
+ npm install heatshrink-compression-ts
22
27
  ```
23
28
 
24
29
  The primary class is the `HeatshrinkDecoder` object that can take in compressed data and turn it back into uncompressed data.
25
30
 
26
31
  ```typescript
32
+ import { HeatshrinkEncoder } from "../src/heatshrink-encoder";
33
+ import { HeatshrinkDecoder } from "../src/heatshrink-decoder";
27
34
 
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);
35
+ const encoder = new HeatshrinkEncoder(12, 4);
36
+ const decoder = new HeatshrinkDecoder(12, 4, 1024);
39
37
 
40
- let output = decoder.getOutput();
38
+ const text = "This is a test. This is a test. This is a test.";
39
+ const input = Buffer.from(text, "utf8");
40
+ const compressed = encoder.compress(input);
41
+ console.log("Compressed bytes:", compressed.byteLength);
41
42
 
42
- // This will print 'Decoded output: this is a test'
43
- let outputString = String.fromCharCode(...output);
44
- console.log("Decoded output: " + outputString);
43
+ decoder.process(compressed);
44
+ const out = decoder.getOutput();
45
+ console.log(Buffer.from(out).toString("utf8"), text);
45
46
  ```
46
47
 
47
48
  There are 2 key parameters that need to match between the encoder and decoder: