@yume-chan/adb 0.0.8 → 0.0.11

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 (407) hide show
  1. package/CHANGELOG.json +49 -0
  2. package/CHANGELOG.md +30 -0
  3. package/LICENSE +21 -21
  4. package/README.md +240 -257
  5. package/esm/adb.d.ts +48 -0
  6. package/esm/adb.d.ts.map +1 -0
  7. package/esm/adb.js +141 -145
  8. package/esm/adb.js.map +1 -1
  9. package/{dts → esm}/auth.d.ts +17 -7
  10. package/esm/auth.d.ts.map +1 -0
  11. package/esm/auth.js +69 -109
  12. package/esm/auth.js.map +1 -1
  13. package/esm/backend.d.ts +9 -0
  14. package/esm/backend.d.ts.map +1 -0
  15. package/{dts → esm}/commands/base.d.ts +1 -1
  16. package/esm/commands/base.d.ts.map +1 -0
  17. package/esm/commands/base.js +1 -0
  18. package/esm/commands/base.js.map +1 -1
  19. package/{dts → esm}/commands/framebuffer.d.ts +3 -3
  20. package/esm/commands/framebuffer.d.ts.map +1 -0
  21. package/esm/commands/framebuffer.js +15 -18
  22. package/esm/commands/framebuffer.js.map +1 -1
  23. package/esm/commands/index.d.ts +9 -0
  24. package/esm/commands/index.d.ts.map +1 -0
  25. package/esm/commands/index.js +8 -8
  26. package/esm/commands/index.js.map +1 -1
  27. package/esm/commands/install.d.ts +4 -0
  28. package/esm/commands/install.d.ts.map +1 -0
  29. package/esm/commands/install.js +21 -13
  30. package/esm/commands/install.js.map +1 -1
  31. package/esm/commands/power.d.ts +23 -0
  32. package/esm/commands/power.d.ts.map +1 -0
  33. package/esm/commands/power.js +45 -0
  34. package/esm/commands/power.js.map +1 -0
  35. package/{dts → esm}/commands/reverse.d.ts +3 -3
  36. package/esm/commands/reverse.d.ts.map +1 -0
  37. package/esm/commands/reverse.js +50 -60
  38. package/esm/commands/reverse.js.map +1 -1
  39. package/esm/commands/subprocess/index.d.ts +57 -0
  40. package/esm/commands/subprocess/index.d.ts.map +1 -0
  41. package/esm/commands/subprocess/index.js +83 -0
  42. package/esm/commands/subprocess/index.js.map +1 -0
  43. package/esm/commands/subprocess/legacy.d.ts +28 -0
  44. package/esm/commands/subprocess/legacy.d.ts.map +1 -0
  45. package/esm/commands/subprocess/legacy.js +44 -0
  46. package/esm/commands/subprocess/legacy.js.map +1 -0
  47. package/esm/commands/subprocess/protocol.d.ts +38 -0
  48. package/esm/commands/subprocess/protocol.d.ts.map +1 -0
  49. package/esm/commands/subprocess/protocol.js +155 -0
  50. package/esm/commands/subprocess/protocol.js.map +1 -0
  51. package/esm/commands/subprocess/types.d.ts +47 -0
  52. package/esm/commands/subprocess/types.d.ts.map +1 -0
  53. package/esm/commands/{shell → subprocess}/types.js +0 -0
  54. package/{cjs/commands/shell → esm/commands/subprocess}/types.js.map +1 -1
  55. package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
  56. package/esm/commands/subprocess/utils.d.ts.map +1 -0
  57. package/esm/commands/{shell → subprocess}/utils.js +0 -0
  58. package/esm/commands/subprocess/utils.js.map +1 -0
  59. package/esm/commands/sync/index.d.ts +8 -0
  60. package/esm/commands/sync/index.d.ts.map +1 -0
  61. package/esm/commands/sync/index.js +7 -7
  62. package/esm/commands/sync/index.js.map +1 -1
  63. package/{dts → esm}/commands/sync/list.d.ts +4 -4
  64. package/esm/commands/sync/list.d.ts.map +1 -0
  65. package/esm/commands/sync/list.js +16 -19
  66. package/esm/commands/sync/list.js.map +1 -1
  67. package/esm/commands/sync/pull.d.ts +11 -0
  68. package/esm/commands/sync/pull.d.ts.map +1 -0
  69. package/esm/commands/sync/pull.js +17 -11
  70. package/esm/commands/sync/pull.js.map +1 -1
  71. package/esm/commands/sync/push.d.ts +8 -0
  72. package/esm/commands/sync/push.d.ts.map +1 -0
  73. package/esm/commands/sync/push.js +19 -37
  74. package/esm/commands/sync/push.js.map +1 -1
  75. package/{dts → esm}/commands/sync/request.d.ts +3 -3
  76. package/esm/commands/sync/request.d.ts.map +1 -0
  77. package/esm/commands/sync/request.js +24 -26
  78. package/esm/commands/sync/request.js.map +1 -1
  79. package/{dts → esm}/commands/sync/response.d.ts +3 -3
  80. package/esm/commands/sync/response.d.ts.map +1 -0
  81. package/esm/commands/sync/response.js +16 -19
  82. package/esm/commands/sync/response.js.map +1 -1
  83. package/{dts → esm}/commands/sync/stat.d.ts +4 -4
  84. package/esm/commands/sync/stat.d.ts.map +1 -0
  85. package/esm/commands/sync/stat.js +22 -27
  86. package/esm/commands/sync/stat.js.map +1 -1
  87. package/esm/commands/sync/sync.d.ts +83 -0
  88. package/esm/commands/sync/sync.d.ts.map +1 -0
  89. package/esm/commands/sync/sync.js +92 -89
  90. package/esm/commands/sync/sync.js.map +1 -1
  91. package/{dts → esm}/commands/tcpip.d.ts +1 -1
  92. package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
  93. package/esm/commands/tcpip.js +14 -19
  94. package/esm/commands/tcpip.js.map +1 -1
  95. package/esm/crypto.d.ts +24 -0
  96. package/esm/crypto.d.ts.map +1 -0
  97. package/esm/crypto.js +33 -31
  98. package/esm/crypto.js.map +1 -1
  99. package/{dts → esm}/features.d.ts +0 -0
  100. package/{dts → esm}/features.d.ts.map +0 -0
  101. package/esm/features.js +1 -1
  102. package/esm/features.js.map +1 -1
  103. package/esm/index.d.ts +11 -0
  104. package/esm/index.d.ts.map +1 -0
  105. package/esm/index.js +10 -10
  106. package/esm/index.js.map +1 -1
  107. package/esm/packet.d.ts +28 -0
  108. package/esm/packet.d.ts.map +1 -0
  109. package/esm/packet.js +26 -53
  110. package/esm/packet.js.map +1 -1
  111. package/esm/socket/controller.d.ts +37 -0
  112. package/esm/socket/controller.d.ts.map +1 -0
  113. package/esm/socket/controller.js +52 -66
  114. package/esm/socket/controller.js.map +1 -1
  115. package/{dts → esm}/socket/dispatcher.d.ts +10 -23
  116. package/esm/socket/dispatcher.d.ts.map +1 -0
  117. package/esm/socket/dispatcher.js +148 -164
  118. package/esm/socket/dispatcher.js.map +1 -1
  119. package/esm/socket/index.d.ts +3 -0
  120. package/esm/socket/index.d.ts.map +1 -0
  121. package/esm/socket/index.js +2 -6
  122. package/esm/socket/index.js.map +1 -1
  123. package/esm/socket/socket.d.ts +34 -0
  124. package/esm/socket/socket.d.ts.map +1 -0
  125. package/esm/socket/socket.js +69 -14
  126. package/esm/socket/socket.js.map +1 -1
  127. package/esm/stream/buffered.d.ts +35 -0
  128. package/esm/stream/buffered.d.ts.map +1 -0
  129. package/esm/stream/buffered.js +123 -0
  130. package/esm/stream/buffered.js.map +1 -0
  131. package/esm/stream/detect.bak.d.ts +240 -0
  132. package/esm/stream/detect.bak.d.ts.map +1 -0
  133. package/esm/stream/detect.bak.js +60 -0
  134. package/esm/stream/detect.bak.js.map +1 -0
  135. package/esm/stream/detect.d.ts +18 -0
  136. package/esm/stream/detect.d.ts.map +1 -0
  137. package/esm/stream/detect.js +6 -0
  138. package/esm/stream/detect.js.map +1 -0
  139. package/esm/stream/detect.native.d.ts +240 -0
  140. package/esm/stream/detect.native.d.ts.map +1 -0
  141. package/esm/stream/detect.native.js +60 -0
  142. package/esm/stream/detect.native.js.map +1 -0
  143. package/esm/stream/detect.polyfill.d.ts +18 -0
  144. package/esm/stream/detect.polyfill.d.ts.map +1 -0
  145. package/esm/stream/detect.polyfill.js +6 -0
  146. package/esm/stream/detect.polyfill.js.map +1 -0
  147. package/esm/stream/index.d.ts +4 -0
  148. package/esm/stream/index.d.ts.map +1 -0
  149. package/esm/stream/index.js +3 -2
  150. package/esm/stream/index.js.map +1 -1
  151. package/esm/stream/transform.d.ts +98 -0
  152. package/esm/stream/transform.d.ts.map +1 -0
  153. package/esm/stream/transform.js +352 -0
  154. package/esm/stream/transform.js.map +1 -0
  155. package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
  156. package/esm/utils/auto-reset-event.d.ts.map +1 -0
  157. package/esm/utils/auto-reset-event.js +2 -1
  158. package/esm/utils/auto-reset-event.js.map +1 -1
  159. package/esm/utils/base64.d.ts +5 -0
  160. package/esm/utils/base64.d.ts.map +1 -0
  161. package/esm/utils/base64.js +116 -80
  162. package/esm/utils/base64.js.map +1 -1
  163. package/esm/utils/encoding.d.ts +3 -0
  164. package/esm/utils/encoding.d.ts.map +1 -0
  165. package/esm/utils/encoding.js +11 -0
  166. package/esm/utils/encoding.js.map +1 -0
  167. package/esm/utils/index.d.ts +4 -0
  168. package/esm/utils/index.d.ts.map +1 -0
  169. package/esm/utils/index.js +3 -4
  170. package/esm/utils/index.js.map +1 -1
  171. package/package.json +49 -50
  172. package/src/adb.ts +247 -242
  173. package/src/auth.ts +170 -156
  174. package/src/backend.ts +11 -24
  175. package/src/commands/base.ts +11 -11
  176. package/src/commands/framebuffer.ts +73 -73
  177. package/src/commands/index.ts +8 -8
  178. package/src/commands/install.ts +32 -21
  179. package/src/commands/power.ts +54 -0
  180. package/src/commands/reverse.ts +136 -133
  181. package/src/commands/subprocess/index.ts +124 -0
  182. package/src/commands/subprocess/legacy.ts +58 -0
  183. package/src/commands/subprocess/protocol.ts +185 -0
  184. package/src/commands/subprocess/types.ts +55 -0
  185. package/src/commands/{shell → subprocess}/utils.ts +20 -20
  186. package/src/commands/sync/index.ts +7 -7
  187. package/src/commands/sync/list.ts +40 -39
  188. package/src/commands/sync/pull.ts +43 -34
  189. package/src/commands/sync/push.ts +41 -46
  190. package/src/commands/sync/request.ts +49 -48
  191. package/src/commands/sync/response.ts +58 -57
  192. package/src/commands/sync/stat.ts +123 -121
  193. package/src/commands/sync/sync.ts +145 -113
  194. package/src/commands/tcpip.ts +21 -21
  195. package/src/crypto.ts +280 -280
  196. package/src/features.ts +5 -5
  197. package/src/index.ts +11 -10
  198. package/src/packet.ts +69 -89
  199. package/src/socket/dispatcher.ts +256 -269
  200. package/src/socket/index.ts +2 -6
  201. package/src/socket/socket.ts +129 -28
  202. package/src/stream/buffered.ts +147 -0
  203. package/src/stream/detect.native.ts +362 -0
  204. package/src/stream/detect.polyfill.ts +25 -0
  205. package/src/stream/detect.ts +25 -0
  206. package/src/stream/index.ts +3 -2
  207. package/src/stream/transform.ts +427 -0
  208. package/src/utils/auto-reset-event.ts +41 -41
  209. package/src/utils/base64.ts +306 -274
  210. package/src/utils/encoding.ts +13 -0
  211. package/src/utils/index.ts +3 -4
  212. package/tsconfig.build.json +3 -0
  213. package/tsconfig.build.tsbuildinfo +1 -0
  214. package/tsconfig.test.json +10 -0
  215. package/cjs/adb.js +0 -205
  216. package/cjs/adb.js.map +0 -1
  217. package/cjs/auth.js +0 -141
  218. package/cjs/auth.js.map +0 -1
  219. package/cjs/backend.js +0 -3
  220. package/cjs/backend.js.map +0 -1
  221. package/cjs/commands/base.js +0 -12
  222. package/cjs/commands/base.js.map +0 -1
  223. package/cjs/commands/demo-mode.js +0 -174
  224. package/cjs/commands/demo-mode.js.map +0 -1
  225. package/cjs/commands/framebuffer.js +0 -66
  226. package/cjs/commands/framebuffer.js.map +0 -1
  227. package/cjs/commands/index.js +0 -12
  228. package/cjs/commands/index.js.map +0 -1
  229. package/cjs/commands/install.js +0 -20
  230. package/cjs/commands/install.js.map +0 -1
  231. package/cjs/commands/reverse.js +0 -105
  232. package/cjs/commands/reverse.js.map +0 -1
  233. package/cjs/commands/shell/index.js +0 -56
  234. package/cjs/commands/shell/index.js.map +0 -1
  235. package/cjs/commands/shell/legacy.js +0 -37
  236. package/cjs/commands/shell/legacy.js.map +0 -1
  237. package/cjs/commands/shell/protocol.js +0 -83
  238. package/cjs/commands/shell/protocol.js.map +0 -1
  239. package/cjs/commands/shell/types.js +0 -3
  240. package/cjs/commands/shell/utils.js +0 -23
  241. package/cjs/commands/shell/utils.js.map +0 -1
  242. package/cjs/commands/sync/index.js +0 -11
  243. package/cjs/commands/sync/index.js.map +0 -1
  244. package/cjs/commands/sync/list.js +0 -36
  245. package/cjs/commands/sync/list.js.map +0 -1
  246. package/cjs/commands/sync/pull.js +0 -34
  247. package/cjs/commands/sync/pull.js.map +0 -1
  248. package/cjs/commands/sync/push.js +0 -49
  249. package/cjs/commands/sync/push.js.map +0 -1
  250. package/cjs/commands/sync/request.js +0 -48
  251. package/cjs/commands/sync/request.js.map +0 -1
  252. package/cjs/commands/sync/response.js +0 -53
  253. package/cjs/commands/sync/response.js.map +0 -1
  254. package/cjs/commands/sync/stat.js +0 -109
  255. package/cjs/commands/sync/stat.js.map +0 -1
  256. package/cjs/commands/sync/sync.js +0 -118
  257. package/cjs/commands/sync/sync.js.map +0 -1
  258. package/cjs/commands/tcpip.js +0 -28
  259. package/cjs/commands/tcpip.js.map +0 -1
  260. package/cjs/crypto.js +0 -231
  261. package/cjs/crypto.js.map +0 -1
  262. package/cjs/features.js +0 -10
  263. package/cjs/features.js.map +0 -1
  264. package/cjs/index.js +0 -14
  265. package/cjs/index.js.map +0 -1
  266. package/cjs/packet.js +0 -77
  267. package/cjs/packet.js.map +0 -1
  268. package/cjs/socket/close-event-emitter.js +0 -32
  269. package/cjs/socket/close-event-emitter.js.map +0 -1
  270. package/cjs/socket/controller.js +0 -84
  271. package/cjs/socket/controller.js.map +0 -1
  272. package/cjs/socket/data-event-emitter.js +0 -29
  273. package/cjs/socket/data-event-emitter.js.map +0 -1
  274. package/cjs/socket/dispatcher.js +0 -219
  275. package/cjs/socket/dispatcher.js.map +0 -1
  276. package/cjs/socket/index.js +0 -10
  277. package/cjs/socket/index.js.map +0 -1
  278. package/cjs/socket/logger.js +0 -3
  279. package/cjs/socket/logger.js.map +0 -1
  280. package/cjs/socket/socket.js +0 -24
  281. package/cjs/socket/socket.js.map +0 -1
  282. package/cjs/stream/buffered-stream.js +0 -78
  283. package/cjs/stream/buffered-stream.js.map +0 -1
  284. package/cjs/stream/index.js +0 -6
  285. package/cjs/stream/index.js.map +0 -1
  286. package/cjs/stream/stream.js +0 -45
  287. package/cjs/stream/stream.js.map +0 -1
  288. package/cjs/utils/auto-reset-event.js +0 -37
  289. package/cjs/utils/auto-reset-event.js.map +0 -1
  290. package/cjs/utils/base64.js +0 -210
  291. package/cjs/utils/base64.js.map +0 -1
  292. package/cjs/utils/chunk.js +0 -75
  293. package/cjs/utils/chunk.js.map +0 -1
  294. package/cjs/utils/event-queue.js +0 -108
  295. package/cjs/utils/event-queue.js.map +0 -1
  296. package/cjs/utils/index.js +0 -8
  297. package/cjs/utils/index.js.map +0 -1
  298. package/dts/adb.d.ts +0 -46
  299. package/dts/adb.d.ts.map +0 -1
  300. package/dts/auth.d.ts.map +0 -1
  301. package/dts/backend.d.ts +0 -15
  302. package/dts/backend.d.ts.map +0 -1
  303. package/dts/commands/base.d.ts.map +0 -1
  304. package/dts/commands/demo-mode.d.ts +0 -41
  305. package/dts/commands/demo-mode.d.ts.map +0 -1
  306. package/dts/commands/framebuffer.d.ts.map +0 -1
  307. package/dts/commands/index.d.ts +0 -9
  308. package/dts/commands/index.d.ts.map +0 -1
  309. package/dts/commands/install.d.ts +0 -3
  310. package/dts/commands/install.d.ts.map +0 -1
  311. package/dts/commands/reverse.d.ts.map +0 -1
  312. package/dts/commands/shell/index.d.ts +0 -20
  313. package/dts/commands/shell/index.d.ts.map +0 -1
  314. package/dts/commands/shell/legacy.d.ts +0 -27
  315. package/dts/commands/shell/legacy.d.ts.map +0 -1
  316. package/dts/commands/shell/protocol.d.ts +0 -37
  317. package/dts/commands/shell/protocol.d.ts.map +0 -1
  318. package/dts/commands/shell/types.d.ts +0 -15
  319. package/dts/commands/shell/types.d.ts.map +0 -1
  320. package/dts/commands/shell/utils.d.ts.map +0 -1
  321. package/dts/commands/sync/index.d.ts +0 -8
  322. package/dts/commands/sync/index.d.ts.map +0 -1
  323. package/dts/commands/sync/list.d.ts.map +0 -1
  324. package/dts/commands/sync/pull.d.ts +0 -11
  325. package/dts/commands/sync/pull.d.ts.map +0 -1
  326. package/dts/commands/sync/push.d.ts +0 -8
  327. package/dts/commands/sync/push.d.ts.map +0 -1
  328. package/dts/commands/sync/request.d.ts.map +0 -1
  329. package/dts/commands/sync/response.d.ts.map +0 -1
  330. package/dts/commands/sync/stat.d.ts.map +0 -1
  331. package/dts/commands/sync/sync.d.ts +0 -68
  332. package/dts/commands/sync/sync.d.ts.map +0 -1
  333. package/dts/crypto.d.ts +0 -17
  334. package/dts/crypto.d.ts.map +0 -1
  335. package/dts/index.d.ts +0 -11
  336. package/dts/index.d.ts.map +0 -1
  337. package/dts/packet.d.ts +0 -27
  338. package/dts/packet.d.ts.map +0 -1
  339. package/dts/socket/close-event-emitter.d.ts +0 -8
  340. package/dts/socket/close-event-emitter.d.ts.map +0 -1
  341. package/dts/socket/controller.d.ts +0 -43
  342. package/dts/socket/controller.d.ts.map +0 -1
  343. package/dts/socket/data-event-emitter.d.ts +0 -10
  344. package/dts/socket/data-event-emitter.d.ts.map +0 -1
  345. package/dts/socket/dispatcher.d.ts.map +0 -1
  346. package/dts/socket/index.d.ts +0 -7
  347. package/dts/socket/index.d.ts.map +0 -1
  348. package/dts/socket/logger.d.ts +0 -9
  349. package/dts/socket/logger.d.ts.map +0 -1
  350. package/dts/socket/socket.d.ts +0 -22
  351. package/dts/socket/socket.d.ts.map +0 -1
  352. package/dts/stream/buffered-stream.d.ts +0 -30
  353. package/dts/stream/buffered-stream.d.ts.map +0 -1
  354. package/dts/stream/index.d.ts +0 -3
  355. package/dts/stream/index.d.ts.map +0 -1
  356. package/dts/stream/stream.d.ts +0 -15
  357. package/dts/stream/stream.d.ts.map +0 -1
  358. package/dts/utils/auto-reset-event.d.ts.map +0 -1
  359. package/dts/utils/base64.d.ts +0 -7
  360. package/dts/utils/base64.d.ts.map +0 -1
  361. package/dts/utils/chunk.d.ts +0 -3
  362. package/dts/utils/chunk.d.ts.map +0 -1
  363. package/dts/utils/event-queue.d.ts +0 -35
  364. package/dts/utils/event-queue.d.ts.map +0 -1
  365. package/dts/utils/index.d.ts +0 -5
  366. package/dts/utils/index.d.ts.map +0 -1
  367. package/esm/commands/demo-mode.js +0 -170
  368. package/esm/commands/demo-mode.js.map +0 -1
  369. package/esm/commands/shell/index.js +0 -52
  370. package/esm/commands/shell/index.js.map +0 -1
  371. package/esm/commands/shell/legacy.js +0 -33
  372. package/esm/commands/shell/legacy.js.map +0 -1
  373. package/esm/commands/shell/protocol.js +0 -79
  374. package/esm/commands/shell/protocol.js.map +0 -1
  375. package/esm/commands/shell/types.js.map +0 -1
  376. package/esm/commands/shell/utils.js.map +0 -1
  377. package/esm/socket/close-event-emitter.js +0 -28
  378. package/esm/socket/close-event-emitter.js.map +0 -1
  379. package/esm/socket/data-event-emitter.js +0 -25
  380. package/esm/socket/data-event-emitter.js.map +0 -1
  381. package/esm/socket/logger.js +0 -2
  382. package/esm/socket/logger.js.map +0 -1
  383. package/esm/stream/buffered-stream.js +0 -73
  384. package/esm/stream/buffered-stream.js.map +0 -1
  385. package/esm/stream/stream.js +0 -41
  386. package/esm/stream/stream.js.map +0 -1
  387. package/esm/utils/chunk.js +0 -70
  388. package/esm/utils/chunk.js.map +0 -1
  389. package/esm/utils/event-queue.js +0 -104
  390. package/esm/utils/event-queue.js.map +0 -1
  391. package/src/commands/demo-mode.ts +0 -160
  392. package/src/commands/shell/index.ts +0 -68
  393. package/src/commands/shell/legacy.ts +0 -42
  394. package/src/commands/shell/protocol.ts +0 -94
  395. package/src/commands/shell/types.ts +0 -21
  396. package/src/socket/close-event-emitter.ts +0 -28
  397. package/src/socket/controller.ts +0 -105
  398. package/src/socket/data-event-emitter.ts +0 -27
  399. package/src/socket/logger.ts +0 -12
  400. package/src/stream/buffered-stream.ts +0 -100
  401. package/src/stream/stream.ts +0 -50
  402. package/src/utils/chunk.ts +0 -70
  403. package/src/utils/event-queue.ts +0 -145
  404. package/tsconfig.cjs.json +0 -11
  405. package/tsconfig.esm.json +0 -28
  406. package/tsconfig.esm.tsbuildinfo +0 -1305
  407. package/tsconfig.json +0 -18
@@ -1,274 +1,306 @@
1
- // Prepare maps for O(1) searching
2
- const charToIndex: Record<string, number> = {};
3
- const indexToChar: number[] = [];
4
- const paddingChar = '='.charCodeAt(0);
5
-
6
- function addRange(start: string, end: string) {
7
- const charCodeStart = start.charCodeAt(0);
8
- const charCodeEnd = end.charCodeAt(0);
9
- const length = charCodeEnd - charCodeStart + 1;
10
-
11
- for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
12
- charToIndex[String.fromCharCode(charCode)] = indexToChar.length;
13
- indexToChar.push(charCode);
14
- }
15
- }
16
-
17
- addRange('A', 'Z');
18
- addRange('a', 'z');
19
- addRange('0', '9');
20
- addRange('+', '+');
21
- addRange('/', '/');
22
-
23
- export function calculateBase64EncodedLength(inputLength: number): [outputLength: number, paddingLength: number] {
24
- const remainder = inputLength % 3;
25
- const paddingLength = remainder !== 0 ? 3 - remainder : 0;
26
- return [(inputLength + paddingLength) / 3 * 4, paddingLength];
27
- }
28
-
29
- export function encodeBase64(
30
- input: ArrayBuffer | Uint8Array,
31
- inputOffset?: number,
32
- inputLength?: number,
33
- ): ArrayBuffer; // overload 1
34
- export function encodeBase64(
35
- input: ArrayBuffer | Uint8Array,
36
- output: ArrayBuffer | Uint8Array,
37
- outputOffset?: number
38
- ): number; // overload 2
39
- export function encodeBase64(
40
- input: ArrayBuffer | Uint8Array,
41
- inputOffset: number,
42
- output: ArrayBuffer | Uint8Array,
43
- outputOffset?: number
44
- ): number; // overload 3
45
- export function encodeBase64(
46
- input: ArrayBuffer | Uint8Array,
47
- inputOffset: number,
48
- inputLength: number,
49
- output: ArrayBuffer | Uint8Array,
50
- outputOffset?: number
51
- ): number; // overload 4
52
- export function encodeBase64(
53
- input: ArrayBuffer | Uint8Array,
54
- arg1?: number | ArrayBuffer | Uint8Array,
55
- arg2?: number | ArrayBuffer | Uint8Array,
56
- _arg3?: number | ArrayBuffer | Uint8Array,
57
- _arg4?: number,
58
- ): ArrayBuffer | number {
59
- if (input instanceof ArrayBuffer) {
60
- input = new Uint8Array(input);
61
- }
62
-
63
- // Because `Uint8Array` is type compatible with `ArrayBuffer`,
64
- // TypeScript doesn't correctly narrow `input` to `Uint8Array` when assigning.
65
- // Manually eliminate `ArrayBuffer` from `input` with a type guard.
66
- if (input instanceof ArrayBuffer) {
67
- return input;
68
- }
69
-
70
- let inputOffset: number;
71
- let inputLength: number;
72
- let output: Uint8Array;
73
- let outputOffset: number;
74
-
75
- let outputArgumentIndex: number;
76
- if (typeof arg1 === 'number') {
77
- // overload 1, 3, 4
78
- inputOffset = arg1;
79
-
80
- if (typeof arg2 === 'number') {
81
- // overload 1, 4
82
- inputLength = arg2;
83
- outputArgumentIndex = 3;
84
- } else {
85
- // overload 3
86
- inputLength = input.byteLength - inputOffset;
87
- outputArgumentIndex = 2;
88
- }
89
- } else {
90
- // overload 2
91
- inputOffset = 0;
92
- inputLength = input.byteLength;
93
- outputArgumentIndex = 1;
94
- }
95
-
96
- const [outputLength, paddingLength] = calculateBase64EncodedLength(inputLength);
97
-
98
- let maybeOutput: ArrayBuffer | Uint8Array | undefined = arguments[outputArgumentIndex];
99
- let outputType: 'ArrayBuffer' | 'number';
100
- if (maybeOutput) {
101
- outputOffset = arguments[outputArgumentIndex + 1] ?? 0;
102
-
103
- if (maybeOutput.byteLength - outputOffset < outputLength) {
104
- throw new Error('output buffer is too small');
105
- }
106
-
107
- if (maybeOutput instanceof ArrayBuffer) {
108
- output = new Uint8Array(maybeOutput);
109
- } else {
110
- output = maybeOutput;
111
- }
112
-
113
- outputType = 'number';
114
- } else {
115
- const buffer = new ArrayBuffer(outputLength);
116
- output = new Uint8Array(buffer);
117
- outputOffset = 0;
118
- outputType = 'ArrayBuffer';
119
- }
120
-
121
- // Because `Uint8Array` is type compatible with `ArrayBuffer`,
122
- // TypeScript doesn't correctly narrow `output` to `Uint8Array` when assigning.
123
- // Manually eliminate `ArrayBuffer` from `output` with a type guard.
124
- if (output instanceof ArrayBuffer) {
125
- return output;
126
- }
127
-
128
- if (input.buffer === output.buffer) {
129
- const bufferInputStart = input.byteOffset + inputOffset;
130
- const bufferOutputStart = output.byteOffset + outputOffset;
131
- if (bufferOutputStart < bufferInputStart - 1) {
132
- const bufferOutputEnd = bufferOutputStart + outputLength;
133
- if (bufferOutputEnd >= bufferInputStart) {
134
- throw new Error('input and output buffer can not be overlapping');
135
- }
136
- }
137
- }
138
-
139
- // Run backward to do in-place overwrite
140
- let inputIndex = inputOffset + inputLength - 1;
141
- let outputIndex = outputOffset + outputLength - 1;
142
-
143
- if (paddingLength === 2) {
144
- // aaaaaabb
145
- const x = input[inputIndex];
146
- inputIndex -= 1;
147
-
148
- output[outputIndex] = paddingChar;
149
- outputIndex -= 1;
150
-
151
- output[outputIndex] = paddingChar;
152
- outputIndex -= 1;
153
-
154
- output[outputIndex] = indexToChar[((x & 0b11) << 4)];
155
- outputIndex -= 1;
156
-
157
- output[outputIndex] = indexToChar[x >> 2];
158
- outputIndex -= 1;
159
- } else if (paddingLength === 1) {
160
- // bbbbcccc
161
- const y = input[inputIndex];
162
- inputIndex -= 1;
163
-
164
- // aaaaaabb
165
- const x = input[inputIndex];
166
- inputIndex -= 1;
167
-
168
- output[outputIndex] = paddingChar;
169
- outputIndex -= 1;
170
-
171
- output[outputIndex] = indexToChar[((y & 0b1111) << 2)];
172
- outputIndex -= 1;
173
-
174
- output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
175
- outputIndex -= 1;
176
-
177
- output[outputIndex] = indexToChar[x >> 2];
178
- outputIndex -= 1;
179
- }
180
-
181
- while (inputIndex >= inputOffset) {
182
- // ccdddddd
183
- const z = input[inputIndex];
184
- inputIndex -= 1;
185
-
186
- // bbbbcccc
187
- const y = input[inputIndex];
188
- inputIndex -= 1;
189
-
190
- // aaaaaabb
191
- const x = input[inputIndex];
192
- inputIndex -= 1;
193
-
194
- output[outputIndex] = indexToChar[z & 0b111111];
195
- outputIndex -= 1;
196
-
197
- output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
198
- outputIndex -= 1;
199
-
200
- output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
201
- outputIndex -= 1;
202
-
203
- output[outputIndex] = indexToChar[x >> 2];
204
- outputIndex -= 1;
205
- }
206
-
207
- if (outputType === 'ArrayBuffer') {
208
- return output.buffer;
209
- } else {
210
- return outputLength;
211
- }
212
- }
213
-
214
- export function decodeBase64(input: string): ArrayBuffer {
215
- let padding: number;
216
- if (input[input.length - 2] === '=') {
217
- padding = 2;
218
- } else if (input[input.length - 1] === '=') {
219
- padding = 1;
220
- } else {
221
- padding = 0;
222
- }
223
-
224
- const result = new Uint8Array(input.length / 4 * 3 - padding);
225
- let sIndex = 0;
226
- let dIndex = 0;
227
-
228
- while (sIndex < input.length - (padding !== 0 ? 4 : 0)) {
229
- const a = charToIndex[input[sIndex]];
230
- sIndex += 1;
231
-
232
- const b = charToIndex[input[sIndex]];
233
- sIndex += 1;
234
-
235
- const c = charToIndex[input[sIndex]];
236
- sIndex += 1;
237
-
238
- const d = charToIndex[input[sIndex]];
239
- sIndex += 1;
240
-
241
- result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
242
- dIndex += 1;
243
-
244
- result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2);
245
- dIndex += 1;
246
-
247
- result[dIndex] = ((c & 0b11) << 6) | d;
248
- dIndex += 1;
249
- }
250
-
251
- if (padding === 1) {
252
- const a = charToIndex[input[sIndex]];
253
- sIndex += 1;
254
-
255
- const b = charToIndex[input[sIndex]];
256
- sIndex += 1;
257
-
258
- const c = charToIndex[input[sIndex]];
259
-
260
- result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
261
- dIndex += 1;
262
-
263
- result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2);
264
- } else if (padding === 2) {
265
- const a = charToIndex[input[sIndex]];
266
- sIndex += 1;
267
-
268
- const b = charToIndex[input[sIndex]];
269
-
270
- result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
271
- }
272
-
273
- return result.buffer;
274
- }
1
+ // Prepare maps for O(1) searching
2
+ const charToIndex: Record<string, number> = {};
3
+ const indexToChar: number[] = [];
4
+ const paddingChar = '='.charCodeAt(0);
5
+
6
+ function addRange(start: string, end: string) {
7
+ const charCodeStart = start.charCodeAt(0);
8
+ const charCodeEnd = end.charCodeAt(0);
9
+
10
+ for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
11
+ charToIndex[String.fromCharCode(charCode)] = indexToChar.length;
12
+ indexToChar.push(charCode);
13
+ }
14
+ }
15
+
16
+ addRange('A', 'Z');
17
+ addRange('a', 'z');
18
+ addRange('0', '9');
19
+ addRange('+', '+');
20
+ addRange('/', '/');
21
+
22
+ export function calculateBase64EncodedLength(inputLength: number): [outputLength: number, paddingLength: number] {
23
+ const remainder = inputLength % 3;
24
+ const paddingLength = remainder !== 0 ? 3 - remainder : 0;
25
+ return [(inputLength + paddingLength) / 3 * 4, paddingLength];
26
+ }
27
+
28
+ export function encodeBase64(
29
+ input: Uint8Array,
30
+ ): Uint8Array;
31
+ export function encodeBase64(
32
+ input: Uint8Array,
33
+ output: Uint8Array,
34
+ ): number;
35
+ export function encodeBase64(
36
+ input: Uint8Array,
37
+ output?: Uint8Array,
38
+ ): Uint8Array | number {
39
+ const [outputLength, paddingLength] = calculateBase64EncodedLength(input.length);
40
+
41
+ if (!output) {
42
+ output = new Uint8Array(outputLength);
43
+ encodeForward(input, output, paddingLength);
44
+ return output;
45
+ } else {
46
+ if (output.length < outputLength) {
47
+ throw new Error('output buffer is too small');
48
+ }
49
+
50
+ output = output.subarray(0, outputLength);
51
+
52
+ // When input and output are on same ArrayBuffer,
53
+ // we check if it's possible to encode in-place.
54
+ if (input.buffer !== output.buffer) {
55
+ encodeForward(input, output, paddingLength);
56
+ } else if (output.byteOffset + output.length - (paddingLength + 1) <= input.byteOffset + input.length) {
57
+ // Output ends before input ends
58
+ // So output won't catch up with input.
59
+
60
+ // Depends on padding length,
61
+ // it's possible to write 1-3 bytes after input ends.
62
+ // spell: disable-next-line
63
+ // | aaaaaabb | | | |
64
+ // | aaaaaa | bb0000 | = | = |
65
+ //
66
+ // spell: disable-next-line
67
+ // | aaaaaabb | bbbbcccc | | |
68
+ // | aaaaaa | bbbbbb | cccc00 | = |
69
+ //
70
+ // spell: disable-next-line
71
+ // | aaaaaabb | bbbbcccc | ccdddddd | |
72
+ // | aaaaaa | bbbbbb | cccccc | dddddd |
73
+
74
+ // Must encode forwards.
75
+ encodeForward(input, output, paddingLength);
76
+ } else if (output.byteOffset >= input.byteOffset - 1) {
77
+ // Output starts after input starts
78
+ // So in backwards, output can't catch up with input.
79
+
80
+ // Because first 3 bytes becomes 4 bytes,
81
+ // it's possible to write 1 byte before input starts.
82
+ // spell: disable-next-line
83
+ // | | aaaaaabb | bbbbcccc | ccdddddd |
84
+ // | aaaaaa | bbbbbb | cccccc | dddddd |
85
+
86
+ // Must encode backwards.
87
+ encodeBackward(input, output, paddingLength);
88
+ } else {
89
+ // Input is in the middle of output,
90
+ // not possible to read neither first or last three bytes,
91
+ throw new Error('input and output cannot overlap');
92
+ }
93
+
94
+ return outputLength;
95
+ }
96
+ }
97
+
98
+ function encodeForward(input: Uint8Array, output: Uint8Array, paddingLength: number) {
99
+ let inputIndex = 0;
100
+ let outputIndex = 0;
101
+
102
+ while (inputIndex < input.length - 2) {
103
+ /* cspell: disable-next-line */
104
+ // aaaaaabb
105
+ const x = input[inputIndex]!;
106
+ inputIndex += 1;
107
+
108
+ /* cspell: disable-next-line */
109
+ // bbbbcccc
110
+ const y = input[inputIndex]!;
111
+ inputIndex += 1;
112
+
113
+ /* cspell: disable-next-line */
114
+ // ccdddddd
115
+ const z = input[inputIndex]!;
116
+ inputIndex += 1;
117
+
118
+ output[outputIndex] = indexToChar[x >> 2]!;
119
+ outputIndex += 1;
120
+
121
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]!;
122
+ outputIndex += 1;
123
+
124
+ output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)]!;
125
+ outputIndex += 1;
126
+
127
+ output[outputIndex] = indexToChar[z & 0b111111]!;
128
+ outputIndex += 1;
129
+ }
130
+
131
+ if (paddingLength === 2) {
132
+ /* cspell: disable-next-line */
133
+ // aaaaaabb
134
+ const x = input[inputIndex]!;
135
+ inputIndex += 1;
136
+
137
+ output[outputIndex] = indexToChar[x >> 2]!;
138
+ outputIndex += 1;
139
+
140
+ output[outputIndex] = indexToChar[((x & 0b11) << 4)]!;
141
+ outputIndex += 1;
142
+
143
+ output[outputIndex] = paddingChar;
144
+ outputIndex += 1;
145
+
146
+ output[outputIndex] = paddingChar;
147
+ } else if (paddingLength === 1) {
148
+ /* cspell: disable-next-line */
149
+ // aaaaaabb
150
+ const x = input[inputIndex]!;
151
+ inputIndex += 1;
152
+
153
+ /* cspell: disable-next-line */
154
+ // bbbbcccc
155
+ const y = input[inputIndex]!;
156
+ inputIndex += 1;
157
+
158
+ output[outputIndex] = indexToChar[x >> 2]!;
159
+ outputIndex += 1;
160
+
161
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]!;
162
+ outputIndex += 1;
163
+
164
+ output[outputIndex] = indexToChar[((y & 0b1111) << 2)]!;
165
+ outputIndex += 1;
166
+
167
+ output[outputIndex] = paddingChar;
168
+ }
169
+ }
170
+
171
+ function encodeBackward(input: Uint8Array, output: Uint8Array, paddingLength: number) {
172
+ let inputIndex = input.length - 1;
173
+ let outputIndex = output.length - 1;
174
+
175
+ if (paddingLength === 2) {
176
+ /* cspell: disable-next-line */
177
+ // aaaaaabb
178
+ const x = input[inputIndex]!;
179
+ inputIndex -= 1;
180
+
181
+ output[outputIndex] = paddingChar;
182
+ outputIndex -= 1;
183
+
184
+ output[outputIndex] = paddingChar;
185
+ outputIndex -= 1;
186
+
187
+ output[outputIndex] = indexToChar[((x & 0b11) << 4)]!;
188
+ outputIndex -= 1;
189
+
190
+ output[outputIndex] = indexToChar[x >> 2]!;
191
+ outputIndex -= 1;
192
+ } else if (paddingLength === 1) {
193
+ /* cspell: disable-next-line */
194
+ // bbbbcccc
195
+ const y = input[inputIndex]!;
196
+ inputIndex -= 1;
197
+
198
+ /* cspell: disable-next-line */
199
+ // aaaaaabb
200
+ const x = input[inputIndex]!;
201
+ inputIndex -= 1;
202
+
203
+ output[outputIndex] = paddingChar;
204
+ outputIndex -= 1;
205
+
206
+ output[outputIndex] = indexToChar[((y & 0b1111) << 2)]!;
207
+ outputIndex -= 1;
208
+
209
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]!;
210
+ outputIndex -= 1;
211
+
212
+ output[outputIndex] = indexToChar[x >> 2]!;
213
+ outputIndex -= 1;
214
+ }
215
+
216
+ while (inputIndex >= 0) {
217
+ /* cspell: disable-next-line */
218
+ // ccdddddd
219
+ const z = input[inputIndex]!;
220
+ inputIndex -= 1;
221
+
222
+ /* cspell: disable-next-line */
223
+ // bbbbcccc
224
+ const y = input[inputIndex]!;
225
+ inputIndex -= 1;
226
+
227
+ /* cspell: disable-next-line */
228
+ // aaaaaabb
229
+ const x = input[inputIndex]!;
230
+ inputIndex -= 1;
231
+
232
+ output[outputIndex] = indexToChar[z & 0b111111]!;
233
+ outputIndex -= 1;
234
+
235
+ output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)]!;
236
+ outputIndex -= 1;
237
+
238
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]!;
239
+ outputIndex -= 1;
240
+
241
+ output[outputIndex] = indexToChar[x >> 2]!;
242
+ outputIndex -= 1;
243
+ }
244
+ }
245
+
246
+ export function decodeBase64(input: string): Uint8Array {
247
+ let padding: number;
248
+ if (input[input.length - 2] === '=') {
249
+ padding = 2;
250
+ } else if (input[input.length - 1] === '=') {
251
+ padding = 1;
252
+ } else {
253
+ padding = 0;
254
+ }
255
+
256
+ const result = new Uint8Array(input.length / 4 * 3 - padding);
257
+ let sIndex = 0;
258
+ let dIndex = 0;
259
+
260
+ while (sIndex < input.length - (padding !== 0 ? 4 : 0)) {
261
+ const a = charToIndex[input[sIndex]!]!;
262
+ sIndex += 1;
263
+
264
+ const b = charToIndex[input[sIndex]!]!;
265
+ sIndex += 1;
266
+
267
+ const c = charToIndex[input[sIndex]!]!;
268
+ sIndex += 1;
269
+
270
+ const d = charToIndex[input[sIndex]!]!;
271
+ sIndex += 1;
272
+
273
+ result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
274
+ dIndex += 1;
275
+
276
+ result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2);
277
+ dIndex += 1;
278
+
279
+ result[dIndex] = ((c & 0b11) << 6) | d;
280
+ dIndex += 1;
281
+ }
282
+
283
+ if (padding === 1) {
284
+ const a = charToIndex[input[sIndex]!]!;
285
+ sIndex += 1;
286
+
287
+ const b = charToIndex[input[sIndex]!]!;
288
+ sIndex += 1;
289
+
290
+ const c = charToIndex[input[sIndex]!]!;
291
+
292
+ result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
293
+ dIndex += 1;
294
+
295
+ result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2);
296
+ } else if (padding === 2) {
297
+ const a = charToIndex[input[sIndex]!]!;
298
+ sIndex += 1;
299
+
300
+ const b = charToIndex[input[sIndex]!]!;
301
+
302
+ result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
303
+ }
304
+
305
+ return result;
306
+ }
@@ -0,0 +1,13 @@
1
+
2
+ // @ts-expect-error @types/node missing `TextEncoder`
3
+ const Utf8Encoder = new TextEncoder();
4
+ // @ts-expect-error @types/node missing `TextDecoder`
5
+ const Utf8Decoder = new TextDecoder();
6
+
7
+ export function encodeUtf8(input: string): Uint8Array {
8
+ return Utf8Encoder.encode(input);
9
+ }
10
+
11
+ export function decodeUtf8(buffer: ArrayBufferView | ArrayBuffer): string {
12
+ return Utf8Decoder.decode(buffer);
13
+ }
@@ -1,4 +1,3 @@
1
- export * from './auto-reset-event';
2
- export * from './base64';
3
- export * from './chunk';
4
- export * from './event-queue';
1
+ export * from './auto-reset-event.js';
2
+ export * from './base64.js';
3
+ export * from './encoding.js';
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./node_modules/@yume-chan/ts-package-builder/tsconfig.base.json"
3
+ }