@gmod/cram 4.0.4 → 4.0.6
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/README.md +53 -51
- package/dist/cram-bundle.js +1 -1
- package/dist/cramFile/codecs/_base.d.ts +1 -1
- package/dist/cramFile/codecs/byteArrayLength.js +3 -2
- package/dist/cramFile/codecs/byteArrayLength.js.map +1 -1
- package/dist/cramFile/codecs/external.d.ts +1 -1
- package/dist/cramFile/codecs/external.js +1 -4
- package/dist/cramFile/codecs/external.js.map +1 -1
- package/dist/cramFile/container/index.d.ts +16 -34
- package/dist/cramFile/container/index.js +5 -20
- package/dist/cramFile/container/index.js.map +1 -1
- package/dist/cramFile/file.d.ts +8 -6
- package/dist/cramFile/file.js +37 -73
- package/dist/cramFile/file.js.map +1 -1
- package/dist/cramFile/record.js.map +1 -1
- package/dist/cramFile/sectionParsers.js +3 -2
- package/dist/cramFile/sectionParsers.js.map +1 -1
- package/dist/cramFile/slice/decodeRecord.d.ts +2 -2
- package/dist/cramFile/slice/decodeRecord.js +7 -4
- package/dist/cramFile/slice/decodeRecord.js.map +1 -1
- package/dist/cramFile/slice/index.js +14 -16
- package/dist/cramFile/slice/index.js.map +1 -1
- package/dist/cramFile/util.d.ts +5 -0
- package/dist/cramFile/util.js +75 -51
- package/dist/cramFile/util.js.map +1 -1
- package/esm/cramFile/codecs/_base.d.ts +1 -1
- package/esm/cramFile/codecs/byteArrayLength.js +3 -2
- package/esm/cramFile/codecs/byteArrayLength.js.map +1 -1
- package/esm/cramFile/codecs/external.d.ts +1 -1
- package/esm/cramFile/codecs/external.js +2 -5
- package/esm/cramFile/codecs/external.js.map +1 -1
- package/esm/cramFile/container/index.d.ts +16 -34
- package/esm/cramFile/container/index.js +5 -20
- package/esm/cramFile/container/index.js.map +1 -1
- package/esm/cramFile/file.d.ts +8 -6
- package/esm/cramFile/file.js +37 -73
- package/esm/cramFile/file.js.map +1 -1
- package/esm/cramFile/record.js.map +1 -1
- package/esm/cramFile/sectionParsers.js +3 -2
- package/esm/cramFile/sectionParsers.js.map +1 -1
- package/esm/cramFile/slice/decodeRecord.d.ts +2 -2
- package/esm/cramFile/slice/decodeRecord.js +7 -4
- package/esm/cramFile/slice/decodeRecord.js.map +1 -1
- package/esm/cramFile/slice/index.js +14 -16
- package/esm/cramFile/slice/index.js.map +1 -1
- package/esm/cramFile/util.d.ts +5 -0
- package/esm/cramFile/util.js +74 -51
- package/esm/cramFile/util.js.map +1 -1
- package/package.json +3 -6
- package/src/cramFile/codecs/_base.ts +1 -1
- package/src/cramFile/codecs/byteArrayLength.ts +4 -12
- package/src/cramFile/codecs/external.ts +3 -7
- package/src/cramFile/container/index.ts +5 -24
- package/src/cramFile/file.ts +41 -77
- package/src/cramFile/record.ts +1 -1
- package/src/cramFile/sectionParsers.ts +5 -2
- package/src/cramFile/slice/decodeRecord.ts +26 -23
- package/src/cramFile/slice/index.ts +25 -31
- package/src/cramFile/util.ts +107 -73
- package/errors.js +0 -27
package/src/cramFile/util.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { fromBytesBE, toNumber } from 'longfn'
|
|
2
1
|
import md5 from 'md5'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
export const TWO_PWR_16_DBL = 1 << 16
|
|
4
|
+
export const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL
|
|
5
|
+
export const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL
|
|
6
|
+
export const TWO_PWR_24_DBL = 1 << 24
|
|
7
|
+
export const TWO_PWR_56_DBL = TWO_PWR_24_DBL * TWO_PWR_32_DBL
|
|
5
8
|
|
|
6
9
|
export function itf8Size(v: number) {
|
|
7
10
|
if (!(v & ~0x7f)) {
|
|
@@ -23,108 +26,144 @@ export function parseItf8(buffer: Uint8Array, initialOffset: number) {
|
|
|
23
26
|
let offset = initialOffset
|
|
24
27
|
const countFlags = buffer[offset]!
|
|
25
28
|
let result: number
|
|
29
|
+
|
|
30
|
+
// Single byte value (0xxxxxxx)
|
|
26
31
|
if (countFlags < 0x80) {
|
|
27
32
|
result = countFlags
|
|
28
|
-
offset
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
offset += 1
|
|
34
|
+
}
|
|
35
|
+
// Two byte value (10xxxxxx)
|
|
36
|
+
else if (countFlags < 0xc0) {
|
|
37
|
+
result = ((countFlags & 0x3f) << 8) | buffer[offset + 1]!
|
|
38
|
+
offset += 2
|
|
39
|
+
}
|
|
40
|
+
// Three byte value (110xxxxx)
|
|
41
|
+
else if (countFlags < 0xe0) {
|
|
33
42
|
result =
|
|
34
|
-
((countFlags
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
((countFlags & 0x1f) << 16) |
|
|
44
|
+
(buffer[offset + 1]! << 8) |
|
|
45
|
+
buffer[offset + 2]!
|
|
46
|
+
offset += 3
|
|
47
|
+
}
|
|
48
|
+
// Four byte value (1110xxxx)
|
|
49
|
+
else if (countFlags < 0xf0) {
|
|
38
50
|
result =
|
|
39
|
-
((countFlags << 24) |
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
((countFlags & 0x0f) << 24) |
|
|
52
|
+
(buffer[offset + 1]! << 16) |
|
|
53
|
+
(buffer[offset + 2]! << 8) |
|
|
54
|
+
buffer[offset + 3]!
|
|
55
|
+
offset += 4
|
|
56
|
+
}
|
|
57
|
+
// Five byte value (11110xxx)
|
|
58
|
+
else {
|
|
46
59
|
result =
|
|
47
60
|
((countFlags & 0x0f) << 28) |
|
|
48
61
|
(buffer[offset + 1]! << 20) |
|
|
49
62
|
(buffer[offset + 2]! << 12) |
|
|
50
63
|
(buffer[offset + 3]! << 4) |
|
|
51
64
|
(buffer[offset + 4]! & 0x0f)
|
|
52
|
-
|
|
53
|
-
// TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;
|
|
54
|
-
offset = offset + 5
|
|
55
|
-
}
|
|
56
|
-
if (offset > buffer.length) {
|
|
57
|
-
throw new CramBufferOverrunError(
|
|
58
|
-
'Attempted to read beyond end of buffer; this file seems truncated.',
|
|
59
|
-
)
|
|
65
|
+
offset += 5
|
|
60
66
|
}
|
|
67
|
+
|
|
61
68
|
return [result, offset - initialOffset] as const
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
export function parseLtf8(buffer: Uint8Array, initialOffset: number) {
|
|
65
|
-
const dataView = new DataView(buffer.buffer)
|
|
66
72
|
let offset = initialOffset
|
|
67
73
|
const countFlags = buffer[offset]!
|
|
68
|
-
let
|
|
74
|
+
let value: number
|
|
75
|
+
|
|
76
|
+
// Single byte value < 0x80
|
|
69
77
|
if (countFlags < 0x80) {
|
|
70
|
-
|
|
78
|
+
value = countFlags
|
|
71
79
|
offset += 1
|
|
72
|
-
}
|
|
73
|
-
|
|
80
|
+
}
|
|
81
|
+
// Two byte value < 0xC0
|
|
82
|
+
else if (countFlags < 0xc0) {
|
|
83
|
+
value = ((countFlags << 8) | buffer[offset + 1]!) & 0x3fff
|
|
74
84
|
offset += 2
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
}
|
|
86
|
+
// Three byte value < 0xE0
|
|
87
|
+
else if (countFlags < 0xe0) {
|
|
88
|
+
value =
|
|
89
|
+
((countFlags & 0x3f) << 16) |
|
|
90
|
+
(buffer[offset + 1]! << 8) |
|
|
91
|
+
buffer[offset + 2]!
|
|
82
92
|
offset += 3
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
}
|
|
94
|
+
// Four byte value < 0xF0
|
|
95
|
+
else if (countFlags < 0xf0) {
|
|
96
|
+
value =
|
|
97
|
+
((countFlags & 0x1f) << 24) |
|
|
98
|
+
(buffer[offset + 1]! << 16) |
|
|
99
|
+
(buffer[offset + 2]! << 8) |
|
|
100
|
+
buffer[offset + 3]!
|
|
90
101
|
offset += 4
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
}
|
|
103
|
+
// Five byte value < 0xF8
|
|
104
|
+
else if (countFlags < 0xf8) {
|
|
105
|
+
value =
|
|
106
|
+
(buffer[offset]! & 0x0f) * TWO_PWR_32_DBL +
|
|
107
|
+
((buffer[offset + 1]! << 24) |
|
|
108
|
+
(buffer[offset + 2]! << 16) |
|
|
95
109
|
(buffer[offset + 3]! << 8) |
|
|
96
110
|
buffer[offset + 4]!)
|
|
97
|
-
// TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;
|
|
98
111
|
offset += 5
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
((buffer[offset +
|
|
112
|
+
}
|
|
113
|
+
// Six byte value < 0xFC
|
|
114
|
+
else if (countFlags < 0xfc) {
|
|
115
|
+
value =
|
|
116
|
+
(((buffer[offset]! & 0x07) << 8) | buffer[offset + 1]!) * TWO_PWR_32_DBL +
|
|
117
|
+
((buffer[offset + 2]! << 24) |
|
|
118
|
+
(buffer[offset + 3]! << 16) |
|
|
104
119
|
(buffer[offset + 4]! << 8) |
|
|
105
120
|
buffer[offset + 5]!)
|
|
106
121
|
offset += 6
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
}
|
|
123
|
+
// Seven byte value < 0xFE
|
|
124
|
+
else if (countFlags < 0xfe) {
|
|
125
|
+
value =
|
|
126
|
+
(((buffer[offset]! & 0x03) << 16) |
|
|
110
127
|
(buffer[offset + 1]! << 8) |
|
|
111
128
|
buffer[offset + 2]!) *
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
129
|
+
TWO_PWR_32_DBL +
|
|
130
|
+
((buffer[offset + 3]! << 24) |
|
|
131
|
+
(buffer[offset + 4]! << 16) |
|
|
115
132
|
(buffer[offset + 5]! << 8) |
|
|
116
133
|
buffer[offset + 6]!)
|
|
117
134
|
offset += 7
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
135
|
+
}
|
|
136
|
+
// Eight byte value < 0xFF
|
|
137
|
+
else if (countFlags < 0xff) {
|
|
138
|
+
value =
|
|
139
|
+
((buffer[offset + 1]! << 24) |
|
|
140
|
+
(buffer[offset + 2]! << 16) |
|
|
141
|
+
(buffer[offset + 3]! << 8) |
|
|
142
|
+
buffer[offset + 4]!) *
|
|
143
|
+
TWO_PWR_32_DBL +
|
|
144
|
+
((buffer[offset + 5]! << 24) |
|
|
145
|
+
(buffer[offset + 6]! << 16) |
|
|
146
|
+
(buffer[offset + 7]! << 8) |
|
|
147
|
+
buffer[offset + 8]!)
|
|
121
148
|
offset += 8
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
149
|
+
}
|
|
150
|
+
// Nine byte value
|
|
151
|
+
else {
|
|
152
|
+
value =
|
|
153
|
+
buffer[offset + 1]! * TWO_PWR_56_DBL +
|
|
154
|
+
((buffer[offset + 2]! << 24) |
|
|
155
|
+
(buffer[offset + 3]! << 16) |
|
|
156
|
+
(buffer[offset + 4]! << 8) |
|
|
157
|
+
buffer[offset + 5]!) *
|
|
158
|
+
TWO_PWR_32_DBL +
|
|
159
|
+
((buffer[offset + 6]! << 24) |
|
|
160
|
+
(buffer[offset + 7]! << 16) |
|
|
161
|
+
(buffer[offset + 8]! << 8) |
|
|
162
|
+
buffer[offset + 9]!)
|
|
125
163
|
offset += 9
|
|
126
164
|
}
|
|
127
|
-
|
|
165
|
+
|
|
166
|
+
return [value, offset - initialOffset] as const
|
|
128
167
|
}
|
|
129
168
|
|
|
130
169
|
export function parseItem<T>(
|
|
@@ -140,11 +179,6 @@ export function parseItem<T>(
|
|
|
140
179
|
_size: offset - startBufferPosition,
|
|
141
180
|
}
|
|
142
181
|
}
|
|
143
|
-
|
|
144
|
-
// this would be nice as a decorator, but i'm a little worried about babel
|
|
145
|
-
// support for it going away or changing. memoizes a method in the stupidest
|
|
146
|
-
// possible way, with no regard for the arguments. actually, this only works
|
|
147
|
-
// on methods that take no arguments
|
|
148
182
|
export function tinyMemoize(_class: any, methodName: any) {
|
|
149
183
|
const method = _class.prototype[methodName]
|
|
150
184
|
const memoAttrName = `_memo_${methodName}`
|
package/errors.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CramArgumentError = exports.CramSizeLimitError = exports.CramMalformedError = exports.CramUnimplementedError = exports.CramError = void 0;
|
|
4
|
-
class CramError extends Error {
|
|
5
|
-
}
|
|
6
|
-
exports.CramError = CramError;
|
|
7
|
-
/** Error caused by encountering a part of the CRAM spec that has not yet been implemented */
|
|
8
|
-
class CramUnimplementedError extends Error {
|
|
9
|
-
}
|
|
10
|
-
exports.CramUnimplementedError = CramUnimplementedError;
|
|
11
|
-
/** An error caused by malformed data. */
|
|
12
|
-
class CramMalformedError extends CramError {
|
|
13
|
-
}
|
|
14
|
-
exports.CramMalformedError = CramMalformedError;
|
|
15
|
-
/**
|
|
16
|
-
* An error caused by data being too big, exceeding a size limit.
|
|
17
|
-
*/
|
|
18
|
-
class CramSizeLimitError extends CramError {
|
|
19
|
-
}
|
|
20
|
-
exports.CramSizeLimitError = CramSizeLimitError;
|
|
21
|
-
/**
|
|
22
|
-
* An invalid argument was supplied to a cram-js method or object.
|
|
23
|
-
*/
|
|
24
|
-
class CramArgumentError extends CramError {
|
|
25
|
-
}
|
|
26
|
-
exports.CramArgumentError = CramArgumentError;
|
|
27
|
-
//# sourceMappingURL=errors.js.map
|