@gmod/cram 1.5.9 → 1.6.2
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 +90 -0
- package/README.md +182 -172
- package/dist/craiIndex.d.ts +37 -0
- package/dist/craiIndex.js +196 -301
- package/dist/craiIndex.js.map +1 -0
- package/dist/cram-bundle.js +6 -15
- 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 -766
- 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/dist/unzip-pako.d.ts +2 -0
- package/dist/unzip-pako.js +9 -0
- package/dist/unzip-pako.js.map +1 -0
- package/dist/unzip.d.ts +2 -0
- package/dist/unzip.js +6 -0
- package/dist/unzip.js.map +1 -0
- package/errors.js +66 -103
- package/esm/craiIndex.d.ts +37 -0
- package/esm/craiIndex.js +158 -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/esm/unzip-pako.d.ts +2 -0
- package/esm/unzip-pako.js +5 -0
- package/esm/unzip-pako.js.map +1 -0
- package/esm/unzip.d.ts +2 -0
- package/esm/unzip.js +3 -0
- package/esm/unzip.js.map +1 -0
- package/package.json +38 -35
- package/src/craiIndex.js +180 -0
- package/src/cramFile/codecs/_base.js +49 -0
- package/src/cramFile/codecs/beta.js +23 -0
- package/src/cramFile/codecs/byteArrayLength.js +55 -0
- package/src/cramFile/codecs/byteArrayStop.js +50 -0
- package/src/cramFile/codecs/external.js +54 -0
- package/src/cramFile/codecs/gamma.js +30 -0
- package/src/cramFile/codecs/huffman.js +137 -0
- package/src/cramFile/codecs/index.js +38 -0
- package/src/cramFile/codecs/subexp.js +32 -0
- package/src/cramFile/constants.js +55 -0
- package/src/cramFile/container/compressionScheme.js +144 -0
- package/src/cramFile/container/index.js +119 -0
- package/src/cramFile/file.js +347 -0
- package/src/cramFile/index.js +3 -0
- package/src/cramFile/record.js +337 -0
- package/src/cramFile/sectionParsers.js +379 -0
- package/src/cramFile/slice/decodeRecord.js +362 -0
- package/src/cramFile/slice/index.js +497 -0
- package/src/cramFile/util.js +169 -0
- package/src/errors.js +22 -0
- package/src/index.js +5 -0
- package/src/indexedCramFile.js +191 -0
- package/src/io/bufferCache.js +66 -0
- package/src/io/index.js +26 -0
- package/src/io/localFile.js +35 -0
- package/src/io/remoteFile.js +71 -0
- package/src/rans/README.md +1 -0
- package/src/rans/constants.js +5 -0
- package/src/rans/d04.js +83 -0
- package/src/rans/d14.js +59 -0
- package/src/rans/decoding.js +141 -0
- package/src/rans/frequencies.js +121 -0
- package/src/rans/index.js +249 -0
- package/src/sam.js +15 -0
- package/src/unzip-pako.ts +5 -0
- package/src/unzip.ts +2 -0
package/dist/unzip.d.ts
ADDED
package/dist/unzip.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unzip = void 0;
|
|
4
|
+
var zlib_1 = require("zlib");
|
|
5
|
+
Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return zlib_1.gunzipSync; } });
|
|
6
|
+
//# sourceMappingURL=unzip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unzip.js","sourceRoot":"","sources":["../src/unzip.ts"],"names":[],"mappings":";;;AAAA,6BAAiC;AACV,sFADd,iBAAU,OACS"}
|
package/errors.js
CHANGED
|
@@ -1,115 +1,78 @@
|
|
|
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
|
-
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CramArgumentError = exports.CramSizeLimitError = exports.CramBufferOverrunError = exports.CramMalformedError = exports.CramUnimplementedError = exports.CramError = void 0;
|
|
19
|
+
var CramError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(CramError, _super);
|
|
21
|
+
function CramError() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return CramError;
|
|
25
|
+
}(Error));
|
|
26
|
+
exports.CramError = CramError;
|
|
27
27
|
/** Error caused by encountering a part of the CRAM spec that has not yet been implemented */
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(0, _classCallCheck2.default)(this, CramUnimplementedError);
|
|
37
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CramUnimplementedError).apply(this, arguments));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return CramUnimplementedError;
|
|
41
|
-
}((0, _wrapNativeSuper2.default)(Error));
|
|
28
|
+
var CramUnimplementedError = /** @class */ (function (_super) {
|
|
29
|
+
__extends(CramUnimplementedError, _super);
|
|
30
|
+
function CramUnimplementedError() {
|
|
31
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
32
|
+
}
|
|
33
|
+
return CramUnimplementedError;
|
|
34
|
+
}(Error));
|
|
35
|
+
exports.CramUnimplementedError = CramUnimplementedError;
|
|
42
36
|
/** An error caused by malformed data. */
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(0, _classCallCheck2.default)(this, CramMalformedError);
|
|
52
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CramMalformedError).apply(this, arguments));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return CramMalformedError;
|
|
56
|
-
}(CramError);
|
|
37
|
+
var CramMalformedError = /** @class */ (function (_super) {
|
|
38
|
+
__extends(CramMalformedError, _super);
|
|
39
|
+
function CramMalformedError() {
|
|
40
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
41
|
+
}
|
|
42
|
+
return CramMalformedError;
|
|
43
|
+
}(CramError));
|
|
44
|
+
exports.CramMalformedError = CramMalformedError;
|
|
57
45
|
/**
|
|
58
46
|
* An error caused by attempting to read beyond the end of the defined data.
|
|
59
47
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(0, _classCallCheck2.default)(this, CramBufferOverrunError);
|
|
69
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CramBufferOverrunError).apply(this, arguments));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return CramBufferOverrunError;
|
|
73
|
-
}(CramMalformedError);
|
|
48
|
+
var CramBufferOverrunError = /** @class */ (function (_super) {
|
|
49
|
+
__extends(CramBufferOverrunError, _super);
|
|
50
|
+
function CramBufferOverrunError() {
|
|
51
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
52
|
+
}
|
|
53
|
+
return CramBufferOverrunError;
|
|
54
|
+
}(CramMalformedError));
|
|
55
|
+
exports.CramBufferOverrunError = CramBufferOverrunError;
|
|
74
56
|
/**
|
|
75
57
|
* An error caused by data being too big, exceeding a size limit.
|
|
76
58
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(0, _classCallCheck2.default)(this, CramSizeLimitError);
|
|
86
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CramSizeLimitError).apply(this, arguments));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return CramSizeLimitError;
|
|
90
|
-
}(CramError);
|
|
59
|
+
var CramSizeLimitError = /** @class */ (function (_super) {
|
|
60
|
+
__extends(CramSizeLimitError, _super);
|
|
61
|
+
function CramSizeLimitError() {
|
|
62
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
63
|
+
}
|
|
64
|
+
return CramSizeLimitError;
|
|
65
|
+
}(CramError));
|
|
66
|
+
exports.CramSizeLimitError = CramSizeLimitError;
|
|
91
67
|
/**
|
|
92
68
|
* An invalid argument was supplied to a cram-js method or object.
|
|
93
69
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CramArgumentError).apply(this, arguments));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return CramArgumentError;
|
|
107
|
-
}(CramError);
|
|
108
|
-
|
|
109
|
-
module.exports = {
|
|
110
|
-
CramBufferOverrunError: CramBufferOverrunError,
|
|
111
|
-
CramMalformedError: CramMalformedError,
|
|
112
|
-
CramUnimplementedError: CramUnimplementedError,
|
|
113
|
-
CramSizeLimitError: CramSizeLimitError,
|
|
114
|
-
CramArgumentError: CramArgumentError
|
|
115
|
-
};
|
|
70
|
+
var CramArgumentError = /** @class */ (function (_super) {
|
|
71
|
+
__extends(CramArgumentError, _super);
|
|
72
|
+
function CramArgumentError() {
|
|
73
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
74
|
+
}
|
|
75
|
+
return CramArgumentError;
|
|
76
|
+
}(CramError));
|
|
77
|
+
exports.CramArgumentError = CramArgumentError;
|
|
78
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default class CraiIndex {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {object} args
|
|
5
|
+
* @param {string} [args.path]
|
|
6
|
+
* @param {string} [args.url]
|
|
7
|
+
* @param {FileHandle} [args.filehandle]
|
|
8
|
+
*/
|
|
9
|
+
constructor(args: {
|
|
10
|
+
path?: string | undefined;
|
|
11
|
+
url?: string | undefined;
|
|
12
|
+
filehandle?: any;
|
|
13
|
+
});
|
|
14
|
+
_parseCache: AbortablePromiseCache<any, any>;
|
|
15
|
+
readFile: any;
|
|
16
|
+
parseIndex(): any;
|
|
17
|
+
getIndex(opts?: {}): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* @param {number} seqId
|
|
20
|
+
* @returns {Promise} true if the index contains entries for
|
|
21
|
+
* the given reference sequence ID, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
hasDataForReferenceSequence(seqId: number): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* fetch index entries for the given range
|
|
26
|
+
*
|
|
27
|
+
* @param {number} seqId
|
|
28
|
+
* @param {number} queryStart
|
|
29
|
+
* @param {number} queryEnd
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise} promise for
|
|
32
|
+
* an array of objects of the form
|
|
33
|
+
* `{start, span, containerStart, sliceStart, sliceBytes }`
|
|
34
|
+
*/
|
|
35
|
+
getEntriesForRange(seqId: number, queryStart: number, queryEnd: number): Promise<any>;
|
|
36
|
+
}
|
|
37
|
+
import AbortablePromiseCache from "abortable-promise-cache";
|
package/esm/craiIndex.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import AbortablePromiseCache from 'abortable-promise-cache';
|
|
2
|
+
import QuickLRU from 'quick-lru';
|
|
3
|
+
import { unzip } from './unzip';
|
|
4
|
+
import { open } from './io';
|
|
5
|
+
import { CramMalformedError } from './errors';
|
|
6
|
+
const BAI_MAGIC = 21578050; // BAI\1
|
|
7
|
+
class Slice {
|
|
8
|
+
constructor(args) {
|
|
9
|
+
Object.assign(this, args);
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return `${this.start}:${this.span}:${this.containerStart}:${this.sliceStart}:${this.sliceBytes}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function addRecordToIndex(index, record) {
|
|
16
|
+
if (record.some(el => el === undefined)) {
|
|
17
|
+
throw new CramMalformedError('invalid .crai index file');
|
|
18
|
+
}
|
|
19
|
+
const [seqId, start, span, containerStart, sliceStart, sliceBytes] = record;
|
|
20
|
+
if (!index[seqId]) {
|
|
21
|
+
index[seqId] = [];
|
|
22
|
+
}
|
|
23
|
+
index[seqId].push(new Slice({
|
|
24
|
+
start,
|
|
25
|
+
span,
|
|
26
|
+
containerStart,
|
|
27
|
+
sliceStart,
|
|
28
|
+
sliceBytes,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
export default class CraiIndex {
|
|
32
|
+
// A CRAM index (.crai) is a gzipped tab delimited file containing the following columns:
|
|
33
|
+
// 1. Sequence id
|
|
34
|
+
// 2. Alignment start
|
|
35
|
+
// 3. Alignment span
|
|
36
|
+
// 4. Container start byte position in the file
|
|
37
|
+
// 5. Slice start byte position in the container data (‘blocks’)
|
|
38
|
+
// 6. Slice size in bytes
|
|
39
|
+
// Each line represents a slice in the CRAM file. Please note that all slices must be listed in index file.
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {object} args
|
|
43
|
+
* @param {string} [args.path]
|
|
44
|
+
* @param {string} [args.url]
|
|
45
|
+
* @param {FileHandle} [args.filehandle]
|
|
46
|
+
*/
|
|
47
|
+
constructor(args) {
|
|
48
|
+
const filehandle = open(args.url, args.path, args.filehandle);
|
|
49
|
+
this._parseCache = new AbortablePromiseCache({
|
|
50
|
+
cache: new QuickLRU({ maxSize: 1 }),
|
|
51
|
+
fill: (data, signal) => this.parseIndex({ signal }),
|
|
52
|
+
});
|
|
53
|
+
this.readFile = filehandle.readFile.bind(filehandle);
|
|
54
|
+
}
|
|
55
|
+
parseIndex() {
|
|
56
|
+
const index = {};
|
|
57
|
+
return this.readFile()
|
|
58
|
+
.then(data => {
|
|
59
|
+
if (data[0] === 31 && data[1] === 139) {
|
|
60
|
+
return unzip(data);
|
|
61
|
+
}
|
|
62
|
+
return data;
|
|
63
|
+
})
|
|
64
|
+
.then(uncompressedBuffer => {
|
|
65
|
+
if (uncompressedBuffer.length > 4 &&
|
|
66
|
+
uncompressedBuffer.readUInt32LE(0) === BAI_MAGIC) {
|
|
67
|
+
throw new CramMalformedError('invalid .crai index file. note: file appears to be a .bai index. this is technically legal but please open a github issue if you need support');
|
|
68
|
+
}
|
|
69
|
+
// interpret the text as regular ascii, since it is
|
|
70
|
+
// supposed to be only digits and whitespace characters
|
|
71
|
+
// this is written in a deliberately low-level fashion for performance,
|
|
72
|
+
// because some .crai files can be pretty large.
|
|
73
|
+
let currentRecord = [];
|
|
74
|
+
let currentString = '';
|
|
75
|
+
for (let i = 0; i < uncompressedBuffer.length; i += 1) {
|
|
76
|
+
const charCode = uncompressedBuffer[i];
|
|
77
|
+
if ((charCode >= 48 && charCode <= 57) /* 0-9 */ ||
|
|
78
|
+
(!currentString && charCode === 45) /* leading - */) {
|
|
79
|
+
currentString += String.fromCharCode(charCode);
|
|
80
|
+
}
|
|
81
|
+
else if (charCode === 9 /* \t */) {
|
|
82
|
+
currentRecord.push(Number.parseInt(currentString, 10));
|
|
83
|
+
currentString = '';
|
|
84
|
+
}
|
|
85
|
+
else if (charCode === 10 /* \n */) {
|
|
86
|
+
currentRecord.push(Number.parseInt(currentString, 10));
|
|
87
|
+
currentString = '';
|
|
88
|
+
addRecordToIndex(index, currentRecord);
|
|
89
|
+
currentRecord = [];
|
|
90
|
+
}
|
|
91
|
+
else if (charCode !== 13 /* \r */ && charCode !== 32 /* space */) {
|
|
92
|
+
// if there are other characters in the file besides
|
|
93
|
+
// space and \r, something is wrong.
|
|
94
|
+
throw new CramMalformedError('invalid .crai index file');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// if the file ends without a \n, we need to flush our buffers
|
|
98
|
+
if (currentString) {
|
|
99
|
+
currentRecord.push(Number.parseInt(currentString, 10));
|
|
100
|
+
}
|
|
101
|
+
if (currentRecord.length === 6) {
|
|
102
|
+
addRecordToIndex(index, currentRecord);
|
|
103
|
+
}
|
|
104
|
+
// sort each of them by start
|
|
105
|
+
Object.entries(index).forEach(([seqId, ent]) => {
|
|
106
|
+
index[seqId] = ent.sort((a, b) => a.start - b.start || a.span - b.span);
|
|
107
|
+
});
|
|
108
|
+
return index;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
getIndex(opts = {}) {
|
|
112
|
+
return this._parseCache.get('index', null, opts.signal);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @param {number} seqId
|
|
116
|
+
* @returns {Promise} true if the index contains entries for
|
|
117
|
+
* the given reference sequence ID, false otherwise
|
|
118
|
+
*/
|
|
119
|
+
async hasDataForReferenceSequence(seqId) {
|
|
120
|
+
return !!(await this.getIndex())[seqId];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* fetch index entries for the given range
|
|
124
|
+
*
|
|
125
|
+
* @param {number} seqId
|
|
126
|
+
* @param {number} queryStart
|
|
127
|
+
* @param {number} queryEnd
|
|
128
|
+
*
|
|
129
|
+
* @returns {Promise} promise for
|
|
130
|
+
* an array of objects of the form
|
|
131
|
+
* `{start, span, containerStart, sliceStart, sliceBytes }`
|
|
132
|
+
*/
|
|
133
|
+
async getEntriesForRange(seqId, queryStart, queryEnd) {
|
|
134
|
+
const seqEntries = (await this.getIndex())[seqId];
|
|
135
|
+
if (!seqEntries) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
const compare = entry => {
|
|
139
|
+
const entryStart = entry.start;
|
|
140
|
+
const entryEnd = entry.start + entry.span;
|
|
141
|
+
if (entryStart >= queryEnd) {
|
|
142
|
+
return -1;
|
|
143
|
+
} // entry is ahead of query
|
|
144
|
+
if (entryEnd <= queryStart) {
|
|
145
|
+
return 1;
|
|
146
|
+
} // entry is behind query
|
|
147
|
+
return 0; // entry overlaps query
|
|
148
|
+
};
|
|
149
|
+
const bins = [];
|
|
150
|
+
for (let i = 0; i < seqEntries.length; i += 1) {
|
|
151
|
+
if (compare(seqEntries[i]) === 0) {
|
|
152
|
+
bins.push(seqEntries[i]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return bins;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=craiIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"craiIndex.js","sourceRoot":"","sources":["../src/craiIndex.js"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAE7C,MAAM,SAAS,GAAG,QAAQ,CAAA,CAAC,QAAQ;AAEnC,MAAM,KAAK;IACT,YAAY,IAAI;QACd,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,EAAE,CAAA;IAClG,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,KAAK,EAAE,MAAM;IACrC,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,EAAE;QACvC,MAAM,IAAI,kBAAkB,CAAC,0BAA0B,CAAC,CAAA;KACzD;IAED,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,MAAM,CAAA;IAE3E,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACjB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;KAClB;IAED,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAC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K,CAAA;YAC9B,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAA;YACzC,IAAI,UAAU,IAAI,QAAQ,EAAE;gBAC1B,OAAO,CAAC,CAAC,CAAA;aACV,CAAC,0BAA0B;YAC5B,IAAI,QAAQ,IAAI,UAAU,EAAE;gBAC1B,OAAO,CAAC,CAAA;aACT,CAAC,wBAAwB;YAC1B,OAAO,CAAC,CAAA,CAAC,uBAAuB;QAClC,CAAC,CAAA;QACD,MAAM,IAAI,GAAG,EAAE,CAAA;QACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YAC7C,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;gBAChC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;aACzB;SACF;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CramBufferOverrunError } from '../../errors';
|
|
2
|
+
const validDataTypes = {
|
|
3
|
+
int: true,
|
|
4
|
+
byte: true,
|
|
5
|
+
long: true,
|
|
6
|
+
byteArray: true,
|
|
7
|
+
byteArrayBlock: true,
|
|
8
|
+
};
|
|
9
|
+
// codec base class
|
|
10
|
+
export default class CramCodec {
|
|
11
|
+
constructor(parameters = {}, dataType) {
|
|
12
|
+
this.parameters = parameters;
|
|
13
|
+
this.dataType = dataType;
|
|
14
|
+
if (!dataType) {
|
|
15
|
+
throw new TypeError('must provide a data type to codec constructor');
|
|
16
|
+
}
|
|
17
|
+
if (!validDataTypes[dataType]) {
|
|
18
|
+
throw new TypeError(`invalid data type ${dataType}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// decode(slice, coreDataBlock, blocksByContentId, cursors) {
|
|
22
|
+
// }
|
|
23
|
+
_getBits(data, cursor, numBits) {
|
|
24
|
+
let val = 0;
|
|
25
|
+
if (cursor.bytePosition + (7 - cursor.bitPosition + numBits) / 8 >
|
|
26
|
+
data.length) {
|
|
27
|
+
throw new CramBufferOverrunError('read error during decoding. the file seems to be truncated.');
|
|
28
|
+
}
|
|
29
|
+
for (let dlen = numBits; dlen; dlen -= 1) {
|
|
30
|
+
// get the next `dlen` bits in the input, put them in val
|
|
31
|
+
val <<= 1;
|
|
32
|
+
val |= (data[cursor.bytePosition] >> cursor.bitPosition) & 1;
|
|
33
|
+
cursor.bitPosition -= 1;
|
|
34
|
+
if (cursor.bitPosition < 0) {
|
|
35
|
+
cursor.bytePosition += 1;
|
|
36
|
+
}
|
|
37
|
+
cursor.bitPosition &= 7;
|
|
38
|
+
}
|
|
39
|
+
return val;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=_base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_base.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/_base.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAErD,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,IAAI;IACf,cAAc,EAAE,IAAI;CACrB,CAAA;AAED,mBAAmB;AACnB,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,YAAY,UAAU,GAAG,EAAE,EAAE,QAAQ;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAA;SACrE;QACD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YAC7B,MAAM,IAAI,SAAS,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAA;SACrD;IACH,CAAC;IAED,6DAA6D;IAC7D,IAAI;IAEJ,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO;QAC5B,IAAI,GAAG,GAAG,CAAC,CAAA;QACX,IACE,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;YAC5D,IAAI,CAAC,MAAM,EACX;YACA,MAAM,IAAI,sBAAsB,CAC9B,6DAA6D,CAC9D,CAAA;SACF;QACD,KAAK,IAAI,IAAI,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE;YACxC,yDAAyD;YACzD,GAAG,KAAK,CAAC,CAAA;YACT,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;YAC5D,MAAM,CAAC,WAAW,IAAI,CAAC,CAAA;YACvB,IAAI,MAAM,CAAC,WAAW,GAAG,CAAC,EAAE;gBAC1B,MAAM,CAAC,YAAY,IAAI,CAAC,CAAA;aACzB;YACD,MAAM,CAAC,WAAW,IAAI,CAAC,CAAA;SACxB;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CramUnimplementedError } from '../../errors';
|
|
2
|
+
import CramCodec from './_base';
|
|
3
|
+
export default class BetaCodec extends CramCodec {
|
|
4
|
+
constructor(parameters = {}, dataType) {
|
|
5
|
+
super(parameters, dataType);
|
|
6
|
+
if (this.dataType !== 'int') {
|
|
7
|
+
throw new CramUnimplementedError(`${this.dataType} decoding not yet implemented by BETA codec`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
decode(slice, coreDataBlock, blocksByContentId, cursors) {
|
|
11
|
+
const data = this._getBits(coreDataBlock.content, cursors.coreBlock, this.parameters.length) - this.parameters.offset;
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=beta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beta.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/beta.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,SAAS,MAAM,SAAS,CAAA;AAE/B,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,SAAS;IAC9C,YAAY,UAAU,GAAG,EAAE,EAAE,QAAQ;QACnC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAC3B,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC3B,MAAM,IAAI,sBAAsB,CAC9B,GAAG,IAAI,CAAC,QAAQ,6CAA6C,CAC9D,CAAA;SACF;IACH,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO;QACrD,MAAM,IAAI,GACR,IAAI,CAAC,QAAQ,CACX,aAAa,CAAC,OAAO,EACrB,OAAO,CAAC,SAAS,EACjB,IAAI,CAAC,UAAU,CAAC,MAAM,CACvB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;QAC5B,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default class ByteArrayStopCodec extends CramCodec {
|
|
2
|
+
constructor(parameters: {} | undefined, dataType: any, instantiateCodec: any);
|
|
3
|
+
instantiateCodec: any;
|
|
4
|
+
decode(slice: any, coreDataBlock: any, blocksByContentId: any, cursors: any): any[];
|
|
5
|
+
_getLengthCodec(): any;
|
|
6
|
+
_getDataCodec(): any;
|
|
7
|
+
}
|
|
8
|
+
import CramCodec from "./_base";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { tinyMemoize } from '../util';
|
|
2
|
+
import CramCodec from './_base';
|
|
3
|
+
export default class ByteArrayStopCodec extends CramCodec {
|
|
4
|
+
constructor(parameters = {}, dataType, instantiateCodec) {
|
|
5
|
+
super(parameters, dataType);
|
|
6
|
+
this.instantiateCodec = instantiateCodec;
|
|
7
|
+
if (dataType !== 'byteArray') {
|
|
8
|
+
throw new TypeError(`byteArrayLength does not support data type ${dataType}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
decode(slice, coreDataBlock, blocksByContentId, cursors) {
|
|
12
|
+
const lengthCodec = this._getLengthCodec();
|
|
13
|
+
const arrayLength = lengthCodec.decode(slice, coreDataBlock, blocksByContentId, cursors);
|
|
14
|
+
const dataCodec = this._getDataCodec();
|
|
15
|
+
const data = new Array(arrayLength);
|
|
16
|
+
for (let i = 0; i < arrayLength; i += 1) {
|
|
17
|
+
data[i] = dataCodec.decode(slice, coreDataBlock, blocksByContentId, cursors);
|
|
18
|
+
}
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
// memoize
|
|
22
|
+
_getLengthCodec() {
|
|
23
|
+
const encodingParams = this.parameters.lengthsEncoding;
|
|
24
|
+
return this.instantiateCodec(encodingParams, 'int');
|
|
25
|
+
}
|
|
26
|
+
// memoize
|
|
27
|
+
_getDataCodec() {
|
|
28
|
+
const encodingParams = this.parameters.valuesEncoding;
|
|
29
|
+
return this.instantiateCodec(encodingParams, 'byte');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
'_getLengthCodec _getDataCodec'
|
|
33
|
+
.split(' ')
|
|
34
|
+
.forEach(method => tinyMemoize(ByteArrayStopCodec, method));
|
|
35
|
+
//# sourceMappingURL=byteArrayLength.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byteArrayLength.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/byteArrayLength.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,SAAS,MAAM,SAAS,CAAA;AAE/B,MAAM,CAAC,OAAO,OAAO,kBAA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C;KACV,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export default class ByteArrayStopCodec extends CramCodec {
|
|
2
|
+
_decode: (contentBlock: any, cursor: any) => any;
|
|
3
|
+
decode(slice: any, coreDataBlock: any, blocksByContentId: any, cursors: any): any;
|
|
4
|
+
_decodeByteArray(contentBlock: any, cursor: any): any;
|
|
5
|
+
}
|
|
6
|
+
import CramCodec from "./_base";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CramBufferOverrunError, CramMalformedError } from '../../errors';
|
|
2
|
+
import CramCodec from './_base';
|
|
3
|
+
export default class ByteArrayStopCodec extends CramCodec {
|
|
4
|
+
constructor(parameters = {}, dataType) {
|
|
5
|
+
super(parameters, dataType);
|
|
6
|
+
if (dataType === 'byteArray') {
|
|
7
|
+
this._decode = this._decodeByteArray;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
throw new TypeError(`byteArrayStop codec does not support data type ${dataType}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
decode(slice, coreDataBlock, blocksByContentId, cursors) {
|
|
14
|
+
const { blockContentId } = this.parameters;
|
|
15
|
+
const contentBlock = blocksByContentId[blockContentId];
|
|
16
|
+
if (!contentBlock) {
|
|
17
|
+
throw new CramMalformedError(`no block found with content ID ${blockContentId}`);
|
|
18
|
+
}
|
|
19
|
+
const cursor = cursors.externalBlocks.getCursor(blockContentId);
|
|
20
|
+
return this._decode(contentBlock, cursor);
|
|
21
|
+
}
|
|
22
|
+
_decodeByteArray(contentBlock, cursor) {
|
|
23
|
+
const dataBuffer = contentBlock.content;
|
|
24
|
+
const { stopByte } = this.parameters;
|
|
25
|
+
// scan to the next stop byte
|
|
26
|
+
const startPosition = cursor.bytePosition;
|
|
27
|
+
let stopPosition = cursor.bytePosition;
|
|
28
|
+
while (dataBuffer[stopPosition] !== stopByte &&
|
|
29
|
+
stopPosition < dataBuffer.length) {
|
|
30
|
+
if (stopPosition === dataBuffer.length) {
|
|
31
|
+
throw new CramBufferOverrunError(`byteArrayStop reading beyond length of data buffer?`);
|
|
32
|
+
}
|
|
33
|
+
stopPosition += 1;
|
|
34
|
+
}
|
|
35
|
+
cursor.bytePosition = stopPosition + 1;
|
|
36
|
+
const data = dataBuffer.slice(startPosition, stopPosition);
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=byteArrayStop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byteArrayStop.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/byteArrayStop.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEzE,OAAO,SAAS,MAAM,SAAS,CAAA;AAE/B,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,SAAS;IACvD,YAAY,UAAU,GAAG,EAAE,EAAE,QAAQ;QACnC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAC3B,IAAI,QAAQ,KAAK,WAAW,EAAE;YAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAA;SACrC;aAAM;YACL,MAAM,IAAI,SAAS,CACjB,kDAAkD,QAAQ,EAAE,CAC7D,CAAA;SACF;IACH,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO;QACrD,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,UAAU,CAAA;QAC1C,MAAM,YAAY,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAA;QACtD,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,kBAAkB,CAC1B,kCAAkC,cAAc,EAAE,CACnD,CAAA;SACF;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;IAC3C,CAAC;IAED,gBAAgB,CAAC,YAAY,EAAE,MAAM;QACnC,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAA;QACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,UAAU,CAAA;QACpC,6BAA6B;QAC7B,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,CAAA;QACzC,IAAI,YAAY,GAAG,MAAM,CAAC,YAAY,CAAA;QACtC,OACE,UAAU,CAAC,YAAY,CAAC,KAAK,QAAQ;YACrC,YAAY,GAAG,UAAU,CAAC,MAAM,EAChC;YACA,IAAI,YAAY,KAAK,UAAU,CAAC,MAAM,EAAE;gBACtC,MAAM,IAAI,sBAAsB,CAC9B,qDAAqD,CACtD,CAAA;aACF;YACD,YAAY,IAAI,CAAC,CAAA;SAClB;QACD,MAAM,CAAC,YAAY,GAAG,YAAY,GAAG,CAAC,CAAA;QACtC,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;QAC1D,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default class ExternalCodec extends CramCodec {
|
|
2
|
+
_decodeData: (contentBlock: any, cursor: any) => any;
|
|
3
|
+
decode(slice: any, coreDataBlock: any, blocksByContentId: any, cursors: any): any;
|
|
4
|
+
_decodeInt(contentBlock: any, cursor: any): any;
|
|
5
|
+
_decodeByte(contentBlock: any, cursor: any): any;
|
|
6
|
+
}
|
|
7
|
+
import CramCodec from "./_base";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CramUnimplementedError, CramMalformedError, CramBufferOverrunError, } from '../../errors';
|
|
2
|
+
import CramCodec from './_base';
|
|
3
|
+
import { parseItf8 } from '../util';
|
|
4
|
+
export default class ExternalCodec extends CramCodec {
|
|
5
|
+
constructor(parameters = {}, dataType) {
|
|
6
|
+
super(parameters, dataType);
|
|
7
|
+
if (this.dataType === 'int') {
|
|
8
|
+
this._decodeData = this._decodeInt;
|
|
9
|
+
}
|
|
10
|
+
else if (this.dataType === 'byte') {
|
|
11
|
+
this._decodeData = this._decodeByte;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
throw new CramUnimplementedError(`${this.dataType} decoding not yet implemented by EXTERNAL codec`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
decode(slice, coreDataBlock, blocksByContentId, cursors) {
|
|
18
|
+
const { blockContentId } = this.parameters;
|
|
19
|
+
const contentBlock = blocksByContentId[blockContentId];
|
|
20
|
+
if (!contentBlock) {
|
|
21
|
+
throw new CramMalformedError(`no block found with content ID ${blockContentId}`);
|
|
22
|
+
}
|
|
23
|
+
const cursor = cursors.externalBlocks.getCursor(blockContentId);
|
|
24
|
+
return this._decodeData(contentBlock, cursor);
|
|
25
|
+
}
|
|
26
|
+
_decodeInt(contentBlock, cursor) {
|
|
27
|
+
const [result, bytesRead] = parseItf8(contentBlock.content, cursor.bytePosition);
|
|
28
|
+
cursor.bytePosition += bytesRead;
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
_decodeByte(contentBlock, cursor) {
|
|
32
|
+
if (cursor.bytePosition >= contentBlock.content.length) {
|
|
33
|
+
throw new CramBufferOverrunError('attempted to read beyond end of block. this file seems truncated.');
|
|
34
|
+
}
|
|
35
|
+
const result = contentBlock.content[cursor.bytePosition];
|
|
36
|
+
cursor.bytePosition += 1;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=external.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../../src/cramFile/codecs/external.js"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,GACvB,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