@kaeawc/auto-mobile 0.0.91 → 0.0.93

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 (272) hide show
  1. package/dist/build-info.json +12 -12
  2. package/dist/schemas/README.md +16 -0
  3. package/dist/schemas/prototype-icon-names.json +302 -0
  4. package/dist/schemas/test-plan.schema.json +370 -52
  5. package/dist/src/chunk-00167wan.js +55 -0
  6. package/dist/src/chunk-0jrrsnc9.js +6 -0
  7. package/dist/src/chunk-0n6swkwg.js +5 -0
  8. package/dist/src/chunk-0qsy1qsx.js +57 -0
  9. package/dist/src/chunk-11m8wj8j.js +237 -0
  10. package/dist/src/chunk-1p7xf5kb.js +5 -0
  11. package/dist/src/chunk-23p5f095.js +4 -0
  12. package/dist/src/chunk-26k317v5.js +5 -0
  13. package/dist/src/chunk-284ptqa4.js +7 -0
  14. package/dist/src/chunk-28re4xrg.js +4 -0
  15. package/dist/src/chunk-2f9rkmhx.js +5 -0
  16. package/dist/src/chunk-2fxdh48t.js +4 -0
  17. package/dist/src/chunk-2tbdrbt6.js +4 -0
  18. package/dist/src/chunk-2tqzq5qh.js +971 -0
  19. package/dist/src/chunk-32gvv9b4.js +21 -0
  20. package/dist/src/chunk-3f3t1x97.js +8 -0
  21. package/dist/src/chunk-3fspkbc7.js +4 -0
  22. package/dist/src/chunk-3qwrzxh0.js +11 -0
  23. package/dist/src/chunk-3sy6ahhz.js +26 -0
  24. package/dist/src/chunk-3vg455e6.js +4 -0
  25. package/dist/src/chunk-3xkpk44w.js +5 -0
  26. package/dist/src/chunk-3y6eykz9.js +4 -0
  27. package/dist/src/chunk-49bsqdx3.js +4 -0
  28. package/dist/src/chunk-4hw3665t.js +42 -0
  29. package/dist/src/chunk-58wzr3mt.js +5 -0
  30. package/dist/src/chunk-5d2hft6c.js +5 -0
  31. package/dist/src/chunk-5s645vr4.js +4 -0
  32. package/dist/src/chunk-5snsn9cf.js +4 -0
  33. package/dist/src/chunk-5tm9mn47.js +54 -0
  34. package/dist/src/chunk-5zc77a5t.js +4 -0
  35. package/dist/src/chunk-64j0majr.js +19 -0
  36. package/dist/src/chunk-65y8v4td.js +17 -0
  37. package/dist/src/chunk-6awz7vhq.js +5 -0
  38. package/dist/src/chunk-6bznss4t.js +8 -0
  39. package/dist/src/chunk-6ep7f5ge.js +4 -0
  40. package/dist/src/chunk-6pg7bqck.js +4 -0
  41. package/dist/src/chunk-6wt9rgjf.js +5 -0
  42. package/dist/src/chunk-6xmss8er.js +8 -0
  43. package/dist/src/chunk-710rxz9y.js +5 -0
  44. package/dist/src/chunk-7cs2da62.js +5 -0
  45. package/dist/src/chunk-7g103b54.js +4 -0
  46. package/dist/src/chunk-7j5vj4pa.js +4 -0
  47. package/dist/src/chunk-7rz9898k.js +5 -0
  48. package/dist/src/chunk-7tw8x05v.js +4 -0
  49. package/dist/src/chunk-7zy586cb.js +4 -0
  50. package/dist/src/chunk-8037tzzj.js +5 -0
  51. package/dist/src/chunk-84nanf8s.js +5 -0
  52. package/dist/src/chunk-8g1922rp.js +10 -0
  53. package/dist/src/chunk-8gvwcv2p.js +4 -0
  54. package/dist/src/chunk-8ph29g99.js +4 -0
  55. package/dist/src/chunk-8thrmfat.js +4 -0
  56. package/dist/src/chunk-8zgzzs7k.js +78 -0
  57. package/dist/src/chunk-97b1zmaq.js +4 -0
  58. package/dist/src/chunk-9fth9ayh.js +4 -0
  59. package/dist/src/chunk-9j6anhjr.js +4 -0
  60. package/dist/src/chunk-aabchzxk.js +9 -0
  61. package/dist/src/chunk-ayp07wbb.js +4 -0
  62. package/dist/src/chunk-bfjwqk8q.js +4 -0
  63. package/dist/src/chunk-bfw6125s.js +5 -0
  64. package/dist/src/chunk-bnhscm2n.js +4 -0
  65. package/dist/src/chunk-bxmsax22.js +5 -0
  66. package/dist/src/chunk-c1vs4g1n.js +4 -0
  67. package/dist/src/chunk-ct3e7yng.js +4 -0
  68. package/dist/src/chunk-cyy71ggq.js +5 -0
  69. package/dist/src/chunk-ddzkz92z.js +4 -0
  70. package/dist/src/chunk-dgrbdpb7.js +9 -0
  71. package/dist/src/chunk-drdz8hee.js +5 -0
  72. package/dist/src/chunk-e98dqnc9.js +145 -0
  73. package/dist/src/chunk-eersndy7.js +5 -0
  74. package/dist/src/chunk-eggq53ks.js +4 -0
  75. package/dist/src/chunk-f2dya7cs.js +4 -0
  76. package/dist/src/chunk-fbakd6cw.js +4 -0
  77. package/dist/src/chunk-fgb98zjj.js +5 -0
  78. package/dist/src/chunk-fmpad823.js +5 -0
  79. package/dist/src/chunk-g04bwyj3.js +4 -0
  80. package/dist/src/chunk-g0xr8zw0.js +4 -0
  81. package/dist/src/chunk-g3rjs80x.js +4 -0
  82. package/dist/src/chunk-g78rtrfv.js +4 -0
  83. package/dist/src/chunk-g7tmjbkt.js +5 -0
  84. package/dist/src/chunk-gabgv3y5.js +4 -0
  85. package/dist/src/chunk-gmr45m8f.js +4 -0
  86. package/dist/src/chunk-gsyfebqj.js +4 -0
  87. package/dist/src/chunk-h5rpn9wr.js +247 -0
  88. package/dist/src/chunk-hb1x7v55.js +4 -0
  89. package/dist/src/chunk-hrfytkxh.js +168 -0
  90. package/dist/src/chunk-j4yjzbak.js +4 -0
  91. package/dist/src/chunk-jd6a5v6p.js +5 -0
  92. package/dist/src/chunk-jh6vhqzx.js +5 -0
  93. package/dist/src/chunk-kn5spq15.js +4 -0
  94. package/dist/src/chunk-m94qs0f0.js +4 -0
  95. package/dist/src/chunk-mjrps0ac.js +7 -0
  96. package/dist/src/chunk-n03dmn5q.js +5 -0
  97. package/dist/src/chunk-n72qhwd9.js +4 -0
  98. package/dist/src/chunk-ndt1ccxm.js +71 -0
  99. package/dist/src/chunk-nr6y0n4y.js +5 -0
  100. package/dist/src/chunk-pcsen2vs.js +4 -0
  101. package/dist/src/chunk-ppfr0b8h.js +4 -0
  102. package/dist/src/chunk-q10bdnat.js +4 -0
  103. package/dist/src/chunk-q9xmq595.js +4 -0
  104. package/dist/src/chunk-qcxzr2my.js +5 -0
  105. package/dist/src/chunk-qf6nynk6.js +7 -0
  106. package/dist/src/chunk-qyqypn28.js +5 -0
  107. package/dist/src/chunk-r2epb56s.js +4 -0
  108. package/dist/src/chunk-r5bxavdx.js +311 -0
  109. package/dist/src/chunk-r6z1eztj.js +18 -0
  110. package/dist/src/chunk-r7bpkgff.js +4 -0
  111. package/dist/src/chunk-r8jf3d92.js +4 -0
  112. package/dist/src/chunk-rbpdk7m0.js +5 -0
  113. package/dist/src/chunk-rc0dbypm.js +4 -0
  114. package/dist/src/chunk-rhcty4ms.js +4 -0
  115. package/dist/src/chunk-rpvckv3p.js +4 -0
  116. package/dist/src/chunk-rqc9ap3x.js +4 -0
  117. package/dist/src/chunk-rvvy1bte.js +7 -0
  118. package/dist/src/chunk-ry0mz41y.js +4 -0
  119. package/dist/src/chunk-s3jc6cwp.js +5 -0
  120. package/dist/src/chunk-sfv61xjb.js +6 -0
  121. package/dist/src/chunk-t6bfvfkg.js +4 -0
  122. package/dist/src/chunk-t6c8akcm.js +5 -0
  123. package/dist/src/chunk-t7w8rctc.js +4 -0
  124. package/dist/src/chunk-thbh3jew.js +5 -0
  125. package/dist/src/chunk-v2wd4n3e.js +5 -0
  126. package/dist/src/chunk-v6pya0dm.js +5 -0
  127. package/dist/src/chunk-vy3bwm1d.js +17 -0
  128. package/dist/src/chunk-w3vs79ex.js +27 -0
  129. package/dist/src/chunk-w4zga19f.js +4 -0
  130. package/dist/src/chunk-w5b2jwk3.js +14 -0
  131. package/dist/src/chunk-w7hkv422.js +5 -0
  132. package/dist/src/chunk-waqwcjyn.js +4 -0
  133. package/dist/src/chunk-wbh8spm5.js +20 -0
  134. package/dist/src/chunk-wyrkw6hw.js +5 -0
  135. package/dist/src/chunk-xa73x2cx.js +5 -0
  136. package/dist/src/chunk-xgan0qqp.js +4 -0
  137. package/dist/src/chunk-y2vs6jwg.js +4 -0
  138. package/dist/src/chunk-yattm52s.js +4 -0
  139. package/dist/src/chunk-yb97j25b.js +6 -0
  140. package/dist/src/chunk-ybbtagbt.js +5 -0
  141. package/dist/src/chunk-ycaj2sgf.js +9 -0
  142. package/dist/src/chunk-yf7ympyz.js +325 -0
  143. package/dist/src/chunk-yjawdzk8.js +4 -0
  144. package/dist/src/chunk-z637nqg8.js +11 -0
  145. package/dist/src/chunk-zgja5f3p.js +6 -0
  146. package/dist/src/chunk-zs1sghs9.js +4 -0
  147. package/dist/src/daemon/processEntry.js +4 -0
  148. package/dist/src/index.js +4 -2843
  149. package/dist/src/runtime/bunRuntimeGuard.js +4 -0
  150. package/dist/src/utils/workers/iosBundleExtractWorker.js +2 -3
  151. package/ios/CameraPosterInjection/Injection/CameraPosterInjection.m +466 -0
  152. package/package.json +7 -6
  153. package/schemas/README.md +16 -0
  154. package/schemas/prototype-icon-names.json +302 -0
  155. package/schemas/test-plan.schema.json +370 -52
  156. package/node_modules/@borewit/text-codec/README.md +0 -87
  157. package/node_modules/@jimp/diff/node_modules/pixelmatch/README.md +0 -110
  158. package/node_modules/@jimp/diff/node_modules/pixelmatch/node_modules/pngjs/README.md +0 -433
  159. package/node_modules/@jimp/file-ops/dist/browser/index.js +0 -8
  160. package/node_modules/@jimp/js-png/README.md +0 -35
  161. package/node_modules/@jimp/js-png/src/__image_snapshots__/index-node-test-ts-png-should-use-png-options-1-snap.png +0 -0
  162. package/node_modules/@jimp/js-png/src/output.png +0 -0
  163. package/node_modules/@jimp/js-png/vitest.config.browser.mjs +0 -3
  164. package/node_modules/@jimp/plugin-resize/README.md +0 -12
  165. package/node_modules/@jimp/plugin-resize/vitest.config.browser.mjs +0 -3
  166. package/node_modules/@tokenizer/inflate/README.md +0 -114
  167. package/node_modules/@tokenizer/token/README.md +0 -19
  168. package/node_modules/await-to-js/README.md +0 -82
  169. package/node_modules/debug/README.md +0 -481
  170. package/node_modules/exif-parser/README.md +0 -83
  171. package/node_modules/file-type/readme.md +0 -667
  172. package/node_modules/ieee754/README.md +0 -51
  173. package/node_modules/mime/README.md +0 -178
  174. package/node_modules/ms/readme.md +0 -59
  175. package/node_modules/parse-bmfont-xml/README.md +0 -74
  176. package/node_modules/parse-bmfont-xml/lib/browser.js +0 -85
  177. package/node_modules/parse-bmfont-xml/node_modules/xml2js/README.md +0 -507
  178. package/node_modules/pngjs/README.md +0 -287
  179. package/node_modules/sax/README.md +0 -228
  180. package/node_modules/strtok3/README.md +0 -795
  181. package/node_modules/tinycolor2/README.md +0 -492
  182. package/node_modules/tinycolor2/cjs/test.js +0 -2191
  183. package/node_modules/tinycolor2/cjs/test_template.js +0 -26
  184. package/node_modules/tinycolor2/deno_asserts@0.168.0.mjs +0 -807
  185. package/node_modules/tinycolor2/esm/test.js +0 -2189
  186. package/node_modules/tinycolor2/esm/test_template.js +0 -24
  187. package/node_modules/tinycolor2/tinycolor.js +0 -1191
  188. package/node_modules/token-types/README.md +0 -160
  189. package/node_modules/uint8array-extras/readme.md +0 -318
  190. package/node_modules/xml-parse-from-string/README.md +0 -35
  191. package/node_modules/xmlbuilder/README.md +0 -86
  192. package/node_modules/zod/README.md +0 -208
  193. package/node_modules/zod/v4/locales/ar.d.cts +0 -4
  194. package/node_modules/zod/v4/locales/ar.d.ts +0 -4
  195. package/node_modules/zod/v4/locales/az.d.cts +0 -4
  196. package/node_modules/zod/v4/locales/az.d.ts +0 -4
  197. package/node_modules/zod/v4/locales/be.d.cts +0 -4
  198. package/node_modules/zod/v4/locales/be.d.ts +0 -4
  199. package/node_modules/zod/v4/locales/ca.d.cts +0 -4
  200. package/node_modules/zod/v4/locales/ca.d.ts +0 -4
  201. package/node_modules/zod/v4/locales/cs.d.cts +0 -4
  202. package/node_modules/zod/v4/locales/cs.d.ts +0 -4
  203. package/node_modules/zod/v4/locales/de.d.cts +0 -4
  204. package/node_modules/zod/v4/locales/de.d.ts +0 -4
  205. package/node_modules/zod/v4/locales/en.d.cts +0 -5
  206. package/node_modules/zod/v4/locales/en.d.ts +0 -5
  207. package/node_modules/zod/v4/locales/eo.d.cts +0 -5
  208. package/node_modules/zod/v4/locales/eo.d.ts +0 -5
  209. package/node_modules/zod/v4/locales/es.d.cts +0 -4
  210. package/node_modules/zod/v4/locales/es.d.ts +0 -4
  211. package/node_modules/zod/v4/locales/fa.d.cts +0 -4
  212. package/node_modules/zod/v4/locales/fa.d.ts +0 -4
  213. package/node_modules/zod/v4/locales/fi.d.cts +0 -4
  214. package/node_modules/zod/v4/locales/fi.d.ts +0 -4
  215. package/node_modules/zod/v4/locales/fr-CA.d.cts +0 -4
  216. package/node_modules/zod/v4/locales/fr-CA.d.ts +0 -4
  217. package/node_modules/zod/v4/locales/fr.d.cts +0 -4
  218. package/node_modules/zod/v4/locales/fr.d.ts +0 -4
  219. package/node_modules/zod/v4/locales/he.d.cts +0 -4
  220. package/node_modules/zod/v4/locales/he.d.ts +0 -4
  221. package/node_modules/zod/v4/locales/hu.d.cts +0 -4
  222. package/node_modules/zod/v4/locales/hu.d.ts +0 -4
  223. package/node_modules/zod/v4/locales/id.d.cts +0 -4
  224. package/node_modules/zod/v4/locales/id.d.ts +0 -4
  225. package/node_modules/zod/v4/locales/index.d.cts +0 -39
  226. package/node_modules/zod/v4/locales/index.d.ts +0 -39
  227. package/node_modules/zod/v4/locales/it.d.cts +0 -4
  228. package/node_modules/zod/v4/locales/it.d.ts +0 -4
  229. package/node_modules/zod/v4/locales/ja.d.cts +0 -4
  230. package/node_modules/zod/v4/locales/ja.d.ts +0 -4
  231. package/node_modules/zod/v4/locales/kh.d.cts +0 -4
  232. package/node_modules/zod/v4/locales/kh.d.ts +0 -4
  233. package/node_modules/zod/v4/locales/ko.d.cts +0 -4
  234. package/node_modules/zod/v4/locales/ko.d.ts +0 -4
  235. package/node_modules/zod/v4/locales/mk.d.cts +0 -4
  236. package/node_modules/zod/v4/locales/mk.d.ts +0 -4
  237. package/node_modules/zod/v4/locales/ms.d.cts +0 -4
  238. package/node_modules/zod/v4/locales/ms.d.ts +0 -4
  239. package/node_modules/zod/v4/locales/nl.d.cts +0 -4
  240. package/node_modules/zod/v4/locales/nl.d.ts +0 -4
  241. package/node_modules/zod/v4/locales/no.d.cts +0 -4
  242. package/node_modules/zod/v4/locales/no.d.ts +0 -4
  243. package/node_modules/zod/v4/locales/ota.d.cts +0 -4
  244. package/node_modules/zod/v4/locales/ota.d.ts +0 -4
  245. package/node_modules/zod/v4/locales/pl.d.cts +0 -4
  246. package/node_modules/zod/v4/locales/pl.d.ts +0 -4
  247. package/node_modules/zod/v4/locales/ps.d.cts +0 -4
  248. package/node_modules/zod/v4/locales/ps.d.ts +0 -4
  249. package/node_modules/zod/v4/locales/pt.d.cts +0 -4
  250. package/node_modules/zod/v4/locales/pt.d.ts +0 -4
  251. package/node_modules/zod/v4/locales/ru.d.cts +0 -4
  252. package/node_modules/zod/v4/locales/ru.d.ts +0 -4
  253. package/node_modules/zod/v4/locales/sl.d.cts +0 -4
  254. package/node_modules/zod/v4/locales/sl.d.ts +0 -4
  255. package/node_modules/zod/v4/locales/sv.d.cts +0 -4
  256. package/node_modules/zod/v4/locales/sv.d.ts +0 -4
  257. package/node_modules/zod/v4/locales/ta.d.cts +0 -4
  258. package/node_modules/zod/v4/locales/ta.d.ts +0 -4
  259. package/node_modules/zod/v4/locales/th.d.cts +0 -4
  260. package/node_modules/zod/v4/locales/th.d.ts +0 -4
  261. package/node_modules/zod/v4/locales/tr.d.cts +0 -5
  262. package/node_modules/zod/v4/locales/tr.d.ts +0 -5
  263. package/node_modules/zod/v4/locales/ua.d.cts +0 -4
  264. package/node_modules/zod/v4/locales/ua.d.ts +0 -4
  265. package/node_modules/zod/v4/locales/ur.d.cts +0 -4
  266. package/node_modules/zod/v4/locales/ur.d.ts +0 -4
  267. package/node_modules/zod/v4/locales/vi.d.cts +0 -4
  268. package/node_modules/zod/v4/locales/vi.d.ts +0 -4
  269. package/node_modules/zod/v4/locales/zh-CN.d.cts +0 -4
  270. package/node_modules/zod/v4/locales/zh-CN.d.ts +0 -4
  271. package/node_modules/zod/v4/locales/zh-TW.d.cts +0 -4
  272. package/node_modules/zod/v4/locales/zh-TW.d.ts +0 -4
@@ -1,795 +0,0 @@
1
- [![Node.js CI](https://github.com/Borewit/strtok3/actions/workflows/ci.yml/badge.svg)](https://github.com/Borewit/strtok3/actions/workflows/ci.yml)
2
- [![CodeQL](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml)
3
- [![NPM version](https://badge.fury.io/js/strtok3.svg)](https://npmjs.org/package/strtok3)
4
- [![npm downloads](http://img.shields.io/npm/dm/strtok3.svg)](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
5
- [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/8526/branches/103329/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=8526&bid=103329)
6
- [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/strtok3/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/strtok3?targetFile=package.json)
7
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/strtok3?utm_source=github.com&utm_medium=referral&utm_content=Borewit/strtok3&utm_campaign=Badge_Grade)
8
- [![Codecov](https://codecov.io/gh/Borewit/strtok3/branch/master/graph/badge.svg)](https://codecov.io/gh/Borewit/strtok3)
9
- # strtok3
10
-
11
- A promise-based streaming [_tokenizer_](#tokenizer-object) for [Node.js](https://nodejs.org) and browsers.
12
-
13
- The `strtok3` module provides several methods for creating a [_tokenizer_](#tokenizer-object) from various input sources.
14
- Designed for:
15
- - Seamless support in streaming environments.
16
- - Efficiently decode binary data, strings, and numbers.
17
- - Reading [predefined](https://github.com/Borewit/token-types) or custom tokens.
18
- - Offering [_tokenizers_](#tokenizer-object) for reading from [files](#fromfile-function), [streams](#fromstream-function) or [Uint8Arrays](#frombuffer-function).
19
-
20
- ### Features
21
-
22
- `strtok3` can read from:
23
- - Files, using a file path as input.
24
- - Node.js [streams](https://nodejs.org/api/stream.html).
25
- - WHATWG [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) objects containing `Uint8Array` chunks.
26
- - [Buffer](https://nodejs.org/api/buffer.html) or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
27
- - [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [File](https://developer.mozilla.org/en-US/docs/Web/API/File) objects.
28
- - HTTP chunked transfer provided by [@tokenizer/http](https://github.com/Borewit/tokenizer-http).
29
- - [Amazon S3](https://aws.amazon.com/s3) chunks with [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3).
30
-
31
- ## Installation
32
-
33
- ```sh
34
- npm install strtok3
35
- ```
36
-
37
- ### Compatibility
38
-
39
- Starting with version 7, the module has migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
40
- The distributed JavaScript codebase is compliant with the [ECMAScript 2020 (11th Edition)](https://en.wikipedia.org/wiki/ECMAScript_version_history#11th_Edition_%E2%80%93_ECMAScript_2020) standard.
41
-
42
- Requires a modern browser, Node.js (V8) ≥ 18 engine or Bun (JavaScriptCore) ≥ 1.2.
43
- It can also be used in a browser environment when bundled with a module bundler.
44
-
45
- For TypeScript CommonJS backward compatibility, you can use [load-esm](https://github.com/Borewit/load-esm).
46
-
47
- Use Node.js 24 LTS to build the project and install development dependencies.
48
- This build requirement is separate from the Node.js ≥ 18 runtime requirement in `package.json`.
49
- CI builds once with Node.js 24, then runs the compiled JavaScript unit tests across the Node.js compatibility matrix and Bun 1.2.x, 1.3.x, and 1.4.x.
50
- Coverage is collected in a separate Node.js 24 job and uploaded to Codecov.
51
-
52
- For local development, running the TypeScript tests with `tsx` requires Node.js 18.19+ (18.x) or Node.js ≥ 20.6.0.
53
-
54
- ## Support the Project
55
-
56
- If you find this project useful and would like to support its development, consider sponsoring or contributing:
57
-
58
- - [Become a sponsor to Borewit](https://github.com/sponsors/Borewit)
59
-
60
- - Buy me a coffee:
61
-
62
- <a href="https://www.buymeacoffee.com/borewit" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy me A coffee" height="41" width="174"></a>
63
-
64
- ## API Documentation
65
-
66
- ### strtok3 methods
67
-
68
- Use one of the methods to instantiate an [_abstract tokenizer_](#tokenizer-object):
69
- - [fromBlob](#fromblob-function)
70
- - [fromBuffer](#frombuffer-function)
71
- - [fromFile](#fromfile-function)
72
- - [fromStream](#fromstream-function)
73
- - [fromWebStream](#fromwebstream-function)
74
- - [createTokenizerView](#createtokenizerview-function)
75
-
76
- > [!NOTE]
77
- > `fromFile` requires Node.js file-system APIs, and `fromStream` requires a Node.js readable stream.
78
- > In browsers, use `fromBlob`, `fromBuffer`, or `fromWebStream`.
79
-
80
- All methods return a [`Tokenizer`](#tokenizer-object), either directly or via a promise.
81
- The `strtok3/core` entry point exports all factories except `fromFile` and can be used
82
- without Node.js file-system APIs. In browsers, `strtok3` resolves to this core entry point.
83
-
84
- #### `fromBlob()` function
85
-
86
- Create a tokenizer from a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
87
-
88
- ```ts
89
- function fromBlob(blob: Blob, options?: ITokenizerOptions): BlobTokenizer;
90
- ```
91
-
92
- | Parameter | Optional | Type | Description |
93
- | --------- | -------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
94
- | blob | no | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [File](https://developer.mozilla.org/en-US/docs/Web/API/File) to read from |
95
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
96
-
97
- Returns a [_tokenizer_](#tokenizer-object).
98
-
99
- ```js
100
- import { fromBlob } from 'strtok3';
101
- import * as Token from 'token-types';
102
-
103
- async function parse() {
104
- const blob = new Blob([new Uint8Array([42])]);
105
-
106
- const tokenizer = fromBlob(blob);
107
-
108
- const myUint8Number = await tokenizer.readToken(Token.UINT8);
109
- console.log(`My number: ${myUint8Number}`);
110
- }
111
-
112
- parse();
113
- ```
114
-
115
- #### `fromBuffer()` function
116
-
117
- Create a tokenizer from memory ([Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or Node.js [Buffer](https://nodejs.org/api/buffer.html)).
118
-
119
- ```ts
120
- function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer;
121
- ```
122
-
123
- | Parameter | Optional | Type | Description |
124
- | ---------- | -------- | --------------------------------------------------------------------------------------------------------- | --------------------------------- |
125
- | uint8Array | no | [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | Buffer or Uint8Array to read from |
126
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
127
-
128
- Returns a [_tokenizer_](#tokenizer-object).
129
-
130
- ```js
131
- import { fromBuffer } from 'strtok3';
132
- import * as Token from 'token-types';
133
-
134
- const tokenizer = fromBuffer(new Uint8Array([42]));
135
-
136
- async function parse() {
137
- const myUint8Number = await tokenizer.readToken(Token.UINT8);
138
- console.log(`My number: ${myUint8Number}`);
139
- }
140
-
141
- parse();
142
- ```
143
-
144
- #### `fromFile` function
145
-
146
- Creates a [_tokenizer_](#tokenizer-object) from a local file.
147
-
148
- ```ts
149
- function fromFile(sourceFilePath: string, options?: IFromFileOptions): Promise<FileTokenizer>;
150
- ```
151
-
152
- | Parameter | Type | Description |
153
- | -------------- | ----------------------------------------------- | ------------------------------- |
154
- | sourceFilePath | `string` | Path to file to read from |
155
- | options | [IFromFileOptions](#ifromfileoptions-interface) | Optional file tokenizer options |
156
-
157
- > [!NOTE]
158
- > - Only available for Node.js engines
159
- > - `fromFile` automatically embeds [file information](#ifileinfo-interface)
160
-
161
- A Promise resolving to a [_tokenizer_](#tokenizer-object) which can be used to parse a file.
162
-
163
- ```js
164
- import { fromFile } from 'strtok3';
165
- import * as Token from 'token-types';
166
-
167
- async function parse() {
168
- const tokenizer = await fromFile('somefile.bin');
169
- try {
170
- const myNumber = await tokenizer.readToken(Token.UINT8);
171
- console.log(`My number: ${myNumber}`);
172
- } finally {
173
- await tokenizer.close(); // Close the file
174
- }
175
- }
176
-
177
- parse();
178
- ```
179
-
180
- #### `fromStream()` function
181
-
182
- Create a tokenizer from a Node.js [readable stream](https://nodejs.org/api/stream.html#readable-streams) containing binary data.
183
-
184
- ```ts
185
- function fromStream(stream: Readable, options?: ITokenizerOptions): Promise<ReadStreamTokenizer>;
186
- ```
187
-
188
- | Parameter | Optional | Type | Description |
189
- | --------- | -------- | ------------------------------------------------- | ------------------------------------ |
190
- | stream | no | Readable | Node.js readable stream to read from |
191
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
192
-
193
- When importing from `strtok3` in Node.js, returns a promise resolving to a [_tokenizer_](#tokenizer-object).
194
- For streams created by `createReadStream`, the file path and size are added to `tokenizer.fileInfo`.
195
- The `strtok3/core` entry point also exports `fromStream`, but returns the tokenizer synchronously without looking up file information.
196
-
197
- ```js
198
- import { createReadStream } from 'node:fs';
199
- import { fromStream } from 'strtok3';
200
- import * as Token from 'token-types';
201
-
202
- async function parse() {
203
- const stream = createReadStream('somefile.bin');
204
- try {
205
- const tokenizer = await fromStream(stream);
206
- try {
207
- const myNumber = await tokenizer.readToken(Token.UINT8);
208
- console.log(`My number: ${myNumber}`);
209
- } finally {
210
- await tokenizer.close();
211
- }
212
- } finally {
213
- stream.destroy();
214
- }
215
- }
216
-
217
- parse();
218
- ```
219
-
220
- #### `fromWebStream()` function
221
-
222
- Create a tokenizer from a [WHATWG ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) containing `Uint8Array` chunks.
223
-
224
- Uses a BYOB reader when supported by the stream, otherwise a default reader. Source cleanup differs between these readers; see [`close()`](#close-function) and [`abort()`](#abort-function).
225
-
226
- ```ts
227
- function fromWebStream(webStream: AnyWebByteStream, options?: ITokenizerOptions): ReadStreamTokenizer;
228
- ```
229
-
230
- | Parameter | Optional | Type | Description |
231
- | --------- | -------- | --------------------------------------------------------------------------------- | ---------------------------------- |
232
- | webStream | no | [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) | WHATWG ReadableStream to read from |
233
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
234
-
235
- Returns a [_tokenizer_](#tokenizer-object).
236
-
237
- ```js
238
- import { fromWebStream } from 'strtok3';
239
- import * as Token from 'token-types';
240
-
241
- async function parse() {
242
- const tokenizer = fromWebStream(readableStream);
243
- try {
244
- const myUint8Number = await tokenizer.readToken(Token.UINT8);
245
- console.log(`My number: ${myUint8Number}`);
246
- } finally {
247
- await tokenizer.close();
248
- }
249
- }
250
-
251
- parse();
252
- ```
253
-
254
- #### `createTokenizerView()` function
255
-
256
- Borrow a finite range of an existing tokenizer without buffering it or taking
257
- ownership of its input. Available from both `strtok3` and `strtok3/core`.
258
-
259
- ```ts
260
- function createTokenizerView(source: ITokenizer, length: number): ITokenizerView;
261
- ```
262
-
263
- The view starts at `source.position`, with local `position` zero and
264
- `fileInfo.size` equal to `length`. Creation does not read or skip bytes. The size
265
- is the declared range, so it can exceed the actual remaining input. The outer
266
- file's MIME type, path, and URL are not copied to the view.
267
-
268
- ```js
269
- import { createTokenizerView, fromBuffer } from 'strtok3';
270
- import { UINT8 } from 'token-types';
271
-
272
- const source = fromBuffer(new Uint8Array([10, 20, 30, 40, 50]));
273
- await source.ignore(1);
274
- const chunk = createTokenizerView(source, 3); // source bytes [20, 30, 40]
275
-
276
- console.log(await chunk.readToken(UINT8)); // 20; chunk.position = 1
277
- const child = chunk.createView(1); // same as createTokenizerView(chunk, 1)
278
- console.log(await child.readToken(UINT8)); // 30; chunk.position = 2
279
- await child.close(); // source stays open, at position 3
280
-
281
- console.log(chunk.remaining); // 1
282
- await chunk.consumeRemainder(); // exactly consume 40, or throw on truncation
283
- await chunk.close();
284
- console.log(await source.readToken(UINT8)); // 50
285
- await source.close();
286
- ```
287
-
288
- All read and peek positions, including explicit offsets and `setPosition()`, are
289
- relative to the view's start. Nested views must fit inside their parent's
290
- remaining range. A view exposes `setPosition()` and reports random access only
291
- when its source supports it; a stream with a known size remains forward-only.
292
- The overload for an `IRandomAccessTokenizer` returns an
293
- `IRandomAccessTokenizerView`, including for nested `createView()` calls.
294
-
295
- A request crossing the declared boundary rejects with `TokenizerBoundaryError`,
296
- a `RangeError` with `position`, `length`, and `size` properties. This applies to
297
- reads, peeks, tokens, and skips, even with `mayBeLess: true`. Invalid lengths,
298
- offsets, and unsafe offset arithmetic reject before allocating token buffers or
299
- consuming input. The source's token allocation and stream lookahead limits still
300
- apply through nested views.
301
-
302
- A request inside the view that encounters truncated underlying input rejects
303
- with `EndOfStreamError`. Buffer reads and peeks with `mayBeLess: true` may return
304
- fewer bytes within the requested range; token reads and peeks always require a
305
- complete token. A failed exact read may have consumed part of the input; the
306
- shared cursor reflects the bytes consumed. Peeks do not advance that cursor.
307
-
308
- `ignore()` preserves the source's skip behavior, which may return a shorter
309
- count or reject at EOF. Use `consumeRemainder()` when the entire declared
310
- remainder must exist: it returns the number consumed, or rejects with
311
- `EndOfStreamError`. On random-access sources it verifies the final byte and
312
- advances the cursor without reading the whole remainder. On streams it drains
313
- the remainder using the source's bounded skip buffers.
314
-
315
- The source, parent, child, and sibling views share one cursor. Use them
316
- sequentially, and close a child before resuming its parent. `close()` is
317
- idempotent, does not drain the remainder, and never closes or aborts the source.
318
- After a partially consumed child closes, the parent resumes at that same byte,
319
- not at the child's declared end. Call `child.consumeRemainder()` before closing
320
- when the parent should resume after the entire child range. Closed views reject
321
- further operations and keep their last local position; closing a parent view
322
- also prevents its children from being used.
323
-
324
- Overlapping operations through a view or its parent/child chain are rejected;
325
- `close()` also rejects while that view has an active operation. Direct operations
326
- on the original source, or separate views created from it, cannot be coordinated
327
- by a view, so callers must keep those sequential too. Explicit `abort()`
328
- propagates to the shared source to cancel pending input and affects its other
329
- users; it also closes the view.
330
-
331
- ### `TokenWriter` class
332
-
333
- Serialize binary data synchronously into a growable in-memory buffer with the
334
- same token definitions used for reading.
335
- Available from both `strtok3` and `strtok3/core`.
336
-
337
- ```ts
338
- const writer = new TokenWriter(); // optional initial capacity in bytes
339
- const cappedWriter = new TokenWriter(undefined, { maxBufferSize: 1024 * 1024 });
340
-
341
- writer.length; // bytes written so far
342
- writer.reserve(length); // reserve zero-filled region, returns start offset
343
- writer.writeToken(token, value); // encode a token, returns bytes written
344
- writer.writeBuffer(value); // copy raw bytes, returns bytes written
345
- writer.writeBytes(value); // alias for writeBuffer
346
- writer.writeZeros(length); // append zeros, returns bytes written
347
- writer.patchToken(token, offset, value); // overwrite an earlier region
348
- writer.toUint8Array(); // copy of the written bytes
349
- ```
350
-
351
- ```js
352
- import { TokenWriter } from 'strtok3';
353
- import { UINT24_BE, UINT32_LE } from 'token-types';
354
-
355
- const writer = new TokenWriter();
356
- writer.writeToken(UINT32_LE, 0x01020304);
357
- const blockLengthOffset = writer.reserve(3);
358
- const bytesWritten = writer.writeBuffer(new Uint8Array([0xaa, 0xbb])); // 2
359
- writer.patchToken(UINT24_BE, blockLengthOffset, 2);
360
-
361
- console.log(writer.length); // 9
362
- const data = writer.toUint8Array(); // Uint8Array(9)
363
- ```
364
-
365
- Append methods return the number of bytes written, like `readBuffer()` returns
366
- the number read; `writer.length` gives the resulting total. `writeToken()` writes
367
- exactly `token.len` bytes and ignores the encoder's returned offset.
368
- `reserve()` returns the starting offset of a zero-filled region for back-filling
369
- with `patchToken()`. Patching outside the written region throws a `RangeError`;
370
- successful patches leave `length` unchanged and return nothing.
371
-
372
- Errors from `put()` propagate without changing the written bytes or `length`:
373
- failed appends clear partial bytes before reuse, and failed patches restore the
374
- original region. Encoders must write synchronously only within `token.len` bytes
375
- starting at the supplied offset and must not retain the destination buffer.
376
-
377
- `writeBuffer()` and its `writeBytes()` alias copy their input. `toUint8Array()`
378
- returns a snapshot that can be modified without changing the writer. The writer
379
- buffers the complete output; snapshots allocate another copy of the written bytes.
380
-
381
- The optional `maxBufferSize` caps both total output length and backing-buffer
382
- capacity. Like the tokenizer option, it defaults to `Infinity` and must be a
383
- positive safe integer or `Infinity`. Requests exceeding the cap throw
384
- `BufferSizeError` before allocation, encoding or changes to the output.
385
- An explicit initial capacity above the cap is rejected. When omitted, the initial
386
- capacity defaults to 1024 bytes or the cap, whichever is smaller; internal minimum
387
- capacity and buffer growth also respect the cap. Empty appends and in-range patches
388
- remain allowed at the limit. The cap does not bound total process memory, caller
389
- inputs, snapshots, patch rollback copies or encoder allocations.
390
-
391
- ### `Tokenizer` object
392
-
393
- The _tokenizer_ is an abstraction of a [stream](https://nodejs.org/api/stream.html), file or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), allowing _reading_ or _peeking_ from the stream.
394
- It can also be translated in chunked reads, as done in [@tokenizer/http](https://github.com/Borewit/tokenizer-http);
395
-
396
- #### Key Features:
397
-
398
- - Supports seeking within the stream using `tokenizer.ignore()`.
399
- - Offers `peek` methods to preview data without advancing the read pointer.
400
- - Maintains the read position via `tokenizer.position`.
401
- - Supports random access for buffer, blob, and file tokenizers.
402
-
403
- #### Tokenizer functions
404
-
405
- _Read_ methods advance the stream pointer, while _peek_ methods do not.
406
-
407
- There are two kinds of functions:
408
- 1. _read_ methods: used to read a _token_ or bytes into a buffer from the [_tokenizer_](#tokenizer-object). After a successful read, `tokenizer.position` is the starting position of the read plus the number of bytes read. An explicit position can skip ahead or, for random-access tokenizers, move backwards.
409
- 2. _peek_ methods: same as the read, but it will _not_ advance the pointer. It allows to read (peek) ahead.
410
-
411
- Reads and peeks require the full requested length unless `mayBeLess: true` is passed to
412
- `readBuffer` or `peekBuffer`. Otherwise, insufficient input rejects with the exported
413
- `EndOfStreamError`. Token methods always require the full token.
414
-
415
- A failed exact stream read can consume partial input and advance `tokenizer.position`
416
- by the number of bytes consumed. A failed exact stream peek leaves `tokenizer.position`
417
- unchanged and retains the partial bytes for subsequent reads. Caller-provided buffers
418
- may contain partial data even when the operation rejects.
419
-
420
- #### `readBuffer` function
421
-
422
- Read data from the _tokenizer_ into provided "buffer" (`Uint8Array`).
423
- `readBuffer(buffer, options?)`
424
-
425
- ```ts
426
- readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
427
- ```
428
-
429
- | Parameter | Type | Description |
430
- | --------- | -------------------------------------------------------------- | ------------------------------------------------------------------------- |
431
- | buffer | [Buffer](https://nodejs.org/api/buffer.html) &#124; Uint8Array | Target buffer to write the data read to |
432
- | options | [IReadChunkOptions](#ireadchunkoptions-interface) | Optional settings for the length, position, and handling of partial reads |
433
-
434
- Return promise with number of bytes read.
435
- The number of bytes read may be less than requested if the `mayBeLess` flag is set.
436
-
437
- #### `peekBuffer` function
438
-
439
- Peek (read ahead), from [_tokenizer_](#tokenizer-object), into the buffer without advancing the stream pointer.
440
-
441
- ```ts
442
- peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
443
- ```
444
-
445
- | Parameter | Type | Description |
446
- | --------- | ------------------------------------------------- | ------------------------------------------------------------------------- |
447
- | buffer | Buffer &#124; Uint8Array | Target buffer to write the data read (peeked) to. |
448
- | options | [IReadChunkOptions](#ireadchunkoptions-interface) | Optional settings for the length, position, and handling of partial reads |
449
-
450
- Return value `Promise<number>` Promise with number of bytes read. The number of bytes read may be less if the `mayBeLess` flag was set.
451
-
452
- For streams with a known size, a nonempty peek starting at or beyond that size
453
- rejects with `EndOfStreamError`, or returns zero with `mayBeLess: true`, before
454
- allocating lookahead or reading input. This also applies through tokenizer views.
455
- Peeks starting inside the advertised input retain their partial-read behavior
456
- when they cross EOF. Zero-length peeks remain no-ops.
457
-
458
- #### `readToken` function
459
-
460
- Read a _token_ from the tokenizer-stream.
461
-
462
- ```ts
463
- readToken<Value>(token: IGetToken<Value>, position: number = this.position): Promise<Value>
464
- ```
465
-
466
- | Parameter | Type | Description |
467
- | --------- | -------------------------- | ----------------------------------------------------------------------------- |
468
- | token | [IGetToken](#token-object) | Token to read from the tokenizer-stream. |
469
- | position? | number | Offset where to begin reading. Defaults to `tokenizer.position` when omitted. |
470
-
471
- Returns a `Promise<Value>` resolving to the decoded token value. Rejects with `EndOfStreamError` if fewer than `token.len` bytes are available.
472
-
473
- #### `peekToken` function
474
-
475
- Peek a _token_ from the [_tokenizer_](#tokenizer-object).
476
-
477
- ```ts
478
- peekToken<Value>(token: IGetToken<Value>, position: number | null = this.position): Promise<Value>
479
- ```
480
-
481
- | Parameter | Type | Description |
482
- | --------- | -------------------------- | --------------------------------------------------------------------------------------- |
483
- | token | [IGetToken](#token-object) | Token to peek from the tokenizer-stream. |
484
- | position? | number &#124; null | Offset where to begin peeking. Defaults to `tokenizer.position` when omitted or `null`. |
485
-
486
- Return a promise with the token value peeked from the [_tokenizer_](#tokenizer-object).
487
-
488
- #### `readNumber` function
489
-
490
- Read a numeric [_token_](#token-object) from the [_tokenizer_](#tokenizer-object).
491
-
492
- ```ts
493
- readNumber(token: IToken<number>): Promise<number>
494
- ```
495
-
496
- | Parameter | Type | Description |
497
- | --------- | ------------------------------- | ------------------------------------------------ |
498
- | token | [IToken<number>](#token-object) | Numeric token to read from the tokenizer-stream. |
499
-
500
- A promise resolving to a numeric value read and decoded from the _tokenizer-stream_.
501
- Uses a reusable 8-byte buffer, so `token.len` must be at most 8 bytes.
502
- For larger tokens or values such as `bigint`, use `readToken` instead.
503
-
504
- #### `peekNumber` function
505
-
506
- Peek a numeric [_token_](#token-object) without advancing `tokenizer.position`.
507
-
508
- ```ts
509
- peekNumber(token: IToken<number>): Promise<number>
510
- ```
511
-
512
- Returns a promise resolving to the decoded numeric value.
513
- Like `readNumber`, rejects with `EndOfStreamError` if the token cannot be read in full.
514
- The same 8-byte token limit applies; use `peekToken` for larger tokens or values such as `bigint`.
515
-
516
- #### `ignore` function
517
-
518
- Advance the offset pointer by the given number of bytes.
519
-
520
- ```ts
521
- ignore(length: number): Promise<number>
522
- ```
523
-
524
- | Parameter | Type | Description |
525
- | --------- | ------ | ----------------------------------------------------------------------------------- |
526
- | length | number | Non-negative safe integer number of bytes to ignore. Advances `tokenizer.position`. |
527
-
528
- Returns a promise resolving to the number of bytes ignored.
529
- Buffer, blob, and file tokenizers stop at the known file size. Stream tokenizers reject with `EndOfStreamError` if the requested bytes are unavailable.
530
- When a stream has a known size, skips beyond that size reject before allocating
531
- a skip buffer or consuming input, including skips through tokenizer views.
532
- If the size is unknown, or the stream ends before its advertised size, a failed
533
- skip may consume available bytes before rejecting; `position` reflects those bytes.
534
-
535
- #### `close` function
536
-
537
- Clean up resources, such as closing a file pointer if applicable.
538
-
539
- ```ts
540
- close(): Promise<void>
541
- ```
542
-
543
- Await this method when finished with a tokenizer. For Node.js streams, it does not destroy the underlying stream; the caller remains responsible for its lifecycle.
544
-
545
- For buffer, blob, and file tokenizers, repeated or concurrent `close()` calls
546
- share one cleanup operation and invoke `onClose` at most once. If cleanup or the
547
- callback fails, subsequent calls reject with the same error. Calling `abort()`
548
- before `close()` does not suppress cleanup or the callback.
549
-
550
- Closing or aborting a Node.js stream tokenizer removes its reader-retaining
551
- stream listeners. After the source ends, shared error and close guards may remain
552
- until the source emits either event, including after tokenizer closure; these
553
- guards do not retain the tokenizer. The caller remains responsible for handling
554
- subsequent source errors.
555
-
556
- For Web streams, `close()` releases the reader lock. A BYOB reader leaves the source uncancelled, allowing another reader to continue reading it. A default reader cancels the source before releasing the lock, discarding remaining data. Bytes already read into tokenizer buffers, including peeked bytes, are not returned to the source.
557
-
558
- #### `abort` function
559
-
560
- Abort pending asynchronous stream operations.
561
-
562
- ```ts
563
- abort(): Promise<void>
564
- ```
565
-
566
- This is a no-op for buffer, blob, and file tokenizers.
567
-
568
- For Node.js streams, pending reads reject with the exported `AbortError`, and buffered
569
- peek data is discarded. The underlying stream is not destroyed. Calling `close()` or
570
- aborting the configured `AbortSignal` has the same effect on pending Node.js stream reads.
571
-
572
- For Web streams, `abort()` releases a BYOB reader's lock without cancelling the source. A default reader cancels the source but keeps its lock until `close()` is called. An `AbortSignal` invokes the same abort behavior.
573
-
574
- #### `supportsRandomAccess` function
575
-
576
- ```ts
577
- supportsRandomAccess(): boolean
578
- ```
579
-
580
- Returns `true` for buffer, blob, and file tokenizers, and `false` for stream tokenizers.
581
- When random access is supported, read and peek methods can use positions before `tokenizer.position`.
582
-
583
- #### `isRandomAccessTokenizer` helper
584
-
585
- Exported from both `strtok3` and `strtok3/core`:
586
-
587
- ```ts
588
- import { isRandomAccessTokenizer, type ITokenizer } from 'strtok3';
589
-
590
- function skipToEnd(tokenizer: ITokenizer): void {
591
- if (isRandomAccessTokenizer(tokenizer)) {
592
- tokenizer.setPosition(tokenizer.fileInfo.size);
593
- }
594
- }
595
- ```
596
-
597
- Narrows `ITokenizer` to `IRandomAccessTokenizer` by checking `supportsRandomAccess()`,
598
- a callable `setPosition`, and a numeric file size. A known size alone does not imply
599
- random access. Existing third-party implementations can keep returning a boolean
600
- from `supportsRandomAccess()` without changing their interface.
601
-
602
- #### `setPosition` function
603
-
604
- Available on buffer, blob, and file tokenizers (`IRandomAccessTokenizer`).
605
-
606
- ```ts
607
- setPosition(position: number): void
608
- ```
609
-
610
- Sets the current byte offset without reading data. The position must be a
611
- non-negative safe integer; invalid positions throw `RangeError` without changing
612
- the cursor. Seeking past EOF is allowed. At or past EOF, `ignore()` returns zero
613
- without moving the cursor backward, subject to safe end-position arithmetic.
614
-
615
- #### `Tokenizer` attributes
616
-
617
- - `fileInfo`
618
-
619
- Object containing optional file information, see [IFileInfo](#ifileinfo-interface).
620
-
621
- - `position`
622
-
623
- Pointer to the current position in the [_tokenizer_](#tokenizer-object) stream.
624
- For stream tokenizers, a _position_ provided to a _read_ or _peek_ method must be at least this value.
625
- Buffer, blob, and file tokenizers also support earlier positions.
626
-
627
- ### `ITokenizerOptions` interface
628
-
629
- Set these options once when creating a tokenizer. The configured limit applies to subsequent
630
- reads and peeks for that tokenizer; no per-read limit is needed. Each attribute is optional:
631
-
632
- | Attribute | Type | Description |
633
- | ------------- | --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
634
- | maxBufferSize | number | Maximum bytes in a dynamically sized tokenizer buffer or stream lookahead span. Disabled by default (`Infinity`). Must be a positive safe integer or `Infinity`. |
635
- | fileInfo | [IFileInfo](#ifileinfo-interface) | Additional metadata about the input |
636
- | onClose | `() => Promise<void>` | Asynchronous callback invoked when a buffer, blob, or file tokenizer is closed |
637
- | abortSignal | [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | Signal used to abort asynchronous stream operations |
638
-
639
- Creating a tokenizer with an already-aborted `abortSignal` throws or rejects with `AbortError`
640
- before acquiring file handles or stream readers. Signal listeners are removed when the signal
641
- fires or the tokenizer is closed, so closed tokenizers can be collected even when a signal is reused.
642
-
643
- When `maxBufferSize` is configured, `readToken()` and `peekToken()` reject oversized buffers with `BufferSizeError`
644
- before allocating or consuming input. The error exposes `requestedSize` and `maxBufferSize`.
645
- Token lengths and positions must be non-negative safe integers. When the input size is known,
646
- a token extending beyond the input rejects with `EndOfStreamError` before allocation.
647
-
648
- For streams, the lookahead limit includes bytes between the current position and the requested
649
- peek position. `mayBeLess: true` does not bypass this limit. With a finite cap, reads into
650
- caller-provided buffers, Blob reads and `ignore()` use bounded chunks where internal buffers
651
- are needed, so their total requested length may exceed `maxBufferSize`.
652
-
653
- This limit does not cap total process memory, caller-owned input/output buffers, or allocations
654
- inside a token's `get()` method. Stream sources may also supply chunks larger than this limit.
655
- The cap is opt-in to preserve existing buffer sizes. Applications parsing untrusted input should
656
- set a finite limit, for example 64 MiB. Omit the option or set it to `Infinity` to disable the cap.
657
-
658
- ```js
659
- import { BufferSizeError, fromFile } from 'strtok3';
660
-
661
- const tokenizer = await fromFile('somefile.bin', { maxBufferSize: 64 * 1024 * 1024 });
662
- try {
663
- // Read or peek tokens here.
664
- } catch (error) {
665
- if (error instanceof BufferSizeError) {
666
- console.error(`Requested ${error.requestedSize} bytes; limit is ${error.maxBufferSize}`);
667
- } else {
668
- throw error;
669
- }
670
- } finally {
671
- await tokenizer.close();
672
- }
673
- ```
674
-
675
- ### `IFromFileOptions` interface
676
-
677
- Extends [ITokenizerOptions](#itokenizeroptions-interface) for `fromFile()`.
678
-
679
- | Attribute | Type | Description |
680
- | --------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
681
- | regularFileOnly | `boolean` | When `true`, opens with `O_RDONLY \| O_NONBLOCK` and checks that the opened handle refers to a regular file. Defaults to `false`, preserving existing behavior. |
682
-
683
- Use this option when non-regular inputs, such as FIFOs, should be rejected without waiting for a writer. Validation uses the opened handle, so replacing the pathname before opening does not bypass the check. Symbolic links to regular files are accepted.
684
-
685
- If an opened handle is not a regular file, `fromFile()` closes it and rejects with the exported `NotRegularFileError`. Its `path` property identifies the requested path. Opening errors, stat errors, and abort errors continue to propagate; any handle acquired by the factory is closed if setup fails. After success, the caller must close the tokenizer.
686
-
687
- ```js
688
- import { fromFile, NotRegularFileError } from 'strtok3';
689
-
690
- try {
691
- const tokenizer = await fromFile('somefile.bin', { regularFileOnly: true });
692
- try {
693
- // Parse the regular file.
694
- } finally {
695
- await tokenizer.close();
696
- }
697
- } catch (error) {
698
- if (!(error instanceof NotRegularFileError)) {
699
- throw error;
700
- }
701
- // Handle an input that is not a regular file.
702
- }
703
- ```
704
-
705
- ### `IReadChunkOptions` interface
706
-
707
- Each attribute is optional:
708
-
709
- | Attribute | Type | Description |
710
- | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
711
- | length | number | Requested number of bytes to read or peek. Must be a non-negative safe integer no larger than the target buffer length. Defaults to the target buffer length. |
712
- | position | number | Byte offset to read or peek from. Must be a non-negative safe integer. Defaults to [tokenizer.position](#tokenizer-attributes) when omitted. Earlier positions require random access. |
713
- | mayBeLess | boolean | If `true`, allows fewer than the requested number of bytes to be read or peeked instead of throwing `EndOfStreamError`. Defaults to `false`. |
714
-
715
- Invalid lengths or positions, including a `position + length` that exceeds the safe
716
- integer range, reject with `RangeError`. Requesting an earlier position on a tokenizer
717
- without random access rejects with `Error`. Data is written starting at index 0 of the
718
- target buffer. To write at an offset, pass `buffer.subarray(offset)` as the target buffer.
719
-
720
- Example usage:
721
- ```js
722
- const bytesPeeked = await tokenizer.peekBuffer(buffer, { mayBeLess: true });
723
- ```
724
-
725
- ### `IFileInfo` interface
726
-
727
- Provides optional metadata about the file being tokenized.
728
-
729
- | Attribute | Type | Description |
730
- | --------- | ------ | ------------------------------------------------------------------------------------------------- |
731
- | size | number | File size in bytes |
732
- | mimeType | string | [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of file. |
733
- | path | string | File path |
734
- | url | string | File URL |
735
-
736
- ### `Token` object
737
-
738
- The _token_ is basically a description of what to read from the [_tokenizer-stream_](#tokenizer-object).
739
- A basic set of _token types_ can be found here: [_token-types_](https://github.com/Borewit/token-types).
740
-
741
- A token is something which implements the following interface:
742
- ```ts
743
- export interface IGetToken<T> {
744
- /**
745
- * Length in bytes of encoded value
746
- */
747
- len: number;
748
-
749
- /**
750
- * Decode value from buffer at offset
751
- * @param buf Buffer to read the decoded value from
752
- * @param off Decode offset
753
- */
754
- get(buf: Uint8Array, off: number): T;
755
- }
756
- ```
757
- The _tokenizer_ reads `token.len` bytes from the _tokenizer-stream_ into a Buffer.
758
- The `token.get` will be called with the Buffer. `token.get` is responsible for conversion from the buffer to the desired output type.
759
-
760
- ### Working with a fetch response
761
-
762
- Pass the response's [WHATWG readable stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) directly to `fromWebStream`.
763
-
764
- ```js
765
- import { fromWebStream } from 'strtok3';
766
- import * as Token from 'token-types';
767
-
768
- (async () => {
769
- const response = await fetch(url);
770
- if (!response.ok || !response.body) {
771
- throw new Error(`Cannot read response: ${response.status}`);
772
- }
773
-
774
- const tokenizer = fromWebStream(response.body);
775
- try {
776
- const myNumber = await tokenizer.readToken(Token.UINT8);
777
- console.log(`My number: ${myNumber}`);
778
- } finally {
779
- await tokenizer.close();
780
- }
781
- })();
782
- ```
783
-
784
- ## Dependencies
785
-
786
- Dependencies:
787
- - [@tokenizer/token](https://github.com/Borewit/tokenizer-token): Provides token definitions and utilities used by `strtok3` for interpreting binary data.
788
-
789
- ## Contributing
790
-
791
- See [the contribution guide](CONTRIBUTING.md) for code style and development commands.
792
-
793
- ## Licence
794
-
795
- This project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.