@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.
Files changed (60) hide show
  1. package/README.md +53 -51
  2. package/dist/cram-bundle.js +1 -1
  3. package/dist/cramFile/codecs/_base.d.ts +1 -1
  4. package/dist/cramFile/codecs/byteArrayLength.js +3 -2
  5. package/dist/cramFile/codecs/byteArrayLength.js.map +1 -1
  6. package/dist/cramFile/codecs/external.d.ts +1 -1
  7. package/dist/cramFile/codecs/external.js +1 -4
  8. package/dist/cramFile/codecs/external.js.map +1 -1
  9. package/dist/cramFile/container/index.d.ts +16 -34
  10. package/dist/cramFile/container/index.js +5 -20
  11. package/dist/cramFile/container/index.js.map +1 -1
  12. package/dist/cramFile/file.d.ts +8 -6
  13. package/dist/cramFile/file.js +37 -73
  14. package/dist/cramFile/file.js.map +1 -1
  15. package/dist/cramFile/record.js.map +1 -1
  16. package/dist/cramFile/sectionParsers.js +3 -2
  17. package/dist/cramFile/sectionParsers.js.map +1 -1
  18. package/dist/cramFile/slice/decodeRecord.d.ts +2 -2
  19. package/dist/cramFile/slice/decodeRecord.js +7 -4
  20. package/dist/cramFile/slice/decodeRecord.js.map +1 -1
  21. package/dist/cramFile/slice/index.js +14 -16
  22. package/dist/cramFile/slice/index.js.map +1 -1
  23. package/dist/cramFile/util.d.ts +5 -0
  24. package/dist/cramFile/util.js +75 -51
  25. package/dist/cramFile/util.js.map +1 -1
  26. package/esm/cramFile/codecs/_base.d.ts +1 -1
  27. package/esm/cramFile/codecs/byteArrayLength.js +3 -2
  28. package/esm/cramFile/codecs/byteArrayLength.js.map +1 -1
  29. package/esm/cramFile/codecs/external.d.ts +1 -1
  30. package/esm/cramFile/codecs/external.js +2 -5
  31. package/esm/cramFile/codecs/external.js.map +1 -1
  32. package/esm/cramFile/container/index.d.ts +16 -34
  33. package/esm/cramFile/container/index.js +5 -20
  34. package/esm/cramFile/container/index.js.map +1 -1
  35. package/esm/cramFile/file.d.ts +8 -6
  36. package/esm/cramFile/file.js +37 -73
  37. package/esm/cramFile/file.js.map +1 -1
  38. package/esm/cramFile/record.js.map +1 -1
  39. package/esm/cramFile/sectionParsers.js +3 -2
  40. package/esm/cramFile/sectionParsers.js.map +1 -1
  41. package/esm/cramFile/slice/decodeRecord.d.ts +2 -2
  42. package/esm/cramFile/slice/decodeRecord.js +7 -4
  43. package/esm/cramFile/slice/decodeRecord.js.map +1 -1
  44. package/esm/cramFile/slice/index.js +14 -16
  45. package/esm/cramFile/slice/index.js.map +1 -1
  46. package/esm/cramFile/util.d.ts +5 -0
  47. package/esm/cramFile/util.js +74 -51
  48. package/esm/cramFile/util.js.map +1 -1
  49. package/package.json +3 -6
  50. package/src/cramFile/codecs/_base.ts +1 -1
  51. package/src/cramFile/codecs/byteArrayLength.ts +4 -12
  52. package/src/cramFile/codecs/external.ts +3 -7
  53. package/src/cramFile/container/index.ts +5 -24
  54. package/src/cramFile/file.ts +41 -77
  55. package/src/cramFile/record.ts +1 -1
  56. package/src/cramFile/sectionParsers.ts +5 -2
  57. package/src/cramFile/slice/decodeRecord.ts +26 -23
  58. package/src/cramFile/slice/index.ts +25 -31
  59. package/src/cramFile/util.ts +107 -73
  60. package/errors.js +0 -27
@@ -1,7 +1,10 @@
1
- import { fromBytesBE, toNumber } from 'longfn'
2
1
  import md5 from 'md5'
3
2
 
4
- import { CramBufferOverrunError } from './codecs/getBits'
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 = offset + 1
29
- } else if (countFlags < 0xc0) {
30
- result = ((countFlags << 8) | buffer[offset + 1]!) & 0x3fff
31
- offset = offset + 2
32
- } else if (countFlags < 0xe0) {
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 << 16) | (buffer[offset + 1]! << 8) | buffer[offset + 2]!) &
35
- 0x1fffff
36
- offset = offset + 3
37
- } else if (countFlags < 0xf0) {
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
- (buffer[offset + 1]! << 16) |
41
- (buffer[offset + 2]! << 8) |
42
- buffer[offset + 3]!) &
43
- 0x0fffffff
44
- offset = offset + 4
45
- } else {
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
- // x=((0xff & 0x0f)<<28) | (0xff<<20) | (0xff<<12) | (0xff<<4) | (0x0f & 0x0f);
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 n: number
74
+ let value: number
75
+
76
+ // Single byte value < 0x80
69
77
  if (countFlags < 0x80) {
70
- n = countFlags
78
+ value = countFlags
71
79
  offset += 1
72
- } else if (countFlags < 0xc0) {
73
- n = ((buffer[offset]! << 8) | buffer[offset + 1]!) & 0x3fff
80
+ }
81
+ // Two byte value < 0xC0
82
+ else if (countFlags < 0xc0) {
83
+ value = ((countFlags << 8) | buffer[offset + 1]!) & 0x3fff
74
84
  offset += 2
75
- } else if (countFlags < 0xe0) {
76
- n =
77
- ((buffer[offset]! << 16) |
78
- (buffer[offset + 1]! << 8) |
79
- buffer[offset + 2]!) &
80
- 0x1fffff
81
- n = ((countFlags & 63) << 16) | dataView.getUint16(offset + 1, true)
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
- } else if (countFlags < 0xf0) {
84
- n =
85
- ((buffer[offset]! << 24) |
86
- (buffer[offset + 1]! << 16) |
87
- (buffer[offset + 2]! << 8) |
88
- buffer[offset + 3]!) &
89
- 0x0fffffff
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
- } else if (countFlags < 0xf8) {
92
- n =
93
- ((buffer[offset]! & 15) * 2 ** 32 + (buffer[offset + 1]! << 24)) |
94
- ((buffer[offset + 2]! << 16) |
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
- } else if (countFlags < 0xfc) {
100
- n =
101
- ((((buffer[offset]! & 7) << 8) | buffer[offset + 1]!) * 2 ** 32 +
102
- (buffer[offset + 2]! << 24)) |
103
- ((buffer[offset + 3]! << 16) |
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
- } else if (countFlags < 0xfe) {
108
- n =
109
- ((((buffer[offset]! & 3) << 16) |
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
- 2 ** 32 +
113
- (buffer[offset + 3]! << 24)) |
114
- ((buffer[offset + 4]! << 16) |
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
- } else if (countFlags < 0xff) {
119
- n = toNumber(fromBytesBE(buffer.slice(offset + 1, offset + 8), false))
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
- } else {
123
- n = toNumber(fromBytesBE(buffer.subarray(offset + 1, offset + 9), false))
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
- return [n, offset - initialOffset] as const
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