@gmod/cram 1.5.6 → 1.6.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.
- package/CHANGELOG.md +82 -0
- package/README.md +126 -154
- package/dist/craiIndex.d.ts +37 -0
- package/dist/craiIndex.js +198 -365
- package/dist/craiIndex.js.map +1 -0
- package/dist/cram-bundle.js +8 -6
- package/dist/cramFile/codecs/_base.d.ts +6 -0
- package/dist/cramFile/codecs/_base.js +44 -53
- package/dist/cramFile/codecs/_base.js.map +1 -0
- package/dist/cramFile/codecs/beta.d.ts +4 -0
- package/dist/cramFile/codecs/beta.js +38 -48
- package/dist/cramFile/codecs/beta.js.map +1 -0
- package/dist/cramFile/codecs/byteArrayLength.d.ts +8 -0
- package/dist/cramFile/codecs/byteArrayLength.js +58 -78
- package/dist/cramFile/codecs/byteArrayLength.js.map +1 -0
- package/dist/cramFile/codecs/byteArrayStop.d.ts +6 -0
- package/dist/cramFile/codecs/byteArrayStop.js +62 -76
- package/dist/cramFile/codecs/byteArrayStop.js.map +1 -0
- package/dist/cramFile/codecs/external.d.ts +7 -0
- package/dist/cramFile/codecs/external.js +63 -81
- package/dist/cramFile/codecs/external.js.map +1 -0
- package/dist/cramFile/codecs/gamma.d.ts +4 -0
- package/dist/cramFile/codecs/gamma.js +43 -56
- package/dist/cramFile/codecs/gamma.js.map +1 -0
- package/dist/cramFile/codecs/huffman.d.ts +17 -0
- package/dist/cramFile/codecs/huffman.js +126 -199
- package/dist/cramFile/codecs/huffman.js.map +1 -0
- package/dist/cramFile/codecs/index.d.ts +2 -0
- package/dist/cramFile/codecs/index.js +31 -38
- package/dist/cramFile/codecs/index.js.map +1 -0
- package/dist/cramFile/codecs/subexp.d.ts +4 -0
- package/dist/cramFile/codecs/subexp.js +51 -64
- package/dist/cramFile/codecs/subexp.js.map +1 -0
- package/dist/cramFile/constants.d.ts +36 -0
- package/dist/cramFile/constants.js +52 -50
- package/dist/cramFile/constants.js.map +1 -0
- package/dist/cramFile/container/compressionScheme.d.ts +23 -0
- package/dist/cramFile/container/compressionScheme.js +115 -153
- package/dist/cramFile/container/compressionScheme.js.map +1 -0
- package/dist/cramFile/container/index.d.ts +13 -0
- package/dist/cramFile/container/index.js +169 -283
- package/dist/cramFile/container/index.js.map +1 -0
- package/dist/cramFile/file.d.ts +63 -0
- package/dist/cramFile/file.js +440 -735
- package/dist/cramFile/file.js.map +1 -0
- package/dist/cramFile/index.d.ts +2 -0
- package/dist/cramFile/index.js +7 -4
- package/dist/cramFile/index.js.map +1 -0
- package/dist/cramFile/record.d.ts +79 -0
- package/dist/cramFile/record.js +253 -308
- package/dist/cramFile/record.js.map +1 -0
- package/dist/cramFile/sectionParsers.d.ts +18 -0
- package/dist/cramFile/sectionParsers.js +324 -362
- package/dist/cramFile/sectionParsers.js.map +1 -0
- package/dist/cramFile/slice/decodeRecord.d.ts +2 -0
- package/dist/cramFile/slice/decodeRecord.js +278 -298
- package/dist/cramFile/slice/decodeRecord.js.map +1 -0
- package/dist/cramFile/slice/index.d.ts +20 -0
- package/dist/cramFile/slice/index.js +488 -789
- package/dist/cramFile/slice/index.js.map +1 -0
- package/dist/cramFile/util.d.ts +5 -0
- package/dist/cramFile/util.js +158 -144
- package/dist/cramFile/util.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +66 -103
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -0
- package/dist/indexedCramFile.d.ts +39 -0
- package/dist/indexedCramFile.js +213 -315
- package/dist/indexedCramFile.js.map +1 -0
- package/dist/io/bufferCache.d.ts +12 -0
- package/dist/io/bufferCache.js +108 -128
- package/dist/io/bufferCache.js.map +1 -0
- package/dist/io/index.d.ts +5 -0
- package/dist/io/index.js +29 -27
- package/dist/io/index.js.map +1 -0
- package/dist/io/localFile.d.ts +10 -0
- package/dist/io/localFile.js +105 -162
- package/dist/io/localFile.js.map +1 -0
- package/dist/io/remoteFile.d.ts +16 -0
- package/dist/io/remoteFile.js +137 -206
- package/dist/io/remoteFile.js.map +1 -0
- package/dist/rans/constants.d.ts +3 -0
- package/dist/rans/constants.js +6 -6
- package/dist/rans/constants.js.map +1 -0
- package/dist/rans/d04.d.ts +1 -0
- package/dist/rans/d04.js +70 -99
- package/dist/rans/d04.js.map +1 -0
- package/dist/rans/d14.d.ts +1 -0
- package/dist/rans/d14.js +55 -93
- package/dist/rans/d14.js.map +1 -0
- package/dist/rans/decoding.d.ts +30 -0
- package/dist/rans/decoding.js +112 -159
- package/dist/rans/decoding.js.map +1 -0
- package/dist/rans/frequencies.d.ts +2 -0
- package/dist/rans/frequencies.js +110 -119
- package/dist/rans/frequencies.js.map +1 -0
- package/dist/rans/index.d.ts +1 -0
- package/dist/rans/index.js +111 -174
- package/dist/rans/index.js.map +1 -0
- package/dist/sam.d.ts +1 -0
- package/dist/sam.js +16 -41
- package/dist/sam.js.map +1 -0
- package/errors.js +66 -103
- package/esm/craiIndex.d.ts +37 -0
- package/esm/craiIndex.js +160 -0
- package/esm/craiIndex.js.map +1 -0
- package/esm/cramFile/codecs/_base.d.ts +6 -0
- package/esm/cramFile/codecs/_base.js +42 -0
- package/esm/cramFile/codecs/_base.js.map +1 -0
- package/esm/cramFile/codecs/beta.d.ts +4 -0
- package/esm/cramFile/codecs/beta.js +15 -0
- package/esm/cramFile/codecs/beta.js.map +1 -0
- package/esm/cramFile/codecs/byteArrayLength.d.ts +8 -0
- package/esm/cramFile/codecs/byteArrayLength.js +35 -0
- package/esm/cramFile/codecs/byteArrayLength.js.map +1 -0
- package/esm/cramFile/codecs/byteArrayStop.d.ts +6 -0
- package/esm/cramFile/codecs/byteArrayStop.js +40 -0
- package/esm/cramFile/codecs/byteArrayStop.js.map +1 -0
- package/esm/cramFile/codecs/external.d.ts +7 -0
- package/esm/cramFile/codecs/external.js +40 -0
- package/esm/cramFile/codecs/external.js.map +1 -0
- package/esm/cramFile/codecs/gamma.d.ts +4 -0
- package/esm/cramFile/codecs/gamma.js +20 -0
- package/esm/cramFile/codecs/gamma.js.map +1 -0
- package/esm/cramFile/codecs/huffman.d.ts +17 -0
- package/esm/cramFile/codecs/huffman.js +107 -0
- package/esm/cramFile/codecs/huffman.js.map +1 -0
- package/esm/cramFile/codecs/index.d.ts +2 -0
- package/esm/cramFile/codecs/index.js +30 -0
- package/esm/cramFile/codecs/index.js.map +1 -0
- package/esm/cramFile/codecs/subexp.d.ts +4 -0
- package/esm/cramFile/codecs/subexp.js +28 -0
- package/esm/cramFile/codecs/subexp.js.map +1 -0
- package/esm/cramFile/constants.d.ts +36 -0
- package/esm/cramFile/constants.js +51 -0
- package/esm/cramFile/constants.js.map +1 -0
- package/esm/cramFile/container/compressionScheme.d.ts +23 -0
- package/esm/cramFile/container/compressionScheme.js +123 -0
- package/esm/cramFile/container/compressionScheme.js.map +1 -0
- package/esm/cramFile/container/index.d.ts +13 -0
- package/esm/cramFile/container/index.js +84 -0
- package/esm/cramFile/container/index.js.map +1 -0
- package/esm/cramFile/file.d.ts +63 -0
- package/esm/cramFile/file.js +281 -0
- package/esm/cramFile/file.js.map +1 -0
- package/esm/cramFile/index.d.ts +2 -0
- package/esm/cramFile/index.js +3 -0
- package/esm/cramFile/index.js.map +1 -0
- package/esm/cramFile/record.d.ts +79 -0
- package/esm/cramFile/record.js +297 -0
- package/esm/cramFile/record.js.map +1 -0
- package/esm/cramFile/sectionParsers.d.ts +18 -0
- package/esm/cramFile/sectionParsers.js +347 -0
- package/esm/cramFile/sectionParsers.js.map +1 -0
- package/esm/cramFile/slice/decodeRecord.d.ts +2 -0
- package/esm/cramFile/slice/decodeRecord.js +299 -0
- package/esm/cramFile/slice/decodeRecord.js.map +1 -0
- package/esm/cramFile/slice/index.d.ts +20 -0
- package/esm/cramFile/slice/index.js +364 -0
- package/esm/cramFile/slice/index.js.map +1 -0
- package/esm/cramFile/util.d.ts +5 -0
- package/esm/cramFile/util.js +161 -0
- package/esm/cramFile/util.js.map +1 -0
- package/esm/errors.d.ts +23 -0
- package/esm/errors.js +24 -0
- package/esm/errors.js.map +1 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -0
- package/esm/indexedCramFile.d.ts +39 -0
- package/esm/indexedCramFile.js +155 -0
- package/esm/indexedCramFile.js.map +1 -0
- package/esm/io/bufferCache.d.ts +12 -0
- package/esm/io/bufferCache.js +54 -0
- package/esm/io/bufferCache.js.map +1 -0
- package/esm/io/index.d.ts +5 -0
- package/esm/io/index.js +24 -0
- package/esm/io/index.js.map +1 -0
- package/esm/io/localFile.d.ts +10 -0
- package/esm/io/localFile.js +31 -0
- package/esm/io/localFile.js.map +1 -0
- package/esm/io/remoteFile.d.ts +16 -0
- package/esm/io/remoteFile.js +64 -0
- package/esm/io/remoteFile.js.map +1 -0
- package/esm/rans/constants.d.ts +3 -0
- package/esm/rans/constants.js +5 -0
- package/esm/rans/constants.js.map +1 -0
- package/esm/rans/d04.d.ts +1 -0
- package/esm/rans/d04.js +67 -0
- package/esm/rans/d04.js.map +1 -0
- package/esm/rans/d14.d.ts +1 -0
- package/esm/rans/d14.js +52 -0
- package/esm/rans/d14.js.map +1 -0
- package/esm/rans/decoding.d.ts +30 -0
- package/esm/rans/decoding.js +118 -0
- package/esm/rans/decoding.js.map +1 -0
- package/esm/rans/frequencies.d.ts +2 -0
- package/esm/rans/frequencies.js +110 -0
- package/esm/rans/frequencies.js.map +1 -0
- package/esm/rans/index.d.ts +1 -0
- package/esm/rans/index.js +195 -0
- package/esm/rans/index.js.map +1 -0
- package/esm/sam.d.ts +1 -0
- package/esm/sam.js +16 -0
- package/esm/sam.js.map +1 -0
- package/package.json +34 -35
|
@@ -1,83 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (_this.dataType === 'int') {
|
|
41
|
-
_this._decodeData = _this._decodeInt;
|
|
42
|
-
} else if (_this.dataType === 'byte') {
|
|
43
|
-
_this._decodeData = _this._decodeByte;
|
|
44
|
-
} else {
|
|
45
|
-
throw new CramUnimplementedError("".concat(_this.dataType, " decoding not yet implemented by EXTERNAL codec"));
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var errors_1 = require("../../errors");
|
|
22
|
+
var _base_1 = __importDefault(require("./_base"));
|
|
23
|
+
var util_1 = require("../util");
|
|
24
|
+
var ExternalCodec = /** @class */ (function (_super) {
|
|
25
|
+
__extends(ExternalCodec, _super);
|
|
26
|
+
function ExternalCodec(parameters, dataType) {
|
|
27
|
+
if (parameters === void 0) { parameters = {}; }
|
|
28
|
+
var _this = _super.call(this, parameters, dataType) || this;
|
|
29
|
+
if (_this.dataType === 'int') {
|
|
30
|
+
_this._decodeData = _this._decodeInt;
|
|
31
|
+
}
|
|
32
|
+
else if (_this.dataType === 'byte') {
|
|
33
|
+
_this._decodeData = _this._decodeByte;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new errors_1.CramUnimplementedError("".concat(_this.dataType, " decoding not yet implemented by EXTERNAL codec"));
|
|
37
|
+
}
|
|
38
|
+
return _this;
|
|
46
39
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
value: function _decodeByte(contentBlock, cursor) {
|
|
74
|
-
if (cursor.bytePosition >= contentBlock.content.length) throw new CramBufferOverrunError('attempted to read beyond end of block. this file seems truncated.');
|
|
75
|
-
var result = contentBlock.content[cursor.bytePosition];
|
|
76
|
-
cursor.bytePosition += 1;
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
}]);
|
|
80
|
-
return ExternalCodec;
|
|
81
|
-
}(CramCodec);
|
|
82
|
-
|
|
83
|
-
module.exports = ExternalCodec;
|
|
40
|
+
ExternalCodec.prototype.decode = function (slice, coreDataBlock, blocksByContentId, cursors) {
|
|
41
|
+
var blockContentId = this.parameters.blockContentId;
|
|
42
|
+
var contentBlock = blocksByContentId[blockContentId];
|
|
43
|
+
if (!contentBlock) {
|
|
44
|
+
throw new errors_1.CramMalformedError("no block found with content ID ".concat(blockContentId));
|
|
45
|
+
}
|
|
46
|
+
var cursor = cursors.externalBlocks.getCursor(blockContentId);
|
|
47
|
+
return this._decodeData(contentBlock, cursor);
|
|
48
|
+
};
|
|
49
|
+
ExternalCodec.prototype._decodeInt = function (contentBlock, cursor) {
|
|
50
|
+
var _a = (0, util_1.parseItf8)(contentBlock.content, cursor.bytePosition), result = _a[0], bytesRead = _a[1];
|
|
51
|
+
cursor.bytePosition += bytesRead;
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
ExternalCodec.prototype._decodeByte = function (contentBlock, cursor) {
|
|
55
|
+
if (cursor.bytePosition >= contentBlock.content.length) {
|
|
56
|
+
throw new errors_1.CramBufferOverrunError('attempted to read beyond end of block. this file seems truncated.');
|
|
57
|
+
}
|
|
58
|
+
var result = contentBlock.content[cursor.bytePosition];
|
|
59
|
+
cursor.bytePosition += 1;
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
return ExternalCodec;
|
|
63
|
+
}(_base_1.default));
|
|
64
|
+
exports.default = ExternalCodec;
|
|
65
|
+
//# sourceMappingURL=external.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/external.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uCAIqB;AACrB,kDAA+B;AAC/B,gCAAmC;AAEnC;IAA2C,iCAAS;IAClD,uBAAY,UAAe,EAAE,QAAQ;QAAzB,2BAAA,EAAA,eAAe;QAA3B,YACE,kBAAM,UAAU,EAAE,QAAQ,CAAC,SAU5B;QATC,IAAI,KAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC3B,KAAI,CAAC,WAAW,GAAG,KAAI,CAAC,UAAU,CAAA;SACnC;aAAM,IAAI,KAAI,CAAC,QAAQ,KAAK,MAAM,EAAE;YACnC,KAAI,CAAC,WAAW,GAAG,KAAI,CAAC,WAAW,CAAA;SACpC;aAAM;YACL,MAAM,IAAI,+BAAsB,CAC9B,UAAG,KAAI,CAAC,QAAQ,oDAAiD,CAClE,CAAA;SACF;;IACH,CAAC;IAED,8BAAM,GAAN,UAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO;QAC7C,IAAA,cAAc,GAAK,IAAI,CAAC,UAAU,eAApB,CAAoB;QAC1C,IAAM,YAAY,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAA;QACtD,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,2BAAkB,CAC1B,yCAAkC,cAAc,CAAE,CACnD,CAAA;SACF;QACD,IAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;IAC/C,CAAC;IAED,kCAAU,GAAV,UAAW,YAAY,EAAE,MAAM;QACvB,IAAA,KAAsB,IAAA,gBAAS,EACnC,YAAY,CAAC,OAAO,EACpB,MAAM,CAAC,YAAY,CACpB,EAHM,MAAM,QAAA,EAAE,SAAS,QAGvB,CAAA;QACD,MAAM,CAAC,YAAY,IAAI,SAAS,CAAA;QAChC,OAAO,MAAM,CAAA;IACf,CAAC;IAED,mCAAW,GAAX,UAAY,YAAY,EAAE,MAAM;QAC9B,IAAI,MAAM,CAAC,YAAY,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE;YACtD,MAAM,IAAI,+BAAsB,CAC9B,mEAAmE,CACpE,CAAA;SACF;QACD,IAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QACxD,MAAM,CAAC,YAAY,IAAI,CAAC,CAAA;QACxB,OAAO,MAAM,CAAA;IACf,CAAC;IACH,oBAAC;AAAD,CAAC,AA7CD,CAA2C,eAAS,GA6CnD"}
|
|
@@ -1,58 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (_this.dataType !== 'int') {
|
|
34
|
-
throw new CramUnimplementedError("".concat(_this.dataType, " decoding not yet implemented by GAMMA codec"));
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var errors_1 = require("../../errors");
|
|
22
|
+
var _base_1 = __importDefault(require("./_base"));
|
|
23
|
+
var GammaCodec = /** @class */ (function (_super) {
|
|
24
|
+
__extends(GammaCodec, _super);
|
|
25
|
+
function GammaCodec(parameters, dataType) {
|
|
26
|
+
if (parameters === void 0) { parameters = {}; }
|
|
27
|
+
var _this = _super.call(this, parameters, dataType) || this;
|
|
28
|
+
if (_this.dataType !== 'int') {
|
|
29
|
+
throw new errors_1.CramUnimplementedError("".concat(_this.dataType, " decoding not yet implemented by GAMMA codec"));
|
|
30
|
+
}
|
|
31
|
+
return _this;
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var readBits = this._getBits(coreDataBlock.content, cursors.coreBlock, length - 1);
|
|
50
|
-
|
|
51
|
-
var value = readBits | 1 << length - 1;
|
|
52
|
-
return value - this.parameters.offset;
|
|
53
|
-
}
|
|
54
|
-
}]);
|
|
55
|
-
return GammaCodec;
|
|
56
|
-
}(CramCodec);
|
|
57
|
-
|
|
58
|
-
module.exports = GammaCodec;
|
|
33
|
+
GammaCodec.prototype.decode = function (slice, coreDataBlock, blocksByContentId, cursors) {
|
|
34
|
+
var length = 1;
|
|
35
|
+
while (this._getBits(coreDataBlock.content, cursors.coreBlock, 1) === 0) {
|
|
36
|
+
length += 1;
|
|
37
|
+
}
|
|
38
|
+
var readBits = this._getBits(coreDataBlock.content, cursors.coreBlock, length - 1);
|
|
39
|
+
var value = readBits | (1 << (length - 1));
|
|
40
|
+
return value - this.parameters.offset;
|
|
41
|
+
};
|
|
42
|
+
return GammaCodec;
|
|
43
|
+
}(_base_1.default));
|
|
44
|
+
exports.default = GammaCodec;
|
|
45
|
+
//# sourceMappingURL=gamma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamma.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/gamma.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uCAAqD;AACrD,kDAA+B;AAE/B;IAAwC,8BAAS;IAC/C,oBAAY,UAAe,EAAE,QAAQ;QAAzB,2BAAA,EAAA,eAAe;QAA3B,YACE,kBAAM,UAAU,EAAE,QAAQ,CAAC,SAM5B;QALC,IAAI,KAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC3B,MAAM,IAAI,+BAAsB,CAC9B,UAAG,KAAI,CAAC,QAAQ,iDAA8C,CAC/D,CAAA;SACF;;IACH,CAAC;IAED,2BAAM,GAAN,UAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO;QACrD,IAAI,MAAM,GAAG,CAAC,CAAA;QAEd,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE;YACvE,MAAM,IAAI,CAAC,CAAA;SACZ;QAED,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAC5B,aAAa,CAAC,OAAO,EACrB,OAAO,CAAC,SAAS,EACjB,MAAM,GAAG,CAAC,CACX,CAAA;QAED,IAAM,KAAK,GAAG,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;QAC5C,OAAO,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;IACvC,CAAC;IACH,iBAAC;AAAD,CAAC,AA1BD,CAAwC,eAAS,GA0BhD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default class HuffmanIntCodec extends CramCodec {
|
|
2
|
+
_decode(slice: any, coreDataBlock: any, coreCursor: any): any;
|
|
3
|
+
buildCodeBook(): void;
|
|
4
|
+
codeBook: {} | undefined;
|
|
5
|
+
buildCodes(): void;
|
|
6
|
+
codes: {} | undefined;
|
|
7
|
+
buildCaches(): void;
|
|
8
|
+
sortedCodes: any[] | undefined;
|
|
9
|
+
sortedByValue: any[] | undefined;
|
|
10
|
+
sortedValuesByBitCode: any[] | undefined;
|
|
11
|
+
sortedBitCodes: any[] | undefined;
|
|
12
|
+
sortedBitLengthsByBitCode: any[] | undefined;
|
|
13
|
+
bitCodeToValue: any[] | undefined;
|
|
14
|
+
decode(slice: any, coreDataBlock: any, blocksByContentId: any, cursors: any): any;
|
|
15
|
+
_decodeZeroLengthCode(): any;
|
|
16
|
+
}
|
|
17
|
+
import CramCodec from "./_base";
|
|
@@ -1,208 +1,135 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
24
|
-
|
|
25
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
26
|
-
|
|
27
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
28
|
-
|
|
29
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/possibleConstructorReturn"));
|
|
30
|
-
|
|
31
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/getPrototypeOf"));
|
|
32
|
-
|
|
33
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/inherits"));
|
|
34
|
-
|
|
35
|
-
var _require = require('../../errors'),
|
|
36
|
-
CramMalformedError = _require.CramMalformedError;
|
|
37
|
-
|
|
38
|
-
var CramCodec = require('./_base');
|
|
39
|
-
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var errors_1 = require("../../errors");
|
|
22
|
+
var _base_1 = __importDefault(require("./_base"));
|
|
40
23
|
function numberOfSetBits(ii) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
var i = (ii - (ii >> 1)) & 0x55555555;
|
|
25
|
+
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
|
|
26
|
+
return (((i + (i >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24;
|
|
44
27
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!(0, _includes.default)(_context = ['byte', 'int']).call(_context, _this.dataType)) {
|
|
62
|
-
throw new TypeError("".concat(_this.dataType, " decoding not yet implemented by HUFFMAN_INT codec"));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_this.buildCodeBook();
|
|
66
|
-
|
|
67
|
-
_this.buildCodes();
|
|
68
|
-
|
|
69
|
-
_this.buildCaches(); // if this is a degenerate zero-length huffman code, special-case the decoding
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (_this.sortedCodes[0].bitLength === 0) _this._decode = _this._decodeZeroLengthCode;
|
|
73
|
-
return _this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
(0, _createClass2.default)(HuffmanIntCodec, [{
|
|
77
|
-
key: "buildCodeBook",
|
|
78
|
-
value: function buildCodeBook() {
|
|
79
|
-
var _this2 = this;
|
|
80
|
-
|
|
81
|
-
// parse the parameters together into a `codes` data structure
|
|
82
|
-
var codes = new Array(this.parameters.numCodes);
|
|
83
|
-
|
|
84
|
-
for (var i = 0; i < this.parameters.numCodes; i += 1) {
|
|
85
|
-
codes[i] = {
|
|
86
|
-
symbol: this.parameters.symbols[i],
|
|
87
|
-
bitLength: this.parameters.bitLengths[i]
|
|
88
|
-
};
|
|
89
|
-
} // sort the codes by bit length and symbol value
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
codes = (0, _sort.default)(codes).call(codes, function (a, b) {
|
|
93
|
-
return a.bitLength - b.bitLength || a.symbol - b.symbol;
|
|
94
|
-
});
|
|
95
|
-
this.codeBook = {};
|
|
96
|
-
(0, _forEach.default)(codes).call(codes, function (code) {
|
|
97
|
-
if (!_this2.codeBook[code.bitLength]) _this2.codeBook[code.bitLength] = [];
|
|
98
|
-
|
|
99
|
-
_this2.codeBook[code.bitLength].push(code.symbol);
|
|
100
|
-
});
|
|
28
|
+
var HuffmanIntCodec = /** @class */ (function (_super) {
|
|
29
|
+
__extends(HuffmanIntCodec, _super);
|
|
30
|
+
function HuffmanIntCodec(parameters, dataType) {
|
|
31
|
+
if (parameters === void 0) { parameters = {}; }
|
|
32
|
+
var _this = _super.call(this, parameters, dataType) || this;
|
|
33
|
+
if (!['byte', 'int'].includes(_this.dataType)) {
|
|
34
|
+
throw new TypeError("".concat(_this.dataType, " decoding not yet implemented by HUFFMAN_INT codec"));
|
|
35
|
+
}
|
|
36
|
+
_this.buildCodeBook();
|
|
37
|
+
_this.buildCodes();
|
|
38
|
+
_this.buildCaches();
|
|
39
|
+
// if this is a degenerate zero-length huffman code, special-case the decoding
|
|
40
|
+
if (_this.sortedCodes[0].bitLength === 0) {
|
|
41
|
+
_this._decode = _this._decodeZeroLengthCode;
|
|
42
|
+
}
|
|
43
|
+
return _this;
|
|
101
44
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var code = {
|
|
121
|
-
bitLength: bitLength,
|
|
122
|
-
value: symbol
|
|
123
|
-
};
|
|
124
|
-
codeValue += 1;
|
|
125
|
-
var delta = bitLength - codeLength; // new length?
|
|
126
|
-
|
|
127
|
-
codeValue <<= delta; // pad with 0's
|
|
128
|
-
|
|
129
|
-
code.bitCode = codeValue; // calculated: huffman code
|
|
130
|
-
|
|
131
|
-
codeLength += delta; // adjust current code length
|
|
132
|
-
|
|
133
|
-
if (numberOfSetBits(codeValue) > bitLength) throw new CramMalformedError('Symbol out of range');
|
|
134
|
-
_this3.codes[symbol] = code;
|
|
45
|
+
HuffmanIntCodec.prototype.buildCodeBook = function () {
|
|
46
|
+
var _this = this;
|
|
47
|
+
// parse the parameters together into a `codes` data structure
|
|
48
|
+
var codes = new Array(this.parameters.numCodes);
|
|
49
|
+
for (var i = 0; i < this.parameters.numCodes; i += 1) {
|
|
50
|
+
codes[i] = {
|
|
51
|
+
symbol: this.parameters.symbols[i],
|
|
52
|
+
bitLength: this.parameters.bitLengths[i],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// sort the codes by bit length and symbol value
|
|
56
|
+
codes = codes.sort(function (a, b) { return a.bitLength - b.bitLength || a.symbol - b.symbol; });
|
|
57
|
+
this.codeBook = {};
|
|
58
|
+
codes.forEach(function (code) {
|
|
59
|
+
if (!_this.codeBook[code.bitLength]) {
|
|
60
|
+
_this.codeBook[code.bitLength] = [];
|
|
61
|
+
}
|
|
62
|
+
_this.codeBook[code.bitLength].push(code.symbol);
|
|
135
63
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
64
|
+
};
|
|
65
|
+
HuffmanIntCodec.prototype.buildCodes = function () {
|
|
66
|
+
var _this = this;
|
|
67
|
+
this.codes = {}; /* new TreeMap<Integer, HuffmanBitCode>(); */
|
|
68
|
+
var codeLength = 0;
|
|
69
|
+
var codeValue = -1;
|
|
70
|
+
Object.entries(this.codeBook).forEach(function (_a) {
|
|
71
|
+
var bitLength = _a[0], symbols = _a[1];
|
|
72
|
+
bitLength = parseInt(bitLength, 10);
|
|
73
|
+
symbols.forEach(function (symbol) {
|
|
74
|
+
var code = { bitLength: bitLength, value: symbol };
|
|
75
|
+
codeValue += 1;
|
|
76
|
+
var delta = bitLength - codeLength; // new length?
|
|
77
|
+
codeValue <<= delta; // pad with 0's
|
|
78
|
+
code.bitCode = codeValue; // calculated: huffman code
|
|
79
|
+
codeLength += delta; // adjust current code length
|
|
80
|
+
if (numberOfSetBits(codeValue) > bitLength) {
|
|
81
|
+
throw new errors_1.CramMalformedError('Symbol out of range');
|
|
82
|
+
}
|
|
83
|
+
_this.codes[symbol] = code;
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
HuffmanIntCodec.prototype.buildCaches = function () {
|
|
88
|
+
this.sortedCodes = Object.values(this.codes).sort(function (a, b) { return a.bitLength - b.bitLength || a.bitCode - b.bitCode; });
|
|
89
|
+
// this.sortedValues = this.parameters.values.sort((a,b) => a-b)
|
|
90
|
+
this.sortedByValue = Object.values(this.codes).sort(function (a, b) { return a.value - b.value; });
|
|
91
|
+
this.sortedValuesByBitCode = this.sortedCodes.map(function (c) { return c.value; });
|
|
92
|
+
this.sortedBitCodes = this.sortedCodes.map(function (c) { return c.bitCode; });
|
|
93
|
+
this.sortedBitLengthsByBitCode = this.sortedCodes.map(function (c) { return c.bitLength; });
|
|
94
|
+
var maxBitCode = Math.max.apply(Math, this.sortedBitCodes);
|
|
95
|
+
this.bitCodeToValue = new Array(maxBitCode + 1).fill(-1);
|
|
96
|
+
for (var i = 0; i < this.sortedBitCodes.length; i += 1) {
|
|
97
|
+
this.bitCodeToValue[this.sortedCodes[i].bitCode] = i;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
HuffmanIntCodec.prototype.decode = function (slice, coreDataBlock, blocksByContentId, cursors) {
|
|
101
|
+
return this._decode(slice, coreDataBlock, cursors.coreBlock);
|
|
102
|
+
};
|
|
103
|
+
// _decodeNull() {
|
|
171
104
|
// return -1
|
|
172
105
|
// }
|
|
173
106
|
// the special case for zero-length codes
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
for (var j = i; this.sortedCodes[j + 1].bitLength === length && j < this.sortedCodes.length; j += 1) {
|
|
197
|
-
i += 1;
|
|
198
|
-
}
|
|
107
|
+
HuffmanIntCodec.prototype._decodeZeroLengthCode = function () {
|
|
108
|
+
return this.sortedCodes[0].value;
|
|
109
|
+
};
|
|
110
|
+
HuffmanIntCodec.prototype._decode = function (slice, coreDataBlock, coreCursor) {
|
|
111
|
+
var input = coreDataBlock.content;
|
|
112
|
+
var prevLen = 0;
|
|
113
|
+
var bits = 0;
|
|
114
|
+
for (var i = 0; i < this.sortedCodes.length; i += 1) {
|
|
115
|
+
var length_1 = this.sortedCodes[i].bitLength;
|
|
116
|
+
bits <<= length_1 - prevLen;
|
|
117
|
+
bits |= this._getBits(input, coreCursor, length_1 - prevLen);
|
|
118
|
+
prevLen = length_1;
|
|
119
|
+
{
|
|
120
|
+
var index = this.bitCodeToValue[bits];
|
|
121
|
+
if (index > -1 && this.sortedBitLengthsByBitCode[index] === length_1) {
|
|
122
|
+
return this.sortedValuesByBitCode[index];
|
|
123
|
+
}
|
|
124
|
+
for (var j = i; this.sortedCodes[j + 1].bitLength === length_1 &&
|
|
125
|
+
j < this.sortedCodes.length; j += 1) {
|
|
126
|
+
i += 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
199
129
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}(CramCodec);
|
|
207
|
-
|
|
208
|
-
module.exports = HuffmanIntCodec;
|
|
130
|
+
throw new errors_1.CramMalformedError('Huffman symbol not found.');
|
|
131
|
+
};
|
|
132
|
+
return HuffmanIntCodec;
|
|
133
|
+
}(_base_1.default));
|
|
134
|
+
exports.default = HuffmanIntCodec;
|
|
135
|
+
//# sourceMappingURL=huffman.js.map
|