heatshrink-compression-ts 0.1.0 → 0.1.1
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.
- package/dist/docs/assets/css/main.css +865 -0
- package/dist/docs/assets/css/main.css.map +7 -0
- package/dist/docs/assets/images/icons.png +0 -0
- package/dist/docs/assets/images/icons@2x.png +0 -0
- package/dist/docs/assets/images/widgets.png +0 -0
- package/dist/docs/assets/images/widgets@2x.png +0 -0
- package/dist/docs/assets/js/main.js +5 -0
- package/dist/docs/assets/js/search.js +3 -0
- package/dist/docs/classes/bitwriter.html +1265 -0
- package/dist/docs/classes/heatshrinkdecoder.html +1744 -0
- package/dist/docs/classes/heatshrinkencoder.html +1195 -0
- package/dist/docs/classes/hsconfigerror.html +1124 -0
- package/dist/docs/classes/hscorruptdataerror.html +1112 -0
- package/dist/docs/classes/hserror.html +1152 -0
- package/dist/docs/classes/hsinternalerror.html +1112 -0
- package/dist/docs/enums/hsstate.html +1151 -0
- package/dist/docs/globals.html +1271 -0
- package/dist/docs/index.html +1272 -0
- package/dist/docs/interfaces/hsbitstreamstate.html +1117 -0
- package/dist/heatshrink-basic.d.ts +42 -0
- package/dist/heatshrink-decoder.d.ts +66 -0
- package/dist/heatshrink-encoder.d.ts +11 -0
- package/dist/heatshrink-ts.d.ts +3 -0
- package/dist/heatshrink-ts.es5.js +568 -0
- package/dist/heatshrink-ts.es5.js.map +1 -0
- package/dist/heatshrink-ts.umd.js +582 -0
- package/dist/heatshrink-ts.umd.js.map +1 -0
- package/dist/heatshrink-utils.d.ts +29 -0
- package/dist/lib/heatshrink-basic.js +74 -0
- package/dist/lib/heatshrink-basic.js.map +1 -0
- package/dist/lib/heatshrink-decoder.js +274 -0
- package/dist/lib/heatshrink-decoder.js.map +1 -0
- package/dist/lib/heatshrink-encoder.js +146 -0
- package/dist/lib/heatshrink-encoder.js.map +1 -0
- package/dist/lib/heatshrink-ts.js +11 -0
- package/dist/lib/heatshrink-ts.js.map +1 -0
- package/dist/lib/heatshrink-utils.js +75 -0
- package/dist/lib/heatshrink-utils.js.map +1 -0
- package/dist/types/heatshrink-basic.d.ts +42 -0
- package/dist/types/heatshrink-decoder.d.ts +66 -0
- package/dist/types/heatshrink-encoder.d.ts +11 -0
- package/dist/types/heatshrink-ts.d.ts +3 -0
- package/dist/types/heatshrink-utils.d.ts +29 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var heatshrink_encoder_1 = require("./heatshrink-encoder");
|
|
4
|
+
exports.HeatshrinkEncoder = heatshrink_encoder_1.HeatshrinkEncoder;
|
|
5
|
+
var heatshrink_decoder_1 = require("./heatshrink-decoder");
|
|
6
|
+
exports.HeatshrinkDecoder = heatshrink_decoder_1.HeatshrinkDecoder;
|
|
7
|
+
var heatshrink_basic_1 = require("./heatshrink-basic");
|
|
8
|
+
exports.HSConfigError = heatshrink_basic_1.HSConfigError;
|
|
9
|
+
exports.HSInternalError = heatshrink_basic_1.HSInternalError;
|
|
10
|
+
exports.HSError = heatshrink_basic_1.HSError;
|
|
11
|
+
//# sourceMappingURL=heatshrink-ts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heatshrink-ts.js","sourceRoot":"","sources":["../../src/heatshrink-ts.ts"],"names":[],"mappings":";;AAAA,2DAAyD;AAAhD,iDAAA,iBAAiB,CAAA;AAC1B,2DAAyD;AAAhD,iDAAA,iBAAiB,CAAA;AAC1B,uDAA6E;AAApE,2CAAA,aAAa,CAAA;AAAE,6CAAA,eAAe,CAAA;AAAE,qCAAA,OAAO,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module heatshrink-utils
|
|
4
|
+
* @external
|
|
5
|
+
* @preferred
|
|
6
|
+
*
|
|
7
|
+
* This internal module contains private utility functions that are used inside
|
|
8
|
+
* the heatshrink-ts package. They are not meant to be used externally nor are
|
|
9
|
+
* they externally visible.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var heatshrink_basic_1 = require("./heatshrink-basic");
|
|
13
|
+
/**
|
|
14
|
+
* Get a specific number of bits from the input buffer. You can get between
|
|
15
|
+
* 1 and 15 bits at a time and those bits are popped from the input buffer and
|
|
16
|
+
* returned. If there are not enough bits remaining in buffer according to the
|
|
17
|
+
* state information in state, then HS_NOBITS is returned as a sentinal value
|
|
18
|
+
* and no bits are consumed from teh buffer.
|
|
19
|
+
*
|
|
20
|
+
* @param count The number of bits to return, must be in the range [1, 15]
|
|
21
|
+
* @param state The current state of the input bitstream. This parameter is
|
|
22
|
+
* modified with every invocation of this function to maintain state between
|
|
23
|
+
* calls.
|
|
24
|
+
* @param buffer A buffer of input data that will be used to retrieve a fixed
|
|
25
|
+
* number of bits. This parameter is never modified. The state of what
|
|
26
|
+
* bits have and have not been extracted is stored in the state parameter.
|
|
27
|
+
* @returns The bits that were popped from the input buffer. If there are not
|
|
28
|
+
* enough bits left in the buffer then HS_NOBITS is returned and state is left
|
|
29
|
+
* unchanged.
|
|
30
|
+
*/
|
|
31
|
+
function getBits(count, buffer, state) {
|
|
32
|
+
if (count > 15) {
|
|
33
|
+
throw new heatshrink_basic_1.HSInternalError("getBits called with invalid number of bits requested (" + count + " not in [1, 15])");
|
|
34
|
+
}
|
|
35
|
+
/*
|
|
36
|
+
* Make sure that we have enough available bits to satisfy this call. There are two cases where
|
|
37
|
+
* we could fail to have enough bits:
|
|
38
|
+
* 1. We are on the last byte and there are fewer bits left than count
|
|
39
|
+
* 2. We are on the penultimate byte and there are fewers bits left in the byte than count - 8
|
|
40
|
+
* so that when we move to the next byte
|
|
41
|
+
*/
|
|
42
|
+
if (state.size === 0 && state.bitIndex < 1 << (count - 1)) {
|
|
43
|
+
return heatshrink_basic_1.HS_NOBITS;
|
|
44
|
+
}
|
|
45
|
+
else if (state.size - state.index === 1 && count > 8) {
|
|
46
|
+
var requiredBitmask = 1 << (count - 8 - 1);
|
|
47
|
+
if (state.bitIndex < requiredBitmask) {
|
|
48
|
+
return heatshrink_basic_1.HS_NOBITS;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var accum = 0;
|
|
52
|
+
for (var i = 0; i < count; ++i) {
|
|
53
|
+
if (state.bitIndex === 0 && state.size === 0) {
|
|
54
|
+
return heatshrink_basic_1.HS_NOBITS;
|
|
55
|
+
}
|
|
56
|
+
if (state.bitIndex === 0) {
|
|
57
|
+
state.currentByte = buffer[state.index];
|
|
58
|
+
state.index += 1;
|
|
59
|
+
// Keep track of when the inputBuffer is used up and mark it as empty again
|
|
60
|
+
if (state.index === state.size) {
|
|
61
|
+
state.index = 0;
|
|
62
|
+
state.size = 0;
|
|
63
|
+
}
|
|
64
|
+
state.bitIndex = 1 << 7;
|
|
65
|
+
}
|
|
66
|
+
accum <<= 1;
|
|
67
|
+
if (state.currentByte & state.bitIndex) {
|
|
68
|
+
accum |= 1;
|
|
69
|
+
}
|
|
70
|
+
state.bitIndex >>= 1;
|
|
71
|
+
}
|
|
72
|
+
return accum;
|
|
73
|
+
}
|
|
74
|
+
exports.getBits = getBits;
|
|
75
|
+
//# sourceMappingURL=heatshrink-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heatshrink-utils.js","sourceRoot":"","sources":["../../src/heatshrink-utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAEH,uDAAkF;AAElF;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAwB,KAAa,EAAE,MAAkB,EAAE,KAAuB;IAC9E,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC;QACb,MAAM,IAAI,kCAAe,CACrB,2DAAyD,KAAK,qBAAkB,CACnF,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACH,EAAE,CAAC,CAAC,KAAK,CAAC,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;QAC5B,CAAC;QAED,KAAK,KAAK,CAAC,CAAC;QACZ,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrC,KAAK,IAAI,CAAC,CAAC;QACf,CAAC;QAED,KAAK,CAAC,QAAQ,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC;AACjB,CAAC;AApDD,0BAoDC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare enum HSState {
|
|
2
|
+
TAG_BIT = 0,
|
|
3
|
+
YIELD_LITERAL = 1,
|
|
4
|
+
BACKREF_INDEX_MSB = 2,
|
|
5
|
+
BACKREF_INDEX_LSB = 3,
|
|
6
|
+
BACKREF_COUNT_MSB = 4,
|
|
7
|
+
BACKREF_COUNT_LSB = 5,
|
|
8
|
+
YIELD_BACKREF = 6,
|
|
9
|
+
}
|
|
10
|
+
export interface HSBitstreamState {
|
|
11
|
+
size: number;
|
|
12
|
+
index: number;
|
|
13
|
+
currentByte: number;
|
|
14
|
+
bitIndex: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* All errors thrown by the heatshrink-ts package will inherit from
|
|
18
|
+
* this class. Different subclasses are thrown for different kinds of
|
|
19
|
+
* errors. All errors have a string message that indicates what exactly
|
|
20
|
+
* went wrong.
|
|
21
|
+
*
|
|
22
|
+
* @category Errors
|
|
23
|
+
*/
|
|
24
|
+
export declare class HSError extends Error {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The heatshrink engine has been misconfigured.
|
|
28
|
+
*
|
|
29
|
+
* @category Errors
|
|
30
|
+
*/
|
|
31
|
+
export declare class HSConfigError extends HSError {
|
|
32
|
+
}
|
|
33
|
+
export declare class HSInternalError extends HSError {
|
|
34
|
+
}
|
|
35
|
+
export declare class HSCorruptDataError extends HSError {
|
|
36
|
+
}
|
|
37
|
+
export declare const HS_MIN_WINDOW_BITS: number;
|
|
38
|
+
export declare const HS_MAX_WINDOW_BITS: number;
|
|
39
|
+
export declare const HS_MIN_LOOKAHEAD_BITS: number;
|
|
40
|
+
export declare const HS_LITERAL_MARKER: number;
|
|
41
|
+
export declare const HS_BACKREF_MARKER: number;
|
|
42
|
+
export declare const HS_NOBITS: number;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A typescript implementation of the heatshrink compression library.
|
|
3
|
+
*
|
|
4
|
+
* Heatshrink is an open-source LZSS based compression library suitable
|
|
5
|
+
* for use in embedded systems since it has a very small and bounded
|
|
6
|
+
* memory footprint. This is an adaptation of the heatshink code to
|
|
7
|
+
* typescript with a slightly more user-fiendly API.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HeatshrinkDecoder {
|
|
10
|
+
inputBuffer: Uint8Array;
|
|
11
|
+
outputBuffer: Uint8Array;
|
|
12
|
+
outputSize: number;
|
|
13
|
+
private windowBuffer;
|
|
14
|
+
private headIndex;
|
|
15
|
+
private outputIndex;
|
|
16
|
+
private outputCount;
|
|
17
|
+
private state;
|
|
18
|
+
private inputState;
|
|
19
|
+
private windowBits;
|
|
20
|
+
private lookaheadBits;
|
|
21
|
+
constructor(windowBits: number, lookaheadBits: number, inputBufferSize: number);
|
|
22
|
+
reset(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Feed data into the heatshrink decoder state machine.
|
|
25
|
+
*
|
|
26
|
+
* This function will take the chunk of input data and turn it into as
|
|
27
|
+
* much expanded output as it can. Decoding a stream of data should be
|
|
28
|
+
* done by calling this function repeatedly with chunks of data from the
|
|
29
|
+
* stream.
|
|
30
|
+
*
|
|
31
|
+
* You can call isFinished() to check and see if all of the data that you
|
|
32
|
+
* have fed in from previous calls to process() has been successfully
|
|
33
|
+
* decoded.
|
|
34
|
+
*
|
|
35
|
+
* @param rawInput A chunk of data that has encoded using the heatshrink
|
|
36
|
+
* library. You can push data a little bit at a time and stop at
|
|
37
|
+
* any byte boundary.
|
|
38
|
+
*/
|
|
39
|
+
process(rawInput: Uint8Array | ArrayBuffer): void;
|
|
40
|
+
sink(input: Uint8Array): number;
|
|
41
|
+
poll(): void;
|
|
42
|
+
isFinished(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get all output data and truncate the output buffer.
|
|
45
|
+
*
|
|
46
|
+
* Calling this function repeatedly will have the effect of
|
|
47
|
+
* pulling the output in chunks from the HeatshrinkDecoder.
|
|
48
|
+
* It will return all data currently available and remove it
|
|
49
|
+
* from the output buffer so another call to getOutput() will
|
|
50
|
+
* not return duplicate data.
|
|
51
|
+
*
|
|
52
|
+
* @returns All data currently in the output buffer.
|
|
53
|
+
*/
|
|
54
|
+
getOutput(): Uint8Array;
|
|
55
|
+
private assureUint8Array(buffer);
|
|
56
|
+
private processTag();
|
|
57
|
+
private yieldLiteral();
|
|
58
|
+
private processBackrefIndexMSB();
|
|
59
|
+
private processBackrefIndexLSB();
|
|
60
|
+
private processBackrefCountMSB();
|
|
61
|
+
private processBackrefCountLSB();
|
|
62
|
+
private yieldBackref();
|
|
63
|
+
private ensureOutputSpace(neededBytes);
|
|
64
|
+
private emitByte(byte);
|
|
65
|
+
private storeByte(byte);
|
|
66
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class HeatshrinkEncoder {
|
|
2
|
+
private windowBits;
|
|
3
|
+
private lookaheadBits;
|
|
4
|
+
private windowSize;
|
|
5
|
+
private lookaheadSize;
|
|
6
|
+
constructor(windowBits: number, lookaheadBits: number);
|
|
7
|
+
/**
|
|
8
|
+
* Compress input and return compressed Uint8Array in heatshrink bitstream format.
|
|
9
|
+
*/
|
|
10
|
+
compress(rawInput: Uint8Array | ArrayBuffer): Uint8Array;
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module heatshrink-utils
|
|
3
|
+
* @external
|
|
4
|
+
* @preferred
|
|
5
|
+
*
|
|
6
|
+
* This internal module contains private utility functions that are used inside
|
|
7
|
+
* the heatshrink-ts package. They are not meant to be used externally nor are
|
|
8
|
+
* they externally visible.
|
|
9
|
+
*/
|
|
10
|
+
import { HSBitstreamState } from "./heatshrink-basic";
|
|
11
|
+
/**
|
|
12
|
+
* Get a specific number of bits from the input buffer. You can get between
|
|
13
|
+
* 1 and 15 bits at a time and those bits are popped from the input buffer and
|
|
14
|
+
* returned. If there are not enough bits remaining in buffer according to the
|
|
15
|
+
* state information in state, then HS_NOBITS is returned as a sentinal value
|
|
16
|
+
* and no bits are consumed from teh buffer.
|
|
17
|
+
*
|
|
18
|
+
* @param count The number of bits to return, must be in the range [1, 15]
|
|
19
|
+
* @param state The current state of the input bitstream. This parameter is
|
|
20
|
+
* modified with every invocation of this function to maintain state between
|
|
21
|
+
* calls.
|
|
22
|
+
* @param buffer A buffer of input data that will be used to retrieve a fixed
|
|
23
|
+
* number of bits. This parameter is never modified. The state of what
|
|
24
|
+
* bits have and have not been extracted is stored in the state parameter.
|
|
25
|
+
* @returns The bits that were popped from the input buffer. If there are not
|
|
26
|
+
* enough bits left in the buffer then HS_NOBITS is returned and state is left
|
|
27
|
+
* unchanged.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getBits(count: number, buffer: Uint8Array, state: HSBitstreamState): number;
|