@yume-chan/adb 2.6.0 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (449) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/esm/adb.d.ts +18 -15
  4. package/esm/adb.d.ts.map +1 -1
  5. package/esm/adb.js +18 -11
  6. package/esm/adb.js.map +1 -1
  7. package/esm/banner.d.ts +1 -1
  8. package/esm/banner.d.ts.map +1 -1
  9. package/esm/daemon/auth/authenticator.d.ts +28 -0
  10. package/esm/daemon/auth/authenticator.d.ts.map +1 -0
  11. package/esm/daemon/auth/authenticator.js +108 -0
  12. package/esm/daemon/auth/authenticator.js.map +1 -0
  13. package/esm/daemon/auth/index.d.ts +5 -0
  14. package/esm/daemon/auth/index.d.ts.map +1 -0
  15. package/esm/daemon/auth/index.js +5 -0
  16. package/esm/daemon/auth/index.js.map +1 -0
  17. package/esm/daemon/auth/packet-processor.d.ts +42 -0
  18. package/esm/daemon/auth/packet-processor.d.ts.map +1 -0
  19. package/esm/daemon/auth/packet-processor.js +129 -0
  20. package/esm/daemon/auth/packet-processor.js.map +1 -0
  21. package/esm/daemon/auth/public-key.d.ts +8 -0
  22. package/esm/daemon/auth/public-key.d.ts.map +1 -0
  23. package/esm/daemon/auth/public-key.js +74 -0
  24. package/esm/daemon/auth/public-key.js.map +1 -0
  25. package/esm/daemon/auth/type.d.ts +5 -0
  26. package/esm/daemon/auth/type.d.ts.map +1 -0
  27. package/esm/daemon/auth/type.js +2 -0
  28. package/esm/daemon/auth/type.js.map +1 -0
  29. package/esm/daemon/crypto.d.ts +6 -5
  30. package/esm/daemon/crypto.d.ts.map +1 -1
  31. package/esm/daemon/crypto.js +23 -73
  32. package/esm/daemon/crypto.js.map +1 -1
  33. package/esm/daemon/dispatcher.d.ts +3 -3
  34. package/esm/daemon/dispatcher.d.ts.map +1 -1
  35. package/esm/daemon/dispatcher.js +11 -4
  36. package/esm/daemon/dispatcher.js.map +1 -1
  37. package/esm/daemon/index.d.ts +1 -1
  38. package/esm/daemon/index.d.ts.map +1 -1
  39. package/esm/daemon/index.js +1 -1
  40. package/esm/daemon/index.js.map +1 -1
  41. package/esm/daemon/socket.d.ts +3 -3
  42. package/esm/daemon/socket.d.ts.map +1 -1
  43. package/esm/daemon/transport.d.ts +13 -65
  44. package/esm/daemon/transport.d.ts.map +1 -1
  45. package/esm/daemon/transport.js +18 -140
  46. package/esm/daemon/transport.js.map +1 -1
  47. package/esm/device-observer.d.ts +2 -3
  48. package/esm/device-observer.d.ts.map +1 -1
  49. package/esm/features-value.d.ts +40 -0
  50. package/esm/features-value.d.ts.map +1 -0
  51. package/esm/features-value.js +46 -0
  52. package/esm/features-value.js.map +1 -0
  53. package/esm/features.d.ts +4 -12
  54. package/esm/features.d.ts.map +1 -1
  55. package/esm/features.js +27 -13
  56. package/esm/features.js.map +1 -1
  57. package/esm/index.d.ts +1 -1
  58. package/esm/index.d.ts.map +1 -1
  59. package/esm/index.js +1 -1
  60. package/esm/index.js.map +1 -1
  61. package/esm/server/client.d.ts +7 -7
  62. package/esm/server/client.d.ts.map +1 -1
  63. package/esm/server/client.js +69 -86
  64. package/esm/server/client.js.map +1 -1
  65. package/esm/server/commands/wireless.js +1 -1
  66. package/esm/server/commands/wireless.js.map +1 -1
  67. package/esm/server/{stream.d.ts → data-connection.d.ts} +5 -5
  68. package/esm/server/data-connection.d.ts.map +1 -0
  69. package/esm/server/{stream.js → data-connection.js} +4 -4
  70. package/esm/server/data-connection.js.map +1 -0
  71. package/esm/server/index.d.ts +1 -1
  72. package/esm/server/index.d.ts.map +1 -1
  73. package/esm/server/index.js +1 -1
  74. package/esm/server/index.js.map +1 -1
  75. package/esm/server/observer.d.ts.map +1 -1
  76. package/esm/server/observer.js +14 -13
  77. package/esm/server/observer.js.map +1 -1
  78. package/esm/server/transport.d.ts +4 -6
  79. package/esm/server/transport.d.ts.map +1 -1
  80. package/esm/server/transport.js +9 -24
  81. package/esm/server/transport.js.map +1 -1
  82. package/esm/service/framebuffer.d.ts.map +1 -0
  83. package/esm/service/framebuffer.js.map +1 -0
  84. package/esm/{commands → service}/index.d.ts +1 -2
  85. package/esm/service/index.d.ts.map +1 -0
  86. package/esm/{commands → service}/index.js +1 -2
  87. package/esm/service/index.js.map +1 -0
  88. package/esm/{commands → service}/power.d.ts +4 -2
  89. package/esm/service/power.d.ts.map +1 -0
  90. package/esm/{commands → service}/power.js +11 -5
  91. package/esm/service/power.js.map +1 -0
  92. package/esm/service/reverse/error.d.ts +14 -0
  93. package/esm/service/reverse/error.d.ts.map +1 -0
  94. package/esm/service/reverse/error.js +21 -0
  95. package/esm/service/reverse/error.js.map +1 -0
  96. package/esm/service/reverse/index.d.ts +3 -0
  97. package/esm/service/reverse/index.d.ts.map +1 -0
  98. package/esm/service/reverse/index.js +4 -0
  99. package/esm/service/reverse/index.js.map +1 -0
  100. package/esm/service/reverse/response.d.ts +2 -0
  101. package/esm/service/reverse/response.d.ts.map +1 -0
  102. package/esm/service/reverse/response.js +30 -0
  103. package/esm/service/reverse/response.js.map +1 -0
  104. package/esm/service/reverse/service.d.ts +59 -0
  105. package/esm/service/reverse/service.d.ts.map +1 -0
  106. package/esm/{commands/reverse.js → service/reverse/service.js} +16 -45
  107. package/esm/service/reverse/service.js.map +1 -0
  108. package/esm/{commands → service}/subprocess/index.d.ts +1 -0
  109. package/esm/service/subprocess/index.d.ts.map +1 -0
  110. package/esm/{commands → service}/subprocess/index.js +1 -0
  111. package/esm/service/subprocess/index.js.map +1 -0
  112. package/esm/service/subprocess/none/index.d.ts.map +1 -0
  113. package/esm/service/subprocess/none/index.js.map +1 -0
  114. package/esm/{commands → service}/subprocess/none/process.d.ts +2 -2
  115. package/esm/service/subprocess/none/process.d.ts.map +1 -0
  116. package/esm/service/subprocess/none/process.js.map +1 -0
  117. package/esm/{commands → service}/subprocess/none/pty.d.ts +4 -4
  118. package/esm/service/subprocess/none/pty.d.ts.map +1 -0
  119. package/esm/{commands → service}/subprocess/none/pty.js +1 -1
  120. package/esm/service/subprocess/none/pty.js.map +1 -0
  121. package/esm/service/subprocess/none/service.d.ts +10 -0
  122. package/esm/service/subprocess/none/service.d.ts.map +1 -0
  123. package/esm/service/subprocess/none/service.js +44 -0
  124. package/esm/service/subprocess/none/service.js.map +1 -0
  125. package/esm/service/subprocess/none/spawner.d.ts +15 -0
  126. package/esm/service/subprocess/none/spawner.d.ts.map +1 -0
  127. package/esm/service/subprocess/none/spawner.js +31 -0
  128. package/esm/service/subprocess/none/spawner.js.map +1 -0
  129. package/esm/{commands → service}/subprocess/pty.d.ts +1 -1
  130. package/esm/service/subprocess/pty.d.ts.map +1 -0
  131. package/esm/{commands → service}/subprocess/pty.js.map +1 -1
  132. package/esm/service/subprocess/service.d.ts.map +1 -0
  133. package/esm/{commands → service}/subprocess/service.js +1 -1
  134. package/esm/service/subprocess/service.js.map +1 -0
  135. package/esm/service/subprocess/shell/index.d.ts +5 -0
  136. package/esm/{commands/subprocess/none → service/subprocess/shell}/index.d.ts.map +1 -1
  137. package/esm/service/subprocess/shell/index.js +6 -0
  138. package/esm/{commands/subprocess/none → service/subprocess/shell}/index.js.map +1 -1
  139. package/esm/{commands → service}/subprocess/shell/process.d.ts +2 -2
  140. package/esm/service/subprocess/shell/process.d.ts.map +1 -0
  141. package/esm/{commands → service}/subprocess/shell/process.js +4 -6
  142. package/esm/service/subprocess/shell/process.js.map +1 -0
  143. package/esm/{commands → service}/subprocess/shell/pty.d.ts +4 -4
  144. package/esm/service/subprocess/shell/pty.d.ts.map +1 -0
  145. package/esm/{commands → service}/subprocess/shell/pty.js +11 -9
  146. package/esm/service/subprocess/shell/pty.js.map +1 -0
  147. package/esm/service/subprocess/shell/service.d.ts +34 -0
  148. package/esm/service/subprocess/shell/service.d.ts.map +1 -0
  149. package/esm/service/subprocess/shell/service.js +52 -0
  150. package/esm/service/subprocess/shell/service.js.map +1 -0
  151. package/esm/service/subprocess/shell/shared.d.ts +2 -0
  152. package/esm/service/subprocess/shell/shared.d.ts.map +1 -0
  153. package/esm/{commands → service}/subprocess/shell/shared.js +2 -0
  154. package/esm/service/subprocess/shell/shared.js.map +1 -0
  155. package/esm/{commands → service}/subprocess/shell/spawner.d.ts +3 -7
  156. package/esm/service/subprocess/shell/spawner.d.ts.map +1 -0
  157. package/esm/service/subprocess/shell/spawner.js +45 -0
  158. package/esm/service/subprocess/shell/spawner.js.map +1 -0
  159. package/esm/service/subprocess/types.d.ts +14 -0
  160. package/esm/service/subprocess/types.d.ts.map +1 -0
  161. package/esm/service/subprocess/types.js +2 -0
  162. package/esm/service/subprocess/types.js.map +1 -0
  163. package/esm/service/subprocess/utils.d.ts +39 -0
  164. package/esm/service/subprocess/utils.d.ts.map +1 -0
  165. package/esm/service/subprocess/utils.js +142 -0
  166. package/esm/service/subprocess/utils.js.map +1 -0
  167. package/esm/service/sync/android.d.ts +34 -0
  168. package/esm/service/sync/android.d.ts.map +1 -0
  169. package/esm/service/sync/android.js +34 -0
  170. package/esm/service/sync/android.js.map +1 -0
  171. package/esm/service/sync/compression/compression.d.ts +17 -0
  172. package/esm/service/sync/compression/compression.d.ts.map +1 -0
  173. package/esm/service/sync/compression/compression.js +92 -0
  174. package/esm/service/sync/compression/compression.js.map +1 -0
  175. package/esm/service/sync/compression/format-ns.d.ts +5 -0
  176. package/esm/service/sync/compression/format-ns.d.ts.map +1 -0
  177. package/esm/service/sync/compression/format-ns.js +5 -0
  178. package/esm/service/sync/compression/format-ns.js.map +1 -0
  179. package/esm/service/sync/compression/format.d.ts +4 -0
  180. package/esm/service/sync/compression/format.d.ts.map +1 -0
  181. package/esm/service/sync/compression/format.js +3 -0
  182. package/esm/service/sync/compression/format.js.map +1 -0
  183. package/esm/service/sync/compression/index.d.ts +2 -0
  184. package/esm/service/sync/compression/index.d.ts.map +1 -0
  185. package/esm/service/sync/compression/index.js +2 -0
  186. package/esm/service/sync/compression/index.js.map +1 -0
  187. package/esm/service/sync/id/common.d.ts +17 -0
  188. package/esm/service/sync/id/common.d.ts.map +1 -0
  189. package/esm/service/sync/id/common.js +29 -0
  190. package/esm/service/sync/id/common.js.map +1 -0
  191. package/esm/service/sync/id/index.d.ts +4 -0
  192. package/esm/service/sync/id/index.d.ts.map +1 -0
  193. package/esm/service/sync/id/index.js +6 -0
  194. package/esm/service/sync/id/index.js.map +1 -0
  195. package/esm/service/sync/id/request.d.ts +7 -0
  196. package/esm/service/sync/id/request.d.ts.map +1 -0
  197. package/esm/service/sync/id/request.js +9 -0
  198. package/esm/service/sync/id/request.js.map +1 -0
  199. package/esm/service/sync/id/response.d.ts +6 -0
  200. package/esm/service/sync/id/response.d.ts.map +1 -0
  201. package/esm/service/sync/id/response.js +8 -0
  202. package/esm/service/sync/id/response.js.map +1 -0
  203. package/esm/service/sync/index-ns.d.ts +7 -0
  204. package/esm/service/sync/index-ns.d.ts.map +1 -0
  205. package/esm/service/sync/index-ns.js +7 -0
  206. package/esm/service/sync/index-ns.js.map +1 -0
  207. package/esm/service/sync/index.d.ts +3 -0
  208. package/esm/service/sync/index.d.ts.map +1 -0
  209. package/esm/service/sync/index.js +3 -0
  210. package/esm/service/sync/index.js.map +1 -0
  211. package/esm/service/sync/request/index.d.ts +5 -0
  212. package/esm/service/sync/request/index.d.ts.map +1 -0
  213. package/esm/service/sync/request/index.js +5 -0
  214. package/esm/service/sync/request/index.js.map +1 -0
  215. package/esm/{commands/sync → service/sync/request}/list.d.ts +21 -19
  216. package/esm/service/sync/request/list.d.ts.map +1 -0
  217. package/esm/service/sync/request/list.js +77 -0
  218. package/esm/service/sync/request/list.js.map +1 -0
  219. package/esm/service/sync/request/pull.d.ts +12 -0
  220. package/esm/service/sync/request/pull.d.ts.map +1 -0
  221. package/esm/service/sync/request/pull.js +28 -0
  222. package/esm/service/sync/request/pull.js.map +1 -0
  223. package/esm/service/sync/request/push.d.ts +54 -0
  224. package/esm/service/sync/request/push.d.ts.map +1 -0
  225. package/esm/service/sync/request/push.js +95 -0
  226. package/esm/service/sync/request/push.js.map +1 -0
  227. package/esm/{commands/sync → service/sync/request}/stat.d.ts +40 -50
  228. package/esm/service/sync/request/stat.d.ts.map +1 -0
  229. package/esm/service/sync/request/stat.js +89 -0
  230. package/esm/service/sync/request/stat.js.map +1 -0
  231. package/esm/service/sync/service.d.ts +123 -0
  232. package/esm/service/sync/service.d.ts.map +1 -0
  233. package/esm/service/sync/service.js +170 -0
  234. package/esm/service/sync/service.js.map +1 -0
  235. package/esm/service/sync/socket-pool.d.ts +11 -0
  236. package/esm/service/sync/socket-pool.d.ts.map +1 -0
  237. package/esm/service/sync/socket-pool.js +80 -0
  238. package/esm/service/sync/socket-pool.js.map +1 -0
  239. package/esm/service/sync/socket.d.ts +40 -0
  240. package/esm/service/sync/socket.d.ts.map +1 -0
  241. package/esm/service/sync/socket.js +153 -0
  242. package/esm/service/sync/socket.js.map +1 -0
  243. package/esm/{commands → service}/tcpip.d.ts +4 -2
  244. package/esm/service/tcpip.d.ts.map +1 -0
  245. package/esm/{commands → service}/tcpip.js +10 -7
  246. package/esm/service/tcpip.js.map +1 -0
  247. package/esm/utils/array-buffer.d.ts.map +1 -1
  248. package/esm/utils/array-buffer.js +2 -3
  249. package/esm/utils/array-buffer.js.map +1 -1
  250. package/esm/utils/base64.d.ts.map +1 -1
  251. package/esm/utils/base64.js +22 -12
  252. package/esm/utils/base64.js.map +1 -1
  253. package/esm/utils/index.d.ts +1 -0
  254. package/esm/utils/index.d.ts.map +1 -1
  255. package/esm/utils/index.js +1 -0
  256. package/esm/utils/index.js.map +1 -1
  257. package/esm/utils/md5.d.ts +8 -0
  258. package/esm/utils/md5.d.ts.map +1 -0
  259. package/esm/utils/md5.js +149 -0
  260. package/esm/utils/md5.js.map +1 -0
  261. package/package.json +10 -10
  262. package/src/adb.ts +44 -34
  263. package/src/daemon/auth/authenticator.ts +186 -0
  264. package/src/daemon/auth/index.ts +4 -0
  265. package/src/daemon/auth/packet-processor.ts +212 -0
  266. package/src/daemon/auth/public-key.ts +112 -0
  267. package/src/daemon/auth/type.ts +5 -0
  268. package/src/daemon/crypto.ts +36 -102
  269. package/src/daemon/dispatcher.ts +15 -8
  270. package/src/daemon/index.ts +1 -1
  271. package/src/daemon/socket.ts +3 -3
  272. package/src/daemon/transport.ts +35 -253
  273. package/src/device-observer.ts +3 -3
  274. package/src/features-value.ts +47 -0
  275. package/src/features.ts +31 -14
  276. package/src/index.ts +1 -1
  277. package/src/server/client.ts +96 -94
  278. package/src/server/commands/wireless.ts +1 -1
  279. package/src/server/{stream.ts → data-connection.ts} +4 -4
  280. package/src/server/index.ts +1 -1
  281. package/src/server/observer.ts +21 -19
  282. package/src/server/transport.ts +13 -34
  283. package/src/{commands → service}/index.ts +1 -2
  284. package/src/{commands → service}/power.ts +14 -5
  285. package/src/service/reverse/error.ts +35 -0
  286. package/src/service/reverse/index.ts +3 -0
  287. package/src/service/reverse/response.ts +38 -0
  288. package/src/{commands/reverse.ts → service/reverse/service.ts} +32 -72
  289. package/src/{commands → service}/subprocess/index.ts +1 -0
  290. package/src/{commands → service}/subprocess/none/process.ts +3 -3
  291. package/src/{commands → service}/subprocess/none/pty.ts +5 -5
  292. package/src/service/subprocess/none/service.ts +57 -0
  293. package/src/service/subprocess/none/spawner.ts +81 -0
  294. package/src/{commands → service}/subprocess/pty.ts +1 -1
  295. package/src/{commands → service}/subprocess/service.ts +1 -1
  296. package/src/{commands → service}/subprocess/shell/index.ts +1 -1
  297. package/src/{commands → service}/subprocess/shell/process.ts +6 -7
  298. package/src/{commands → service}/subprocess/shell/pty.ts +15 -13
  299. package/src/service/subprocess/shell/service.ts +75 -0
  300. package/src/{commands → service}/subprocess/shell/shared.ts +5 -0
  301. package/src/service/subprocess/shell/spawner.ts +109 -0
  302. package/src/service/subprocess/types.ts +19 -0
  303. package/src/service/subprocess/utils.ts +166 -0
  304. package/src/service/sync/android.ts +43 -0
  305. package/src/service/sync/compression/compression.ts +126 -0
  306. package/src/service/sync/compression/format-ns.ts +4 -0
  307. package/src/service/sync/compression/format.ts +5 -0
  308. package/src/service/sync/compression/index.ts +1 -0
  309. package/src/service/sync/id/common.ts +33 -0
  310. package/src/service/sync/id/index.ts +7 -0
  311. package/src/service/sync/id/request.ts +12 -0
  312. package/src/service/sync/id/response.ts +11 -0
  313. package/src/service/sync/index-ns.ts +6 -0
  314. package/src/service/sync/index.ts +2 -0
  315. package/src/service/sync/request/index.ts +4 -0
  316. package/src/service/sync/request/list.ts +110 -0
  317. package/src/service/sync/request/pull.ts +49 -0
  318. package/src/service/sync/request/push.ts +184 -0
  319. package/src/service/sync/request/stat.ts +127 -0
  320. package/src/service/sync/service.ts +255 -0
  321. package/src/service/sync/socket-pool.ts +97 -0
  322. package/src/service/sync/socket.ts +201 -0
  323. package/src/{commands → service}/tcpip.ts +13 -7
  324. package/src/utils/array-buffer.ts +2 -3
  325. package/src/utils/base64.ts +24 -12
  326. package/src/utils/index.ts +1 -0
  327. package/src/utils/md5.ts +185 -0
  328. package/yume-chan-adb-3.0.0-beta.0.tgz +0 -0
  329. package/CHANGELOG.md +0 -251
  330. package/esm/commands/base.d.ts +0 -8
  331. package/esm/commands/base.d.ts.map +0 -1
  332. package/esm/commands/base.js +0 -12
  333. package/esm/commands/base.js.map +0 -1
  334. package/esm/commands/framebuffer.d.ts.map +0 -1
  335. package/esm/commands/framebuffer.js.map +0 -1
  336. package/esm/commands/index.d.ts.map +0 -1
  337. package/esm/commands/index.js.map +0 -1
  338. package/esm/commands/power.d.ts.map +0 -1
  339. package/esm/commands/power.js.map +0 -1
  340. package/esm/commands/reverse.d.ts +0 -48
  341. package/esm/commands/reverse.d.ts.map +0 -1
  342. package/esm/commands/reverse.js.map +0 -1
  343. package/esm/commands/subprocess/index.d.ts.map +0 -1
  344. package/esm/commands/subprocess/index.js.map +0 -1
  345. package/esm/commands/subprocess/none/process.d.ts.map +0 -1
  346. package/esm/commands/subprocess/none/process.js.map +0 -1
  347. package/esm/commands/subprocess/none/pty.d.ts.map +0 -1
  348. package/esm/commands/subprocess/none/pty.js.map +0 -1
  349. package/esm/commands/subprocess/none/service.d.ts +0 -10
  350. package/esm/commands/subprocess/none/service.d.ts.map +0 -1
  351. package/esm/commands/subprocess/none/service.js +0 -34
  352. package/esm/commands/subprocess/none/service.js.map +0 -1
  353. package/esm/commands/subprocess/none/spawner.d.ts +0 -19
  354. package/esm/commands/subprocess/none/spawner.d.ts.map +0 -1
  355. package/esm/commands/subprocess/none/spawner.js +0 -26
  356. package/esm/commands/subprocess/none/spawner.js.map +0 -1
  357. package/esm/commands/subprocess/pty.d.ts.map +0 -1
  358. package/esm/commands/subprocess/service.d.ts.map +0 -1
  359. package/esm/commands/subprocess/service.js.map +0 -1
  360. package/esm/commands/subprocess/shell/index.d.ts +0 -6
  361. package/esm/commands/subprocess/shell/index.d.ts.map +0 -1
  362. package/esm/commands/subprocess/shell/index.js +0 -6
  363. package/esm/commands/subprocess/shell/index.js.map +0 -1
  364. package/esm/commands/subprocess/shell/process.d.ts.map +0 -1
  365. package/esm/commands/subprocess/shell/process.js.map +0 -1
  366. package/esm/commands/subprocess/shell/pty.d.ts.map +0 -1
  367. package/esm/commands/subprocess/shell/pty.js.map +0 -1
  368. package/esm/commands/subprocess/shell/service.d.ts +0 -14
  369. package/esm/commands/subprocess/shell/service.d.ts.map +0 -1
  370. package/esm/commands/subprocess/shell/service.js +0 -41
  371. package/esm/commands/subprocess/shell/service.js.map +0 -1
  372. package/esm/commands/subprocess/shell/shared.d.ts +0 -19
  373. package/esm/commands/subprocess/shell/shared.d.ts.map +0 -1
  374. package/esm/commands/subprocess/shell/shared.js.map +0 -1
  375. package/esm/commands/subprocess/shell/spawner.d.ts.map +0 -1
  376. package/esm/commands/subprocess/shell/spawner.js +0 -38
  377. package/esm/commands/subprocess/shell/spawner.js.map +0 -1
  378. package/esm/commands/subprocess/utils.d.ts +0 -3
  379. package/esm/commands/subprocess/utils.d.ts.map +0 -1
  380. package/esm/commands/subprocess/utils.js +0 -56
  381. package/esm/commands/subprocess/utils.js.map +0 -1
  382. package/esm/commands/sync/index.d.ts +0 -9
  383. package/esm/commands/sync/index.d.ts.map +0 -1
  384. package/esm/commands/sync/index.js +0 -9
  385. package/esm/commands/sync/index.js.map +0 -1
  386. package/esm/commands/sync/list.d.ts.map +0 -1
  387. package/esm/commands/sync/list.js +0 -64
  388. package/esm/commands/sync/list.js.map +0 -1
  389. package/esm/commands/sync/pull.d.ts +0 -12
  390. package/esm/commands/sync/pull.d.ts.map +0 -1
  391. package/esm/commands/sync/pull.js +0 -33
  392. package/esm/commands/sync/pull.js.map +0 -1
  393. package/esm/commands/sync/push.d.ts +0 -61
  394. package/esm/commands/sync/push.d.ts.map +0 -1
  395. package/esm/commands/sync/push.js +0 -83
  396. package/esm/commands/sync/push.js.map +0 -1
  397. package/esm/commands/sync/request.d.ts +0 -24
  398. package/esm/commands/sync/request.d.ts.map +0 -1
  399. package/esm/commands/sync/request.js +0 -32
  400. package/esm/commands/sync/request.js.map +0 -1
  401. package/esm/commands/sync/response.d.ts +0 -28
  402. package/esm/commands/sync/response.d.ts.map +0 -1
  403. package/esm/commands/sync/response.js +0 -81
  404. package/esm/commands/sync/response.js.map +0 -1
  405. package/esm/commands/sync/socket.d.ts +0 -22
  406. package/esm/commands/sync/socket.d.ts.map +0 -1
  407. package/esm/commands/sync/socket.js +0 -78
  408. package/esm/commands/sync/socket.js.map +0 -1
  409. package/esm/commands/sync/stat.d.ts.map +0 -1
  410. package/esm/commands/sync/stat.js +0 -121
  411. package/esm/commands/sync/stat.js.map +0 -1
  412. package/esm/commands/sync/sync.d.ts +0 -82
  413. package/esm/commands/sync/sync.d.ts.map +0 -1
  414. package/esm/commands/sync/sync.js +0 -138
  415. package/esm/commands/sync/sync.js.map +0 -1
  416. package/esm/commands/tcpip.d.ts.map +0 -1
  417. package/esm/commands/tcpip.js.map +0 -1
  418. package/esm/daemon/auth.d.ts +0 -54
  419. package/esm/daemon/auth.d.ts.map +0 -1
  420. package/esm/daemon/auth.js +0 -104
  421. package/esm/daemon/auth.js.map +0 -1
  422. package/esm/server/stream.d.ts.map +0 -1
  423. package/esm/server/stream.js.map +0 -1
  424. package/src/commands/base.ts +0 -15
  425. package/src/commands/subprocess/none/service.ts +0 -45
  426. package/src/commands/subprocess/none/spawner.ts +0 -68
  427. package/src/commands/subprocess/shell/service.ts +0 -58
  428. package/src/commands/subprocess/shell/spawner.ts +0 -90
  429. package/src/commands/subprocess/utils.ts +0 -61
  430. package/src/commands/sync/index.ts +0 -8
  431. package/src/commands/sync/list.ts +0 -99
  432. package/src/commands/sync/pull.ts +0 -55
  433. package/src/commands/sync/push.ts +0 -172
  434. package/src/commands/sync/request.ts +0 -53
  435. package/src/commands/sync/response.ts +0 -105
  436. package/src/commands/sync/socket.ts +0 -109
  437. package/src/commands/sync/stat.ts +0 -177
  438. package/src/commands/sync/sync.ts +0 -175
  439. package/src/daemon/auth.ts +0 -204
  440. package/tsconfig.build.tsbuildinfo +0 -1
  441. /package/esm/{commands → service}/framebuffer.d.ts +0 -0
  442. /package/esm/{commands → service}/framebuffer.js +0 -0
  443. /package/esm/{commands → service}/subprocess/none/index.d.ts +0 -0
  444. /package/esm/{commands → service}/subprocess/none/index.js +0 -0
  445. /package/esm/{commands → service}/subprocess/none/process.js +0 -0
  446. /package/esm/{commands → service}/subprocess/pty.js +0 -0
  447. /package/esm/{commands → service}/subprocess/service.d.ts +0 -0
  448. /package/src/{commands → service}/framebuffer.ts +0 -0
  449. /package/src/{commands → service}/subprocess/none/index.ts +0 -0
@@ -1,61 +0,0 @@
1
- export function escapeArg(s: string) {
2
- let result = "";
3
- result += `'`;
4
-
5
- let base = 0;
6
- while (true) {
7
- const found = s.indexOf(`'`, base);
8
- if (found === -1) {
9
- result += s.substring(base);
10
- break;
11
- }
12
- result += s.substring(base, found);
13
- // a'b becomes a'\'b (the backslash is not a escape character)
14
- result += String.raw`'\''`;
15
- base = found + 1;
16
- }
17
-
18
- result += `'`;
19
- return result;
20
- }
21
-
22
- export function splitCommand(command: string): string[] {
23
- const result: string[] = [];
24
- let quote: string | undefined;
25
- let isEscaped = false;
26
- let start = 0;
27
-
28
- for (let i = 0, len = command.length; i < len; i += 1) {
29
- if (isEscaped) {
30
- isEscaped = false;
31
- continue;
32
- }
33
-
34
- const char = command.charAt(i);
35
- switch (char) {
36
- case " ":
37
- if (!quote && i !== start) {
38
- result.push(command.substring(start, i));
39
- start = i + 1;
40
- }
41
- break;
42
- case "'":
43
- case '"':
44
- if (!quote) {
45
- quote = char;
46
- } else if (char === quote) {
47
- quote = undefined;
48
- }
49
- break;
50
- case "\\":
51
- isEscaped = true;
52
- break;
53
- }
54
- }
55
-
56
- if (start < command.length) {
57
- result.push(command.substring(start));
58
- }
59
-
60
- return result;
61
- }
@@ -1,8 +0,0 @@
1
- export * from "./list.js";
2
- export * from "./pull.js";
3
- export * from "./push.js";
4
- export * from "./request.js";
5
- export * from "./response.js";
6
- export * from "./socket.js";
7
- export * from "./stat.js";
8
- export * from "./sync.js";
@@ -1,99 +0,0 @@
1
- import type { StructValue } from "@yume-chan/struct";
2
- import { extend, string, u32 } from "@yume-chan/struct";
3
-
4
- import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js";
5
- import { AdbSyncResponseId, adbSyncReadResponses } from "./response.js";
6
- import type { AdbSyncSocket } from "./socket.js";
7
- import type { AdbSyncStat } from "./stat.js";
8
- import {
9
- AdbSyncLstatResponse,
10
- AdbSyncStatErrorCode,
11
- AdbSyncStatResponse,
12
- } from "./stat.js";
13
-
14
- export interface AdbSyncEntry extends AdbSyncStat {
15
- name: string;
16
- }
17
-
18
- export const AdbSyncEntryResponse = extend(AdbSyncLstatResponse, {
19
- name: string(u32),
20
- });
21
-
22
- export type AdbSyncEntryResponse = StructValue<typeof AdbSyncEntryResponse>;
23
-
24
- export const AdbSyncEntry2Response = extend(AdbSyncStatResponse, {
25
- name: string(u32),
26
- });
27
-
28
- export type AdbSyncEntry2Response = StructValue<typeof AdbSyncEntry2Response>;
29
-
30
- export async function* adbSyncOpenDirV2(
31
- socket: AdbSyncSocket,
32
- path: string,
33
- ): AsyncGenerator<AdbSyncEntry2Response, void, void> {
34
- const locked = await socket.lock();
35
- try {
36
- await adbSyncWriteRequest(locked, AdbSyncRequestId.ListV2, path);
37
- for await (const item of adbSyncReadResponses(
38
- locked,
39
- AdbSyncResponseId.Entry2,
40
- AdbSyncEntry2Response,
41
- )) {
42
- // `LST2` can return error codes for failed `lstat` calls.
43
- // `LIST` just ignores them.
44
- // But they only contain `name` so still pretty useless.
45
- if (item.error !== AdbSyncStatErrorCode.SUCCESS) {
46
- continue;
47
- }
48
- yield item;
49
- }
50
- } finally {
51
- locked.release();
52
- }
53
- }
54
-
55
- export async function* adbSyncOpenDirV1(
56
- socket: AdbSyncSocket,
57
- path: string,
58
- ): AsyncGenerator<AdbSyncEntryResponse, void, void> {
59
- const locked = await socket.lock();
60
- try {
61
- await adbSyncWriteRequest(locked, AdbSyncRequestId.List, path);
62
- for await (const item of adbSyncReadResponses(
63
- locked,
64
- AdbSyncResponseId.Entry,
65
- AdbSyncEntryResponse,
66
- )) {
67
- yield item;
68
- }
69
- } finally {
70
- locked.release();
71
- }
72
- }
73
-
74
- export async function* adbSyncOpenDir(
75
- socket: AdbSyncSocket,
76
- path: string,
77
- v2: boolean,
78
- ): AsyncGenerator<AdbSyncEntry, void, void> {
79
- if (v2) {
80
- yield* adbSyncOpenDirV2(socket, path);
81
- } else {
82
- for await (const item of adbSyncOpenDirV1(socket, path)) {
83
- // Convert to same format as `AdbSyncEntry2Response` for easier consumption.
84
- // However it will add some overhead.
85
- yield {
86
- mode: item.mode,
87
- size: BigInt(item.size),
88
- mtime: BigInt(item.mtime),
89
- get type() {
90
- return item.type;
91
- },
92
- get permission() {
93
- return item.permission;
94
- },
95
- name: item.name,
96
- };
97
- }
98
- }
99
- }
@@ -1,55 +0,0 @@
1
- import { ReadableStream } from "@yume-chan/stream-extra";
2
- import type { StructValue } from "@yume-chan/struct";
3
- import { buffer, struct, u32 } from "@yume-chan/struct";
4
-
5
- import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js";
6
- import { adbSyncReadResponses, AdbSyncResponseId } from "./response.js";
7
- import type { AdbSyncSocket } from "./socket.js";
8
-
9
- export const AdbSyncDataResponse = struct(
10
- { data: buffer(u32) },
11
- { littleEndian: true },
12
- );
13
-
14
- export type AdbSyncDataResponse = StructValue<typeof AdbSyncDataResponse>;
15
-
16
- export async function* adbSyncPullGenerator(
17
- socket: AdbSyncSocket,
18
- path: string,
19
- ): AsyncGenerator<Uint8Array, void, void> {
20
- const locked = await socket.lock();
21
- let done = false;
22
- try {
23
- await adbSyncWriteRequest(locked, AdbSyncRequestId.Receive, path);
24
- for await (const packet of adbSyncReadResponses(
25
- locked,
26
- AdbSyncResponseId.Data,
27
- AdbSyncDataResponse,
28
- )) {
29
- yield packet.data;
30
- }
31
- done = true;
32
- } catch (e) {
33
- done = true;
34
- throw e;
35
- } finally {
36
- if (!done) {
37
- // sync pull can't be cancelled, so we have to read all data
38
- for await (const packet of adbSyncReadResponses(
39
- locked,
40
- AdbSyncResponseId.Data,
41
- AdbSyncDataResponse,
42
- )) {
43
- void packet;
44
- }
45
- }
46
- locked.release();
47
- }
48
- }
49
-
50
- export function adbSyncPull(
51
- socket: AdbSyncSocket,
52
- path: string,
53
- ): ReadableStream<Uint8Array> {
54
- return ReadableStream.from(adbSyncPullGenerator(socket, path));
55
- }
@@ -1,172 +0,0 @@
1
- import type { ReadableStream } from "@yume-chan/stream-extra";
2
- import {
3
- AbortController,
4
- DistributionStream,
5
- MaybeConsumable,
6
- } from "@yume-chan/stream-extra";
7
- import { struct, u32 } from "@yume-chan/struct";
8
-
9
- import { NOOP } from "../../utils/index.js";
10
-
11
- import { AdbSyncRequestId, adbSyncWriteRequest } from "./request.js";
12
- import { AdbSyncResponseId, adbSyncReadResponse } from "./response.js";
13
- import type { AdbSyncSocket, AdbSyncSocketLocked } from "./socket.js";
14
- import { LinuxFileType } from "./stat.js";
15
-
16
- export const ADB_SYNC_MAX_PACKET_SIZE = 64 * 1024;
17
-
18
- export interface AdbSyncPushV1Options {
19
- socket: AdbSyncSocket;
20
- filename: string;
21
- file: ReadableStream<MaybeConsumable<Uint8Array>>;
22
- type?: LinuxFileType;
23
- permission?: number;
24
- mtime?: number;
25
- packetSize?: number;
26
- }
27
-
28
- export const AdbSyncOkResponse = struct(
29
- { unused: u32 },
30
- { littleEndian: true },
31
- );
32
-
33
- async function pipeFileData(
34
- locked: AdbSyncSocketLocked,
35
- file: ReadableStream<MaybeConsumable<Uint8Array>>,
36
- packetSize: number,
37
- mtime: number,
38
- ) {
39
- // Read and write in parallel,
40
- // allow error response to abort the write.
41
- const abortController = new AbortController();
42
- file.pipeThrough(new DistributionStream(packetSize, true))
43
- .pipeTo(
44
- new MaybeConsumable.WritableStream({
45
- write(chunk) {
46
- return adbSyncWriteRequest(
47
- locked,
48
- AdbSyncRequestId.Data,
49
- chunk,
50
- );
51
- },
52
- }),
53
- { signal: abortController.signal },
54
- )
55
- .then(async () => {
56
- await adbSyncWriteRequest(locked, AdbSyncRequestId.Done, mtime);
57
- await locked.flush();
58
- }, NOOP);
59
-
60
- await adbSyncReadResponse(
61
- locked,
62
- AdbSyncResponseId.Ok,
63
- AdbSyncOkResponse,
64
- ).catch((e) => {
65
- abortController.abort();
66
- throw e;
67
- });
68
- }
69
-
70
- export async function adbSyncPushV1({
71
- socket,
72
- filename,
73
- file,
74
- type = LinuxFileType.File,
75
- permission = 0o666,
76
- mtime = (Date.now() / 1000) | 0,
77
- packetSize = ADB_SYNC_MAX_PACKET_SIZE,
78
- }: AdbSyncPushV1Options) {
79
- const locked = await socket.lock();
80
- try {
81
- const mode = (type << 12) | permission;
82
- const pathAndMode = `${filename},${mode.toString()}`;
83
- await adbSyncWriteRequest(locked, AdbSyncRequestId.Send, pathAndMode);
84
- await pipeFileData(locked, file, packetSize, mtime);
85
- } finally {
86
- locked.release();
87
- }
88
- }
89
-
90
- export const AdbSyncSendV2Flags = {
91
- None: 0,
92
- Brotli: 1,
93
- /**
94
- * 2
95
- */
96
- Lz4: 1 << 1,
97
- /**
98
- * 4
99
- */
100
- Zstd: 1 << 2,
101
- DryRun: 0x80000000,
102
- } as const;
103
-
104
- export type AdbSyncSendV2Flags =
105
- (typeof AdbSyncSendV2Flags)[keyof typeof AdbSyncSendV2Flags];
106
-
107
- export interface AdbSyncPushV2Options extends AdbSyncPushV1Options {
108
- /**
109
- * Don't write the file to disk. Requires the `sendrecv_v2` feature.
110
- *
111
- * It was used during ADB development to benchmark the performance of
112
- * compression algorithms.
113
- */
114
- dryRun?: boolean;
115
- }
116
-
117
- export const AdbSyncSendV2Request = struct(
118
- { id: u32, mode: u32, flags: u32<AdbSyncSendV2Flags>() },
119
- { littleEndian: true },
120
- );
121
-
122
- export async function adbSyncPushV2({
123
- socket,
124
- filename,
125
- file,
126
- type = LinuxFileType.File,
127
- permission = 0o666,
128
- mtime = (Date.now() / 1000) | 0,
129
- packetSize = ADB_SYNC_MAX_PACKET_SIZE,
130
- dryRun = false,
131
- }: AdbSyncPushV2Options) {
132
- const locked = await socket.lock();
133
- try {
134
- await adbSyncWriteRequest(locked, AdbSyncRequestId.SendV2, filename);
135
-
136
- const mode = (type << 12) | permission;
137
- let flags: AdbSyncSendV2Flags = AdbSyncSendV2Flags.None;
138
- if (dryRun) {
139
- flags |= AdbSyncSendV2Flags.DryRun;
140
- }
141
- await locked.write(
142
- AdbSyncSendV2Request.serialize({
143
- id: AdbSyncRequestId.SendV2,
144
- mode,
145
- flags,
146
- }),
147
- );
148
-
149
- await pipeFileData(locked, file, packetSize, mtime);
150
- } finally {
151
- locked.release();
152
- }
153
- }
154
-
155
- export interface AdbSyncPushOptions extends AdbSyncPushV2Options {
156
- /**
157
- * Whether to use the v2 protocol. Requires the `sendrecv_v2` feature.
158
- */
159
- v2: boolean;
160
- }
161
-
162
- export function adbSyncPush(options: AdbSyncPushOptions) {
163
- if (options.v2) {
164
- return adbSyncPushV2(options);
165
- }
166
-
167
- if (options.dryRun) {
168
- throw new Error("dryRun is not supported in v1");
169
- }
170
-
171
- return adbSyncPushV1(options);
172
- }
@@ -1,53 +0,0 @@
1
- import { encodeUtf8, struct, u32 } from "@yume-chan/struct";
2
-
3
- import { adbSyncEncodeId } from "./response.js";
4
-
5
- export const AdbSyncRequestId = {
6
- List: adbSyncEncodeId("LIST"),
7
- ListV2: adbSyncEncodeId("LIS2"),
8
- Send: adbSyncEncodeId("SEND"),
9
- SendV2: adbSyncEncodeId("SND2"),
10
- Lstat: adbSyncEncodeId("STAT"),
11
- Stat: adbSyncEncodeId("STA2"),
12
- LstatV2: adbSyncEncodeId("LST2"),
13
- Data: adbSyncEncodeId("DATA"),
14
- Done: adbSyncEncodeId("DONE"),
15
- Receive: adbSyncEncodeId("RECV"),
16
- } as const;
17
-
18
- export const AdbSyncNumberRequest = struct(
19
- { id: u32, arg: u32 },
20
- { littleEndian: true },
21
- );
22
-
23
- export interface AdbSyncWritable {
24
- write(buffer: Uint8Array): Promise<void>;
25
- }
26
-
27
- export async function adbSyncWriteRequest(
28
- writable: AdbSyncWritable,
29
- id: number | string,
30
- value: number | string | Uint8Array,
31
- ): Promise<void> {
32
- if (typeof id === "string") {
33
- id = adbSyncEncodeId(id);
34
- }
35
-
36
- if (typeof value === "number") {
37
- await writable.write(
38
- AdbSyncNumberRequest.serialize({ id, arg: value }),
39
- );
40
- return;
41
- }
42
-
43
- if (typeof value === "string") {
44
- value = encodeUtf8(value);
45
- }
46
-
47
- // `writable` is buffered, it copies inputs to an internal buffer,
48
- // so don't concatenate headers and data here, that will be an unnecessary copy.
49
- await writable.write(
50
- AdbSyncNumberRequest.serialize({ id, arg: value.length }),
51
- );
52
- await writable.write(value);
53
- }
@@ -1,105 +0,0 @@
1
- import { getUint32LittleEndian } from "@yume-chan/no-data-view";
2
- import type { AsyncExactReadable, StructDeserializer } from "@yume-chan/struct";
3
- import { decodeUtf8, string, struct, u32 } from "@yume-chan/struct";
4
-
5
- import { unreachable } from "../../utils/no-op.js";
6
-
7
- function encodeAsciiUnchecked(value: string): Uint8Array<ArrayBuffer> {
8
- const result = new Uint8Array(value.length);
9
- for (let i = 0; i < value.length; i += 1) {
10
- result[i] = value.charCodeAt(i);
11
- }
12
- return result;
13
- }
14
-
15
- /**
16
- * Encode ID to numbers for faster comparison
17
- * @param value A 4-character string
18
- * @returns A 32-bit integer by encoding the string as little-endian
19
- *
20
- * #__NO_SIDE_EFFECTS__
21
- */
22
- export function adbSyncEncodeId(value: string): number {
23
- const buffer = encodeAsciiUnchecked(value);
24
- return getUint32LittleEndian(buffer, 0);
25
- }
26
-
27
- export const AdbSyncResponseId = {
28
- Entry: adbSyncEncodeId("DENT"),
29
- Entry2: adbSyncEncodeId("DNT2"),
30
- Lstat: adbSyncEncodeId("STAT"),
31
- Stat: adbSyncEncodeId("STA2"),
32
- Lstat2: adbSyncEncodeId("LST2"),
33
- Done: adbSyncEncodeId("DONE"),
34
- Data: adbSyncEncodeId("DATA"),
35
- Ok: adbSyncEncodeId("OKAY"),
36
- Fail: adbSyncEncodeId("FAIL"),
37
- };
38
-
39
- export class AdbSyncError extends Error {}
40
-
41
- export const AdbSyncFailResponse = struct(
42
- { message: string(u32) },
43
- {
44
- littleEndian: true,
45
- postDeserialize(value) {
46
- throw new AdbSyncError(value.message);
47
- },
48
- },
49
- );
50
-
51
- export async function adbSyncReadResponse<T>(
52
- stream: AsyncExactReadable,
53
- id: number | string,
54
- type: StructDeserializer<T>,
55
- ): Promise<T> {
56
- if (typeof id === "string") {
57
- id = adbSyncEncodeId(id);
58
- }
59
-
60
- const buffer = await stream.readExactly(4);
61
- switch (getUint32LittleEndian(buffer, 0)) {
62
- case AdbSyncResponseId.Fail:
63
- await AdbSyncFailResponse.deserialize(stream);
64
- throw new Error("Unreachable");
65
- case id:
66
- return await type.deserialize(stream);
67
- default:
68
- throw new Error(
69
- `Expected '${id}', but got '${decodeUtf8(buffer)}'`,
70
- );
71
- }
72
- }
73
-
74
- export async function* adbSyncReadResponses<T>(
75
- stream: AsyncExactReadable,
76
- id: number | string,
77
- type: StructDeserializer<T>,
78
- ): AsyncGenerator<T, void, void> {
79
- if (typeof id === "string") {
80
- id = adbSyncEncodeId(id);
81
- }
82
-
83
- while (true) {
84
- const buffer = await stream.readExactly(4);
85
- switch (getUint32LittleEndian(buffer, 0)) {
86
- case AdbSyncResponseId.Fail:
87
- await AdbSyncFailResponse.deserialize(stream);
88
- unreachable();
89
- case AdbSyncResponseId.Done:
90
- // `DONE` responses' size are always same as the request's normal response.
91
- //
92
- // For example, `DONE` responses for `LIST` requests are 16 bytes (same as `DENT` responses),
93
- // but `DONE` responses for `STAT` requests are 12 bytes (same as `STAT` responses).
94
- await stream.readExactly(type.size);
95
- return;
96
- case id:
97
- yield await type.deserialize(stream);
98
- break;
99
- default:
100
- throw new Error(
101
- `Expected '${id}' or '${AdbSyncResponseId.Done}', but got '${decodeUtf8(buffer)}'`,
102
- );
103
- }
104
- }
105
- }
@@ -1,109 +0,0 @@
1
- import type {
2
- MaybeConsumable,
3
- WritableStreamDefaultWriter,
4
- } from "@yume-chan/stream-extra";
5
- import {
6
- BufferCombiner,
7
- BufferedReadableStream,
8
- Consumable,
9
- } from "@yume-chan/stream-extra";
10
- import type { AsyncExactReadable } from "@yume-chan/struct";
11
-
12
- import type { AdbSocket } from "../../adb.js";
13
- import { AutoResetEvent } from "../../utils/index.js";
14
-
15
- export class AdbSyncSocketLocked implements AsyncExactReadable {
16
- readonly #writer: WritableStreamDefaultWriter<MaybeConsumable<Uint8Array>>;
17
- readonly #readable: BufferedReadableStream;
18
- readonly #socketLock: AutoResetEvent;
19
- readonly #writeLock = new AutoResetEvent();
20
- readonly #combiner: BufferCombiner;
21
-
22
- get position() {
23
- return this.#readable.position;
24
- }
25
-
26
- constructor(
27
- writer: WritableStreamDefaultWriter<MaybeConsumable<Uint8Array>>,
28
- readable: BufferedReadableStream,
29
- bufferSize: number,
30
- lock: AutoResetEvent,
31
- ) {
32
- this.#writer = writer;
33
- this.#readable = readable;
34
- this.#socketLock = lock;
35
- this.#combiner = new BufferCombiner(bufferSize);
36
- }
37
-
38
- #write(buffer: Uint8Array) {
39
- // `#combiner` will reuse the buffer, so we need to use the Consumable pattern
40
- return Consumable.WritableStream.write(this.#writer, buffer);
41
- }
42
-
43
- async flush() {
44
- try {
45
- await this.#writeLock.wait();
46
- const buffer = this.#combiner.flush();
47
- if (buffer) {
48
- await this.#write(buffer);
49
- }
50
- } finally {
51
- this.#writeLock.notifyOne();
52
- }
53
- }
54
-
55
- async write(data: Uint8Array) {
56
- try {
57
- await this.#writeLock.wait();
58
- for (const buffer of this.#combiner.push(data)) {
59
- await this.#write(buffer);
60
- }
61
- } finally {
62
- this.#writeLock.notifyOne();
63
- }
64
- }
65
-
66
- async readExactly(length: number) {
67
- // The request may still be in the internal buffer.
68
- // Call `flush` to send it before starting reading
69
- await this.flush();
70
- return await this.#readable.readExactly(length);
71
- }
72
-
73
- release(): void {
74
- // In theory, the writer shouldn't leave anything in the buffer,
75
- // but to be safe, call `flush` to throw away any remaining data.
76
- this.#combiner.flush();
77
- this.#socketLock.notifyOne();
78
- }
79
-
80
- async close() {
81
- await this.#readable.cancel();
82
- }
83
- }
84
-
85
- export class AdbSyncSocket {
86
- readonly #lock = new AutoResetEvent();
87
- readonly #socket: AdbSocket;
88
- readonly #locked: AdbSyncSocketLocked;
89
-
90
- constructor(socket: AdbSocket, bufferSize: number) {
91
- this.#socket = socket;
92
- this.#locked = new AdbSyncSocketLocked(
93
- socket.writable.getWriter(),
94
- new BufferedReadableStream(socket.readable),
95
- bufferSize,
96
- this.#lock,
97
- );
98
- }
99
-
100
- async lock() {
101
- await this.#lock.wait();
102
- return this.#locked;
103
- }
104
-
105
- async close() {
106
- await this.#locked.close();
107
- await this.#socket.close();
108
- }
109
- }