@gmod/cram 2.0.3 → 3.0.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +0 -4
  3. package/dist/craiIndex.js +1 -1
  4. package/dist/craiIndex.js.map +1 -1
  5. package/dist/cram-bundle.js +1 -1
  6. package/dist/cram-bundle.js.LICENSE.txt +0 -2
  7. package/dist/cramFile/codecs/byteArrayLength.js +1 -1
  8. package/dist/cramFile/codecs/byteArrayLength.js.map +1 -1
  9. package/dist/cramFile/codecs/byteArrayStop.d.ts +0 -1
  10. package/dist/cramFile/codecs/external.js +1 -1
  11. package/dist/cramFile/codecs/external.js.map +1 -1
  12. package/dist/cramFile/codecs/getBits.d.ts +0 -1
  13. package/dist/cramFile/codecs/getBits.js +2 -2
  14. package/dist/cramFile/codecs/getBits.js.map +1 -1
  15. package/dist/cramFile/codecs/huffman.js +2 -1
  16. package/dist/cramFile/codecs/huffman.js.map +1 -1
  17. package/dist/cramFile/codecs/index.js +1 -2
  18. package/dist/cramFile/codecs/index.js.map +1 -1
  19. package/dist/cramFile/container/compressionScheme.d.ts +0 -3
  20. package/dist/cramFile/container/compressionScheme.js +0 -4
  21. package/dist/cramFile/container/compressionScheme.js.map +1 -1
  22. package/dist/cramFile/container/index.d.ts +57 -5
  23. package/dist/cramFile/container/index.js +15 -9
  24. package/dist/cramFile/container/index.js.map +1 -1
  25. package/dist/cramFile/file.d.ts +24 -61
  26. package/dist/cramFile/file.js +23 -28
  27. package/dist/cramFile/file.js.map +1 -1
  28. package/dist/cramFile/record.d.ts +1 -1
  29. package/dist/cramFile/sectionParsers.d.ts +195 -49
  30. package/dist/cramFile/sectionParsers.js +622 -304
  31. package/dist/cramFile/sectionParsers.js.map +1 -1
  32. package/dist/cramFile/slice/decodeRecord.js +1 -1
  33. package/dist/cramFile/slice/decodeRecord.js.map +1 -1
  34. package/dist/cramFile/slice/index.d.ts +23 -1
  35. package/dist/cramFile/slice/index.js +9 -6
  36. package/dist/cramFile/slice/index.js.map +1 -1
  37. package/dist/cramFile/util.d.ts +6 -6
  38. package/dist/cramFile/util.js +93 -12
  39. package/dist/cramFile/util.js.map +1 -1
  40. package/dist/indexedCramFile.d.ts +0 -3
  41. package/dist/indexedCramFile.js +4 -16
  42. package/dist/indexedCramFile.js.map +1 -1
  43. package/dist/io/index.d.ts +1 -3
  44. package/dist/io/index.js +3 -16
  45. package/dist/io/index.js.map +1 -1
  46. package/dist/rans/d04.js +1 -1
  47. package/dist/rans/d04.js.map +1 -1
  48. package/dist/rans/d14.js +1 -1
  49. package/dist/rans/d14.js.map +1 -1
  50. package/dist/rans/frequencies.js +2 -3
  51. package/dist/rans/frequencies.js.map +1 -1
  52. package/dist/rans/index.js +1 -1
  53. package/dist/rans/index.js.map +1 -1
  54. package/dist/sam.js +1 -2
  55. package/dist/sam.js.map +1 -1
  56. package/dist/typescript.d.ts +0 -1
  57. package/dist/typescript.js +0 -8
  58. package/dist/typescript.js.map +1 -1
  59. package/dist/unzip-pako.d.ts +0 -1
  60. package/dist/unzip-pako.js +1 -2
  61. package/dist/unzip-pako.js.map +1 -1
  62. package/dist/unzip.d.ts +0 -1
  63. package/esm/craiIndex.js +1 -1
  64. package/esm/craiIndex.js.map +1 -1
  65. package/esm/cramFile/codecs/byteArrayLength.js +1 -1
  66. package/esm/cramFile/codecs/byteArrayLength.js.map +1 -1
  67. package/esm/cramFile/codecs/byteArrayStop.d.ts +0 -1
  68. package/esm/cramFile/codecs/external.js +1 -1
  69. package/esm/cramFile/codecs/external.js.map +1 -1
  70. package/esm/cramFile/codecs/getBits.d.ts +0 -1
  71. package/esm/cramFile/codecs/huffman.js +2 -1
  72. package/esm/cramFile/codecs/huffman.js.map +1 -1
  73. package/esm/cramFile/container/compressionScheme.d.ts +0 -3
  74. package/esm/cramFile/container/compressionScheme.js +0 -4
  75. package/esm/cramFile/container/compressionScheme.js.map +1 -1
  76. package/esm/cramFile/container/index.d.ts +57 -5
  77. package/esm/cramFile/container/index.js +15 -9
  78. package/esm/cramFile/container/index.js.map +1 -1
  79. package/esm/cramFile/file.d.ts +24 -61
  80. package/esm/cramFile/file.js +22 -25
  81. package/esm/cramFile/file.js.map +1 -1
  82. package/esm/cramFile/record.d.ts +1 -1
  83. package/esm/cramFile/sectionParsers.d.ts +195 -49
  84. package/esm/cramFile/sectionParsers.js +620 -303
  85. package/esm/cramFile/sectionParsers.js.map +1 -1
  86. package/esm/cramFile/slice/index.d.ts +23 -1
  87. package/esm/cramFile/slice/index.js +10 -7
  88. package/esm/cramFile/slice/index.js.map +1 -1
  89. package/esm/cramFile/util.d.ts +6 -6
  90. package/esm/cramFile/util.js +87 -6
  91. package/esm/cramFile/util.js.map +1 -1
  92. package/esm/indexedCramFile.d.ts +0 -3
  93. package/esm/indexedCramFile.js +3 -15
  94. package/esm/indexedCramFile.js.map +1 -1
  95. package/esm/io/index.d.ts +1 -3
  96. package/esm/io/index.js +2 -11
  97. package/esm/io/index.js.map +1 -1
  98. package/esm/typescript.d.ts +0 -1
  99. package/esm/typescript.js +1 -6
  100. package/esm/typescript.js.map +1 -1
  101. package/esm/unzip-pako.d.ts +0 -1
  102. package/esm/unzip.d.ts +0 -1
  103. package/package.json +9 -15
  104. package/src/craiIndex.ts +1 -1
  105. package/src/cramFile/codecs/byteArrayLength.ts +1 -2
  106. package/src/cramFile/codecs/external.ts +1 -1
  107. package/src/cramFile/codecs/huffman.ts +2 -1
  108. package/src/cramFile/container/compressionScheme.ts +1 -8
  109. package/src/cramFile/container/index.ts +21 -10
  110. package/src/cramFile/file.ts +28 -43
  111. package/src/cramFile/record.ts +1 -1
  112. package/src/cramFile/sectionParsers.ts +668 -390
  113. package/src/cramFile/slice/index.ts +11 -5
  114. package/src/cramFile/util.ts +90 -91
  115. package/src/indexedCramFile.ts +3 -25
  116. package/src/io/index.ts +2 -12
  117. package/src/typescript.ts +0 -7
  118. package/src/typings/binary-parser.d.ts +0 -44
@@ -7,6 +7,7 @@ import CramRecord from '../record'
7
7
  import CramContainer from '../container'
8
8
  import CramFile, { CramFileBlock } from '../file'
9
9
  import {
10
+ getSectionParsers,
10
11
  isMappedSliceHeader,
11
12
  MappedSliceHeader,
12
13
  UnmappedSliceHeader,
@@ -191,10 +192,15 @@ export default class CramSlice {
191
192
  }
192
193
 
193
194
  // memoize
194
- async getHeader(): Promise<SliceHeader> {
195
+ async getHeader() {
195
196
  // fetch and parse the slice header
196
- const sectionParsers = await this.file.getSectionParsers()
197
+ const { majorVersion } = await this.file.getDefinition()
198
+ const sectionParsers = getSectionParsers(majorVersion)
197
199
  const containerHeader = await this.container.getHeader()
200
+ if (!containerHeader) {
201
+ throw new Error('no container header detected')
202
+ }
203
+
198
204
  const header = await this.file.readBlock(
199
205
  containerHeader._endPosition + this.containerPosition,
200
206
  )
@@ -230,7 +236,7 @@ export default class CramSlice {
230
236
  // read all the blocks into memory and store them
231
237
  let blockPosition = header._endPosition
232
238
  const blocks: CramFileBlock[] = new Array(header.parsedContent.numBlocks)
233
- for (let i = 0; i < blocks.length; i += 1) {
239
+ for (let i = 0; i < blocks.length; i++) {
234
240
  const block = await this.file.readBlock(blockPosition)
235
241
  if (block === undefined) {
236
242
  throw new Error('block undefined')
@@ -363,14 +369,14 @@ export default class CramSlice {
363
369
  this.file.options.checkSequenceMD5 &&
364
370
  isMappedSliceHeader(sliceHeader.parsedContent) &&
365
371
  sliceHeader.parsedContent.refSeqId >= 0 &&
366
- sliceHeader.parsedContent.md5.join('') !== '0000000000000000'
372
+ sliceHeader.parsedContent.md5?.join('') !== '0000000000000000'
367
373
  ) {
368
374
  const refRegion = await this.getReferenceRegion()
369
375
  if (refRegion) {
370
376
  const { seq, start, end } = refRegion
371
377
  const seqMd5 = sequenceMD5(seq)
372
378
  const storedMd5 = sliceHeader.parsedContent.md5
373
- .map(byte => (byte < 16 ? '0' : '') + byte.toString(16))
379
+ ?.map(byte => (byte < 16 ? '0' : '') + byte.toString(16))
374
380
  .join('')
375
381
  if (seqMd5 !== storedMd5) {
376
382
  throw new CramMalformedError(
@@ -1,5 +1,5 @@
1
1
  import md5 from 'md5'
2
- import { Parser } from '@gmod/binary-parser'
2
+ import Long from 'long'
3
3
  import { CramBufferOverrunError } from './codecs/getBits'
4
4
 
5
5
  export function itf8Size(v: number) {
@@ -18,10 +18,7 @@ export function itf8Size(v: number) {
18
18
  return 5
19
19
  }
20
20
 
21
- export function parseItf8(
22
- buffer: Uint8Array,
23
- initialOffset: number,
24
- ): [number, number] {
21
+ export function parseItf8(buffer: Uint8Array, initialOffset: number) {
25
22
  let offset = initialOffset
26
23
  const countFlags = buffer[offset]
27
24
  let result
@@ -60,106 +57,108 @@ export function parseItf8(
60
57
  'Attempted to read beyond end of buffer; this file seems truncated.',
61
58
  )
62
59
  }
63
- return [result, offset - initialOffset]
60
+ return [result, offset - initialOffset] as const
64
61
  }
65
62
 
66
- // parseLtf8(buffer, initialOffset) {
67
- // let offset = initialOffset
68
- // const countFlags = buffer[offset]
69
- // let result
70
- // if (countFlags < 0x80) {
71
- // result = countFlags
72
- // offset += 1
73
- // } else if (countFlags < 0xc0) {
74
- // result = ((buffer[offset] << 8) | buffer[offset + 1]) & 0x3fff
75
- // offset += 2
76
- // } else if (countFlags < 0xe0) {
77
- // result =
78
- // ((buffer[offset] << 16) |
79
- // (buffer[offset + 1] << 8) |
80
- // buffer[offset + 2]) &
81
- // 0x1fffff
82
- // offset += 3
83
- // } else if (countFlags < 0xf0) {
84
- // result =
85
- // ((buffer[offset] << 24) |
86
- // (buffer[offset + 1] << 16) |
87
- // (buffer[offset + 2] << 8) |
88
- // buffer[offset + 3]) &
89
- // 0x0fffffff
90
- // offset += 4
91
- // } else if (countFlags < 0xf8) {
92
- // result =
93
- // ((buffer[offset] & 15) * Math.pow(2,32) + (buffer[offset + 1] << 24)) |
94
- // ((buffer[offset + 2] << 16) |
95
- // (buffer[offset + 3] << 8) |
96
- // buffer[offset + 4])
97
- // // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;
98
- // offset += 5
99
- // } else if (countFlags < 0xfc) {
100
- // result =
101
- // ((((buffer[offset] & 7) << 8) | buffer[offset + 1]) * Math.pow(2,32) +
102
- // (buffer[offset + 2] << 24)) |
103
- // ((buffer[offset + 3] << 16) |
104
- // (buffer[offset + 4] << 8) |
105
- // buffer[offset + 5])
106
- // offset += 6
107
- // } else if (countFlags < 0xfe) {
108
- // result =
109
- // ((((buffer[offset] & 3) << 16) |
110
- // (buffer[offset + 1] << 8) |
111
- // buffer[offset + 2]) *
112
- // Math.pow(2,32) +
113
- // (buffer[offset + 3] << 24)) |
114
- // ((buffer[offset + 4] << 16) |
115
- // (buffer[offset + 5] << 8) |
116
- // buffer[offset + 6])
117
- // offset += 7
118
- // } else if (countFlags < 0xff) {
119
- // result = Long.fromBytesBE(buffer.slice(offset + 1, offset + 8))
120
- // if (
121
- // result.greaterThan(Number.MAX_SAFE_INTEGER) ||
122
- // result.lessThan(Number.MIN_SAFE_INTEGER)
123
- // )
124
- // throw new CramUnimplementedError('integer overflow')
125
- // result = result.toNumber()
126
- // offset += 8
127
- // } else {
128
- // result = Long.fromBytesBE(buffer.slice(offset + 1, offset + 9))
129
- // if (
130
- // result.greaterThan(Number.MAX_SAFE_INTEGER) ||
131
- // result.lessThan(Number.MIN_SAFE_INTEGER)
132
- // )
133
- // throw new CramUnimplementedError('integer overflow')
134
- // result = result.toNumber()
135
- // offset += 9
136
- // }
137
- // return [result, offset - initialOffset]
138
- // },
139
-
140
- export type ParsedItem<T> = T & {
141
- _endPosition: number
142
- _size: number
63
+ export function parseLtf8(buffer: Buffer, initialOffset: number) {
64
+ let offset = initialOffset
65
+ const countFlags = buffer[offset]
66
+ let n
67
+ if (countFlags < 0x80) {
68
+ n = countFlags
69
+ offset += 1
70
+ } else if (countFlags < 0xc0) {
71
+ n = ((buffer[offset] << 8) | buffer[offset + 1]) & 0x3fff
72
+ offset += 2
73
+ } else if (countFlags < 0xe0) {
74
+ n =
75
+ ((buffer[offset] << 16) |
76
+ (buffer[offset + 1] << 8) |
77
+ buffer[offset + 2]) &
78
+ 0x1fffff
79
+ n = ((countFlags & 63) << 16) | buffer.readUInt16LE(offset + 1)
80
+ offset += 3
81
+ } else if (countFlags < 0xf0) {
82
+ n =
83
+ ((buffer[offset] << 24) |
84
+ (buffer[offset + 1] << 16) |
85
+ (buffer[offset + 2] << 8) |
86
+ buffer[offset + 3]) &
87
+ 0x0fffffff
88
+ offset += 4
89
+ } else if (countFlags < 0xf8) {
90
+ n =
91
+ ((buffer[offset] & 15) * Math.pow(2, 32) + (buffer[offset + 1] << 24)) |
92
+ ((buffer[offset + 2] << 16) |
93
+ (buffer[offset + 3] << 8) |
94
+ buffer[offset + 4])
95
+ // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;
96
+ offset += 5
97
+ } else if (countFlags < 0xfc) {
98
+ n =
99
+ ((((buffer[offset] & 7) << 8) | buffer[offset + 1]) * Math.pow(2, 32) +
100
+ (buffer[offset + 2] << 24)) |
101
+ ((buffer[offset + 3] << 16) |
102
+ (buffer[offset + 4] << 8) |
103
+ buffer[offset + 5])
104
+ offset += 6
105
+ } else if (countFlags < 0xfe) {
106
+ n =
107
+ ((((buffer[offset] & 3) << 16) |
108
+ (buffer[offset + 1] << 8) |
109
+ buffer[offset + 2]) *
110
+ Math.pow(2, 32) +
111
+ (buffer[offset + 3] << 24)) |
112
+ ((buffer[offset + 4] << 16) |
113
+ (buffer[offset + 5] << 8) |
114
+ buffer[offset + 6])
115
+ offset += 7
116
+ } else if (countFlags < 0xff) {
117
+ n = Long.fromBytesBE(
118
+ buffer.slice(offset + 1, offset + 8) as unknown as number[],
119
+ )
120
+ if (
121
+ n.greaterThan(Number.MAX_SAFE_INTEGER) ||
122
+ n.lessThan(Number.MIN_SAFE_INTEGER)
123
+ ) {
124
+ throw new Error('integer overflow')
125
+ }
126
+ n = n.toNumber()
127
+ offset += 8
128
+ } else {
129
+ n = Long.fromBytesBE(
130
+ buffer.slice(offset + 1, offset + 9) as unknown as number[],
131
+ )
132
+ if (
133
+ n.greaterThan(Number.MAX_SAFE_INTEGER) ||
134
+ n.lessThan(Number.MIN_SAFE_INTEGER)
135
+ ) {
136
+ throw new Error('integer overflow')
137
+ }
138
+ n = n.toNumber()
139
+ offset += 9
140
+ }
141
+ return [n, offset - initialOffset] as const
143
142
  }
144
143
 
145
144
  export function parseItem<T>(
146
145
  buffer: Buffer,
147
- parser: Parser<T>,
146
+ parser: (buffer: Buffer, offset: number) => { offset: number; value: T },
148
147
  startBufferPosition = 0,
149
148
  startFilePosition = 0,
150
- ): ParsedItem<T> {
151
- const { offset, result } = parser.parse(buffer)
149
+ ) {
150
+ const { offset, value } = parser(buffer, startBufferPosition)
152
151
  return {
153
- ...result,
152
+ ...value,
154
153
  _endPosition: offset + startFilePosition,
155
154
  _size: offset - startBufferPosition,
156
155
  }
157
156
  }
158
157
 
159
- // this would be nice as a decorator, but i'm a little worried about
160
- // babel support for it going away or changing.
161
- // memoizes a method in the stupidest possible way, with no regard for the
162
- // arguments. actually, this only works on methods that take no arguments
158
+ // this would be nice as a decorator, but i'm a little worried about babel
159
+ // support for it going away or changing. memoizes a method in the stupidest
160
+ // possible way, with no regard for the arguments. actually, this only works
161
+ // on methods that take no arguments
163
162
  export function tinyMemoize(_class: any, methodName: any) {
164
163
  const method = _class.prototype[methodName]
165
164
  const memoAttrName = `_memo_${methodName}`
@@ -1,5 +1,4 @@
1
- import { CramSizeLimitError, CramUnimplementedError } from './errors'
2
-
1
+ import { CramUnimplementedError } from './errors'
3
2
  import CramFile from './cramFile'
4
3
  import CramRecord from './cramFile/record'
5
4
  import { SeqFetch } from './cramFile/file'
@@ -24,7 +23,6 @@ export interface CramIndexLike {
24
23
  export default class IndexedCramFile {
25
24
  public cram: CramFile
26
25
  public index: CramIndexLike
27
- private fetchSizeLimit: number
28
26
 
29
27
  /**
30
28
  *
@@ -32,14 +30,12 @@ export default class IndexedCramFile {
32
30
  * @param {CramFile} args.cram
33
31
  * @param {Index-like} args.index object that supports getEntriesForRange(seqId,start,end) -> Promise[Array[index entries]]
34
32
  * @param {number} [args.cacheSize] optional maximum number of CRAM records to cache. default 20,000
35
- * @param {number} [args.fetchSizeLimit] optional maximum number of bytes to fetch in a single getRecordsForRange call. Default 3 MiB.
36
33
  * @param {boolean} [args.checkSequenceMD5] - default true. if false, disables verifying the MD5
37
34
  * checksum of the reference sequence underlying a slice. In some applications, this check can cause an inconvenient amount (many megabases) of sequences to be fetched.
38
35
  */
39
36
  constructor(
40
37
  args: {
41
38
  index: CramIndexLike
42
- fetchSizeLimit?: number
43
39
  } & (
44
40
  | { cram: CramFile }
45
41
  | ({
@@ -70,8 +66,6 @@ export default class IndexedCramFile {
70
66
  if (!this.index.getEntriesForRange) {
71
67
  throw new Error('invalid arguments: not an index')
72
68
  }
73
-
74
- this.fetchSizeLimit = args.fetchSizeLimit || 3000000
75
69
  }
76
70
 
77
71
  /**
@@ -103,12 +97,6 @@ export default class IndexedCramFile {
103
97
  }
104
98
  const seqId = seq
105
99
  const slices = await this.index.getEntriesForRange(seqId, start, end)
106
- const totalSize = slices.map(s => s.sliceBytes).reduce((a, b) => a + b, 0)
107
- if (totalSize > this.fetchSizeLimit) {
108
- throw new CramSizeLimitError(
109
- `data size of ${totalSize.toLocaleString()} bytes exceeded fetch size limit of ${this.fetchSizeLimit.toLocaleString()} bytes`,
110
- )
111
- }
112
100
 
113
101
  // TODO: do we need to merge or de-duplicate the blocks?
114
102
 
@@ -180,17 +168,7 @@ export default class IndexedCramFile {
180
168
 
181
169
  const mateRecordPromises = []
182
170
  const mateFeatPromises: Promise<CramRecord[]>[] = []
183
-
184
- const mateTotalSize = mateChunks
185
- .map(s => s.sliceBytes)
186
- .reduce((a, b) => a + b, 0)
187
- if (mateTotalSize > this.fetchSizeLimit) {
188
- throw new Error(
189
- `mate data size of ${mateTotalSize.toLocaleString()} bytes exceeded fetch size limit of ${this.fetchSizeLimit.toLocaleString()} bytes`,
190
- )
191
- }
192
-
193
- mateChunks.forEach(c => {
171
+ for (const c of mateChunks) {
194
172
  let recordPromise = this.cram.featureCache.get(c.toString())
195
173
  if (!recordPromise) {
196
174
  recordPromise = this.getRecordsInSlice(c, () => true)
@@ -210,7 +188,7 @@ export default class IndexedCramFile {
210
188
  return mateRecs
211
189
  })
212
190
  mateFeatPromises.push(featPromise)
213
- })
191
+ }
214
192
  const newMateFeats = await Promise.all(mateFeatPromises)
215
193
  if (newMateFeats.length) {
216
194
  const newMates = newMateFeats.reduce((result, current) =>
package/src/io/index.ts CHANGED
@@ -1,16 +1,6 @@
1
- import url from 'url'
2
- import { ensureNotNullish } from '../typescript'
3
1
  import { Filehandle } from '../cramFile/filehandle'
4
2
  import { LocalFile, RemoteFile } from 'generic-filehandle'
5
3
 
6
- function fromUrl(source: string) {
7
- const { protocol, pathname } = url.parse(source)
8
- if (protocol === 'file:') {
9
- return new LocalFile(unescape(ensureNotNullish(pathname)))
10
- }
11
- return new RemoteFile(source)
12
- }
13
-
14
4
  function open(
15
5
  maybeUrl?: string,
16
6
  maybePath?: string,
@@ -20,7 +10,7 @@ function open(
20
10
  return maybeFilehandle
21
11
  }
22
12
  if (maybeUrl) {
23
- return fromUrl(maybeUrl)
13
+ return new RemoteFile(maybeUrl)
24
14
  }
25
15
  if (maybePath) {
26
16
  return new LocalFile(maybePath)
@@ -28,6 +18,6 @@ function open(
28
18
  throw new Error('no url, path, or filehandle provided, cannot open')
29
19
  }
30
20
 
31
- export { fromUrl, open }
21
+ export { open }
32
22
 
33
23
  export { LocalFile, RemoteFile } from 'generic-filehandle'
package/src/typescript.ts CHANGED
@@ -1,10 +1,3 @@
1
- export function ensureNotNullish<T>(x: T | null | undefined): T {
2
- if (x === null || x === undefined) {
3
- throw new Error('Value must not be nullish.')
4
- }
5
- return x
6
- }
7
-
8
1
  export type TupleOf<T, N extends number> = N extends N
9
2
  ? number extends N
10
3
  ? T[]
@@ -1,44 +0,0 @@
1
- declare module '@gmod/binary-parser' {
2
- export interface Options {
3
- stripNull?: boolean
4
- formatter?: (item: any) => any
5
- length?: number | string | ((this: { $parent: unknown }) => void)
6
- }
7
-
8
- export class Parser<T = unknown> {
9
- public static start<TStart>(): Parser<TStart>
10
-
11
- public uint8(name?: string | null, options?: Options): Parser
12
-
13
- public itf8(name?: string | null, options?: Options): Parser
14
-
15
- public ltf8(name?: string | null, options?: Options): Parser
16
-
17
- public uint32(name?: string | null, options?: Options): Parser
18
-
19
- public int32(name?: string | null, options?: Options): Parser
20
-
21
- public buffer(name?: string | null, options?: Options): Parser
22
-
23
- public string(name?: string | null, options?: Options): Parser
24
-
25
- public namely(name: string): Parser
26
-
27
- public nest(
28
- name?: string | null,
29
- options?: { type: Parser | string } & Options,
30
- ): Parser
31
-
32
- public choice(
33
- name?: string | null,
34
- options?: { tag: string; choices: any } & Options,
35
- ): Parser
36
-
37
- public array(
38
- name?: string | null,
39
- options?: { type: string | Parser } & Options,
40
- ): Parser
41
-
42
- parse(bytes: Buffer): { result: T; offset: number }
43
- }
44
- }