@yume-chan/adb 0.0.18 → 0.0.20

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 (241) hide show
  1. package/CHANGELOG.json +54 -0
  2. package/CHANGELOG.md +25 -1
  3. package/README.md +220 -103
  4. package/esm/adb.d.ts +43 -60
  5. package/esm/adb.d.ts.map +1 -1
  6. package/esm/adb.js +68 -249
  7. package/esm/adb.js.map +1 -1
  8. package/esm/banner.d.ts +17 -0
  9. package/esm/banner.d.ts.map +1 -0
  10. package/esm/banner.js +67 -0
  11. package/esm/banner.js.map +1 -0
  12. package/esm/commands/base.d.ts +6 -6
  13. package/esm/commands/base.d.ts.map +1 -1
  14. package/esm/commands/base.js +8 -8
  15. package/esm/commands/framebuffer.d.ts +53 -53
  16. package/esm/commands/framebuffer.d.ts.map +1 -1
  17. package/esm/commands/framebuffer.js +46 -46
  18. package/esm/commands/framebuffer.js.map +1 -1
  19. package/esm/commands/index.d.ts +7 -8
  20. package/esm/commands/index.d.ts.map +1 -1
  21. package/esm/commands/index.js +7 -8
  22. package/esm/commands/index.js.map +1 -1
  23. package/esm/commands/power.d.ts +22 -22
  24. package/esm/commands/power.js +48 -48
  25. package/esm/commands/reverse.d.ts +40 -28
  26. package/esm/commands/reverse.d.ts.map +1 -1
  27. package/esm/commands/reverse.js +130 -100
  28. package/esm/commands/reverse.js.map +1 -1
  29. package/esm/commands/subprocess/command.d.ts +57 -51
  30. package/esm/commands/subprocess/command.d.ts.map +1 -1
  31. package/esm/commands/subprocess/command.js +86 -80
  32. package/esm/commands/subprocess/command.js.map +1 -1
  33. package/esm/commands/subprocess/index.d.ts +3 -3
  34. package/esm/commands/subprocess/index.js +3 -3
  35. package/esm/commands/subprocess/protocols/index.d.ts +3 -3
  36. package/esm/commands/subprocess/protocols/index.js +3 -3
  37. package/esm/commands/subprocess/protocols/none.d.ts +30 -35
  38. package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
  39. package/esm/commands/subprocess/protocols/none.js +65 -55
  40. package/esm/commands/subprocess/protocols/none.js.map +1 -1
  41. package/esm/commands/subprocess/protocols/shell.d.ts +33 -38
  42. package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
  43. package/esm/commands/subprocess/protocols/shell.js +172 -162
  44. package/esm/commands/subprocess/protocols/shell.js.map +1 -1
  45. package/esm/commands/subprocess/protocols/types.d.ts +48 -49
  46. package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
  47. package/esm/commands/subprocess/protocols/types.js +1 -1
  48. package/esm/commands/subprocess/utils.d.ts +1 -1
  49. package/esm/commands/subprocess/utils.js +18 -18
  50. package/esm/commands/sync/index.d.ts +8 -7
  51. package/esm/commands/sync/index.d.ts.map +1 -1
  52. package/esm/commands/sync/index.js +8 -7
  53. package/esm/commands/sync/index.js.map +1 -1
  54. package/esm/commands/sync/list.d.ts +42 -40
  55. package/esm/commands/sync/list.d.ts.map +1 -1
  56. package/esm/commands/sync/list.js +67 -47
  57. package/esm/commands/sync/list.js.map +1 -1
  58. package/esm/commands/sync/pull.d.ts +13 -11
  59. package/esm/commands/sync/pull.d.ts.map +1 -1
  60. package/esm/commands/sync/pull.js +35 -37
  61. package/esm/commands/sync/pull.js.map +1 -1
  62. package/esm/commands/sync/push.d.ts +57 -7
  63. package/esm/commands/sync/push.d.ts.map +1 -1
  64. package/esm/commands/sync/push.js +89 -22
  65. package/esm/commands/sync/push.js.map +1 -1
  66. package/esm/commands/sync/request.d.ts +26 -23
  67. package/esm/commands/sync/request.d.ts.map +1 -1
  68. package/esm/commands/sync/request.js +40 -42
  69. package/esm/commands/sync/request.js.map +1 -1
  70. package/esm/commands/sync/response.d.ts +19 -19
  71. package/esm/commands/sync/response.d.ts.map +1 -1
  72. package/esm/commands/sync/response.js +54 -54
  73. package/esm/commands/sync/response.js.map +1 -1
  74. package/esm/commands/sync/socket.d.ts +22 -0
  75. package/esm/commands/sync/socket.d.ts.map +1 -0
  76. package/esm/commands/sync/socket.js +69 -0
  77. package/esm/commands/sync/socket.js.map +1 -0
  78. package/esm/commands/sync/stat.d.ts +72 -72
  79. package/esm/commands/sync/stat.d.ts.map +1 -1
  80. package/esm/commands/sync/stat.js +116 -104
  81. package/esm/commands/sync/stat.js.map +1 -1
  82. package/esm/commands/sync/sync.d.ts +65 -60
  83. package/esm/commands/sync/sync.d.ts.map +1 -1
  84. package/esm/commands/sync/sync.js +123 -149
  85. package/esm/commands/sync/sync.js.map +1 -1
  86. package/esm/commands/tcpip.d.ts +5 -5
  87. package/esm/commands/tcpip.d.ts.map +1 -1
  88. package/esm/commands/tcpip.js +20 -18
  89. package/esm/commands/tcpip.js.map +1 -1
  90. package/esm/{auth.d.ts → daemon/auth.d.ts} +50 -51
  91. package/esm/daemon/auth.d.ts.map +1 -0
  92. package/esm/{auth.js → daemon/auth.js} +95 -96
  93. package/esm/daemon/auth.js.map +1 -0
  94. package/esm/daemon/connection.d.ts +11 -0
  95. package/esm/daemon/connection.d.ts.map +1 -0
  96. package/esm/daemon/connection.js +2 -0
  97. package/esm/daemon/connection.js.map +1 -0
  98. package/esm/{crypto.d.ts → daemon/crypto.d.ts} +36 -36
  99. package/esm/daemon/crypto.d.ts.map +1 -0
  100. package/esm/{crypto.js → daemon/crypto.js} +244 -248
  101. package/esm/daemon/crypto.js.map +1 -0
  102. package/esm/daemon/device.d.ts +9 -0
  103. package/esm/daemon/device.d.ts.map +1 -0
  104. package/esm/daemon/device.js +2 -0
  105. package/esm/daemon/device.js.map +1 -0
  106. package/esm/daemon/dispatcher.d.ts +42 -0
  107. package/esm/daemon/dispatcher.d.ts.map +1 -0
  108. package/esm/{socket → daemon}/dispatcher.js +225 -234
  109. package/esm/daemon/dispatcher.js.map +1 -0
  110. package/esm/daemon/index.d.ts +8 -0
  111. package/esm/daemon/index.d.ts.map +1 -0
  112. package/esm/daemon/index.js +8 -0
  113. package/esm/daemon/index.js.map +1 -0
  114. package/esm/{packet.d.ts → daemon/packet.d.ts} +45 -46
  115. package/esm/daemon/packet.d.ts.map +1 -0
  116. package/esm/{packet.js → daemon/packet.js} +43 -48
  117. package/esm/daemon/packet.js.map +1 -0
  118. package/esm/daemon/socket.d.ts +58 -0
  119. package/esm/daemon/socket.d.ts.map +1 -0
  120. package/esm/{socket → daemon}/socket.js +121 -118
  121. package/esm/daemon/socket.js.map +1 -0
  122. package/esm/daemon/transport.d.ts +45 -0
  123. package/esm/daemon/transport.d.ts.map +1 -0
  124. package/esm/daemon/transport.js +184 -0
  125. package/esm/daemon/transport.js.map +1 -0
  126. package/esm/features.d.ts +10 -7
  127. package/esm/features.d.ts.map +1 -1
  128. package/esm/features.js +13 -10
  129. package/esm/features.js.map +1 -1
  130. package/esm/index.d.ts +7 -9
  131. package/esm/index.d.ts.map +1 -1
  132. package/esm/index.js +7 -9
  133. package/esm/index.js.map +1 -1
  134. package/esm/server/client.d.ts +78 -0
  135. package/esm/server/client.d.ts.map +1 -0
  136. package/esm/server/client.js +329 -0
  137. package/esm/server/client.js.map +1 -0
  138. package/esm/server/index.d.ts +3 -0
  139. package/esm/server/index.d.ts.map +1 -0
  140. package/esm/server/index.js +3 -0
  141. package/esm/server/index.js.map +1 -0
  142. package/esm/server/transport.d.ts +19 -0
  143. package/esm/server/transport.d.ts.map +1 -0
  144. package/esm/server/transport.js +44 -0
  145. package/esm/server/transport.js.map +1 -0
  146. package/esm/utils/auto-reset-event.d.ts +8 -9
  147. package/esm/utils/auto-reset-event.d.ts.map +1 -1
  148. package/esm/utils/auto-reset-event.js +33 -33
  149. package/esm/utils/auto-reset-event.js.map +1 -1
  150. package/esm/utils/base64.d.ts +27 -27
  151. package/esm/utils/base64.js +246 -246
  152. package/esm/utils/base64.js.map +1 -1
  153. package/esm/utils/conditional-variable.d.ts +8 -0
  154. package/esm/utils/conditional-variable.d.ts.map +1 -0
  155. package/esm/utils/conditional-variable.js +34 -0
  156. package/esm/utils/conditional-variable.js.map +1 -0
  157. package/esm/utils/hex.d.ts +3 -0
  158. package/esm/utils/hex.d.ts.map +1 -0
  159. package/esm/utils/hex.js +55 -0
  160. package/esm/utils/hex.js.map +1 -0
  161. package/esm/utils/index.d.ts +6 -3
  162. package/esm/utils/index.d.ts.map +1 -1
  163. package/esm/utils/index.js +6 -3
  164. package/esm/utils/index.js.map +1 -1
  165. package/esm/utils/no-op.d.ts +7 -0
  166. package/esm/utils/no-op.d.ts.map +1 -0
  167. package/esm/utils/no-op.js +12 -0
  168. package/esm/utils/no-op.js.map +1 -0
  169. package/package.json +14 -12
  170. package/src/adb.ts +47 -248
  171. package/src/banner.ts +82 -0
  172. package/src/commands/base.ts +1 -1
  173. package/src/commands/framebuffer.ts +4 -4
  174. package/src/commands/index.ts +7 -8
  175. package/src/commands/power.ts +2 -2
  176. package/src/commands/reverse.ts +90 -70
  177. package/src/commands/subprocess/command.ts +12 -4
  178. package/src/commands/subprocess/index.ts +3 -3
  179. package/src/commands/subprocess/protocols/index.ts +3 -3
  180. package/src/commands/subprocess/protocols/none.ts +36 -23
  181. package/src/commands/subprocess/protocols/shell.ts +94 -74
  182. package/src/commands/subprocess/protocols/types.ts +7 -7
  183. package/src/commands/subprocess/utils.ts +1 -1
  184. package/src/commands/sync/index.ts +8 -7
  185. package/src/commands/sync/list.ts +44 -25
  186. package/src/commands/sync/pull.ts +40 -45
  187. package/src/commands/sync/push.ts +158 -39
  188. package/src/commands/sync/request.ts +21 -16
  189. package/src/commands/sync/response.ts +10 -9
  190. package/src/commands/sync/socket.ts +99 -0
  191. package/src/commands/sync/stat.ts +47 -42
  192. package/src/commands/sync/sync.ts +73 -116
  193. package/src/commands/tcpip.ts +9 -7
  194. package/src/{auth.ts → daemon/auth.ts} +24 -23
  195. package/src/{crypto.ts → daemon/crypto.ts} +25 -33
  196. package/src/daemon/device.ts +14 -0
  197. package/src/{socket → daemon}/dispatcher.ts +95 -117
  198. package/src/daemon/index.ts +7 -0
  199. package/src/daemon/packet.ts +75 -0
  200. package/src/{socket → daemon}/socket.ts +71 -56
  201. package/src/daemon/transport.ts +269 -0
  202. package/src/features.ts +9 -6
  203. package/src/index.ts +3 -5
  204. package/src/server/client.ts +476 -0
  205. package/src/server/index.ts +2 -0
  206. package/src/server/transport.ts +77 -0
  207. package/src/utils/auto-reset-event.ts +14 -15
  208. package/src/utils/conditional-variable.ts +45 -0
  209. package/src/utils/hex.ts +58 -0
  210. package/src/utils/index.ts +6 -3
  211. package/src/utils/no-op.ts +12 -0
  212. package/tsconfig.build.json +12 -1
  213. package/tsconfig.build.tsbuildinfo +1 -1
  214. package/esm/auth.d.ts.map +0 -1
  215. package/esm/auth.js.map +0 -1
  216. package/esm/backend.d.ts +0 -9
  217. package/esm/backend.d.ts.map +0 -1
  218. package/esm/backend.js +0 -2
  219. package/esm/backend.js.map +0 -1
  220. package/esm/commands/install.d.ts +0 -4
  221. package/esm/commands/install.d.ts.map +0 -1
  222. package/esm/commands/install.js +0 -29
  223. package/esm/commands/install.js.map +0 -1
  224. package/esm/crypto.d.ts.map +0 -1
  225. package/esm/crypto.js.map +0 -1
  226. package/esm/packet.d.ts.map +0 -1
  227. package/esm/packet.js.map +0 -1
  228. package/esm/socket/dispatcher.d.ts +0 -60
  229. package/esm/socket/dispatcher.d.ts.map +0 -1
  230. package/esm/socket/dispatcher.js.map +0 -1
  231. package/esm/socket/index.d.ts +0 -3
  232. package/esm/socket/index.d.ts.map +0 -1
  233. package/esm/socket/index.js +0 -3
  234. package/esm/socket/index.js.map +0 -1
  235. package/esm/socket/socket.d.ts +0 -60
  236. package/esm/socket/socket.d.ts.map +0 -1
  237. package/esm/socket/socket.js.map +0 -1
  238. package/src/backend.ts +0 -14
  239. package/src/commands/install.ts +0 -40
  240. package/src/packet.ts +0 -90
  241. package/src/socket/index.ts +0 -2
@@ -1,10 +1,9 @@
1
- import { type Disposable } from "@yume-chan/event";
2
- export declare class AutoResetEvent implements Disposable {
3
- private readonly list;
4
- private blocking;
5
- constructor(initialSet?: boolean);
6
- wait(): Promise<void>;
7
- notify(): void;
8
- dispose(): void;
9
- }
1
+ import type { Disposable } from "@yume-chan/event";
2
+ export declare class AutoResetEvent implements Disposable {
3
+ #private;
4
+ constructor(initialSet?: boolean);
5
+ wait(): Promise<void>;
6
+ notifyOne(): void;
7
+ dispose(): void;
8
+ }
10
9
  //# sourceMappingURL=auto-reset-event.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-reset-event.d.ts","sourceRoot":"","sources":["../../src/utils/auto-reset-event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAa,cAAe,YAAW,UAAU;IAC7C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA+B;IAEpD,OAAO,CAAC,QAAQ,CAAU;gBAEP,UAAU,UAAQ;IAI9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAcrB,MAAM;IAQN,OAAO;CAMjB"}
1
+ {"version":3,"file":"auto-reset-event.d.ts","sourceRoot":"","sources":["../../src/utils/auto-reset-event.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAa,cAAe,YAAW,UAAU;;gBAI1B,UAAU,UAAQ;IAI9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAcrB,SAAS;IAQT,OAAO;CAMjB"}
@@ -1,34 +1,34 @@
1
- import { PromiseResolver } from "@yume-chan/async";
2
- export class AutoResetEvent {
3
- list = [];
4
- blocking;
5
- constructor(initialSet = false) {
6
- this.blocking = initialSet;
7
- }
8
- wait() {
9
- if (!this.blocking) {
10
- this.blocking = true;
11
- if (this.list.length === 0) {
12
- return Promise.resolve();
13
- }
14
- }
15
- const resolver = new PromiseResolver();
16
- this.list.push(resolver);
17
- return resolver.promise;
18
- }
19
- notify() {
20
- if (this.list.length !== 0) {
21
- this.list.pop().resolve();
22
- }
23
- else {
24
- this.blocking = false;
25
- }
26
- }
27
- dispose() {
28
- for (const item of this.list) {
29
- item.reject(new Error("The AutoResetEvent has been disposed"));
30
- }
31
- this.list.length = 0;
32
- }
33
- }
1
+ import { PromiseResolver } from "@yume-chan/async";
2
+ export class AutoResetEvent {
3
+ #set;
4
+ #queue = [];
5
+ constructor(initialSet = false) {
6
+ this.#set = initialSet;
7
+ }
8
+ wait() {
9
+ if (!this.#set) {
10
+ this.#set = true;
11
+ if (this.#queue.length === 0) {
12
+ return Promise.resolve();
13
+ }
14
+ }
15
+ const resolver = new PromiseResolver();
16
+ this.#queue.push(resolver);
17
+ return resolver.promise;
18
+ }
19
+ notifyOne() {
20
+ if (this.#queue.length !== 0) {
21
+ this.#queue.pop().resolve();
22
+ }
23
+ else {
24
+ this.#set = false;
25
+ }
26
+ }
27
+ dispose() {
28
+ for (const item of this.#queue) {
29
+ item.reject(new Error("The AutoResetEvent has been disposed"));
30
+ }
31
+ this.#queue.length = 0;
32
+ }
33
+ }
34
34
  //# sourceMappingURL=auto-reset-event.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-reset-event.js","sourceRoot":"","sources":["../../src/utils/auto-reset-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,MAAM,OAAO,cAAc;IACN,IAAI,GAA4B,EAAE,CAAC;IAE5C,QAAQ,CAAU;IAE1B,YAAmB,UAAU,GAAG,KAAK;QACjC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YAErB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;gBACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;aAC5B;SACJ;QAED,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAQ,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC5B,CAAC;IAEM,MAAM;QACT,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAG,CAAC,OAAO,EAAE,CAAC;SAC9B;aAAM;YACH,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACzB;IACL,CAAC;IAEM,OAAO;QACV,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;SAClE;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACzB,CAAC;CACJ"}
1
+ {"version":3,"file":"auto-reset-event.js","sourceRoot":"","sources":["../../src/utils/auto-reset-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,MAAM,OAAO,cAAc;IACvB,IAAI,CAAU;IACL,MAAM,GAA4B,EAAE,CAAC;IAE9C,YAAmB,UAAU,GAAG,KAAK;QACjC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IAC3B,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YAEjB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC1B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;aAC5B;SACJ;QAED,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAQ,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC5B,CAAC;IAEM,SAAS;QACZ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAG,CAAC,OAAO,EAAE,CAAC;SAChC;aAAM;YACH,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;SACrB;IACL,CAAC;IAEM,OAAO;QACV,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;SAClE;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;CACJ"}
@@ -1,28 +1,28 @@
1
- /**
2
- * Calculate the required length of the output buffer for the given input length.
3
- *
4
- * @param inputLength Length of the input in bytes
5
- * @returns Length of the output in bytes
6
- */
7
- export declare function calculateBase64EncodedLength(inputLength: number): [outputLength: number, paddingLength: number];
8
- /**
9
- * Encode the given input buffer into base64.
10
- *
11
- * @param input The input buffer
12
- * @returns The encoded output buffer
13
- */
14
- export declare function encodeBase64(input: Uint8Array): Uint8Array;
15
- /**
16
- * Encode the given input into base64 and write it to the output buffer.
17
- *
18
- * The output buffer must be at least as long as the value returned by `calculateBase64EncodedLength`.
19
- * It can points to the same buffer as the input, as long as `output.offset <= input.offset - input.length / 3`,
20
- * or `output.offset >= input.offset - 1`
21
- *
22
- * @param input The input buffer
23
- * @param output The output buffer
24
- * @returns The number of bytes written to the output buffer
25
- */
26
- export declare function encodeBase64(input: Uint8Array, output: Uint8Array): number;
27
- export declare function decodeBase64(input: string): Uint8Array;
1
+ /**
2
+ * Calculate the required length of the output buffer for the given input length.
3
+ *
4
+ * @param inputLength Length of the input in bytes
5
+ * @returns Length of the output in bytes
6
+ */
7
+ export declare function calculateBase64EncodedLength(inputLength: number): [outputLength: number, paddingLength: number];
8
+ /**
9
+ * Encode the given input buffer into base64.
10
+ *
11
+ * @param input The input buffer
12
+ * @returns The encoded output buffer
13
+ */
14
+ export declare function encodeBase64(input: Uint8Array): Uint8Array;
15
+ /**
16
+ * Encode the given input into base64 and write it to the output buffer.
17
+ *
18
+ * The output buffer must be at least as long as the value returned by `calculateBase64EncodedLength`.
19
+ * It can points to the same buffer as the input, as long as `output.offset <= input.offset - input.length / 3`,
20
+ * or `output.offset >= input.offset - 1`
21
+ *
22
+ * @param input The input buffer
23
+ * @param output The output buffer
24
+ * @returns The number of bytes written to the output buffer
25
+ */
26
+ export declare function encodeBase64(input: Uint8Array, output: Uint8Array): number;
27
+ export declare function decodeBase64(input: string): Uint8Array;
28
28
  //# sourceMappingURL=base64.d.ts.map
@@ -1,247 +1,247 @@
1
- // Array is faster than object literal or `Map`
2
- const charToIndex = [];
3
- const indexToChar = [];
4
- const paddingChar = "=".charCodeAt(0);
5
- function addRange(start, end) {
6
- const charCodeStart = start.charCodeAt(0);
7
- const charCodeEnd = end.charCodeAt(0);
8
- for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
9
- charToIndex[charCode] = indexToChar.length;
10
- indexToChar.push(charCode);
11
- }
12
- }
13
- addRange("A", "Z");
14
- addRange("a", "z");
15
- addRange("0", "9");
16
- addRange("+", "+");
17
- addRange("/", "/");
18
- /**
19
- * Calculate the required length of the output buffer for the given input length.
20
- *
21
- * @param inputLength Length of the input in bytes
22
- * @returns Length of the output in bytes
23
- */
24
- export function calculateBase64EncodedLength(inputLength) {
25
- const remainder = inputLength % 3;
26
- const paddingLength = remainder !== 0 ? 3 - remainder : 0;
27
- return [((inputLength + paddingLength) / 3) * 4, paddingLength];
28
- }
29
- export function encodeBase64(input, output) {
30
- const [outputLength, paddingLength] = calculateBase64EncodedLength(input.length);
31
- if (!output) {
32
- output = new Uint8Array(outputLength);
33
- encodeForward(input, output, paddingLength);
34
- return output;
35
- }
36
- else {
37
- if (output.length < outputLength) {
38
- throw new Error("output buffer is too small");
39
- }
40
- output = output.subarray(0, outputLength);
41
- // When input and output are on same ArrayBuffer,
42
- // we check if it's possible to encode in-place.
43
- if (input.buffer !== output.buffer) {
44
- encodeForward(input, output, paddingLength);
45
- }
46
- else if (output.byteOffset + output.length - (paddingLength + 1) <=
47
- input.byteOffset + input.length) {
48
- // Output ends before input ends
49
- // So output won't catch up with input.
50
- // Depends on padding length,
51
- // it's possible to write 1-3 bytes after input ends.
52
- // spell: disable-next-line
53
- // | aaaaaabb | | | |
54
- // | aaaaaa | bb0000 | = | = |
55
- //
56
- // spell: disable-next-line
57
- // | aaaaaabb | bbbbcccc | | |
58
- // | aaaaaa | bbbbbb | cccc00 | = |
59
- //
60
- // spell: disable-next-line
61
- // | aaaaaabb | bbbbcccc | ccdddddd | |
62
- // | aaaaaa | bbbbbb | cccccc | dddddd |
63
- // Must encode forwards.
64
- encodeForward(input, output, paddingLength);
65
- }
66
- else if (output.byteOffset >= input.byteOffset - 1) {
67
- // Output starts after input starts
68
- // So in backwards, output can't catch up with input.
69
- // Because first 3 bytes becomes 4 bytes,
70
- // it's possible to write 1 byte before input starts.
71
- // spell: disable-next-line
72
- // | | aaaaaabb | bbbbcccc | ccdddddd |
73
- // | aaaaaa | bbbbbb | cccccc | dddddd |
74
- // Must encode backwards.
75
- encodeBackward(input, output, paddingLength);
76
- }
77
- else {
78
- // Input is in the middle of output,
79
- // not possible to read neither first or last three bytes,
80
- throw new Error("input and output cannot overlap");
81
- }
82
- return outputLength;
83
- }
84
- }
85
- function encodeForward(input, output, paddingLength) {
86
- let inputIndex = 0;
87
- let outputIndex = 0;
88
- while (inputIndex < input.length - 2) {
89
- /* cspell: disable-next-line */
90
- // aaaaaabb
91
- const x = input[inputIndex];
92
- inputIndex += 1;
93
- /* cspell: disable-next-line */
94
- // bbbbcccc
95
- const y = input[inputIndex];
96
- inputIndex += 1;
97
- /* cspell: disable-next-line */
98
- // ccdddddd
99
- const z = input[inputIndex];
100
- inputIndex += 1;
101
- output[outputIndex] = indexToChar[x >> 2];
102
- outputIndex += 1;
103
- output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
104
- outputIndex += 1;
105
- output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
106
- outputIndex += 1;
107
- output[outputIndex] = indexToChar[z & 0b111111];
108
- outputIndex += 1;
109
- }
110
- if (paddingLength === 2) {
111
- /* cspell: disable-next-line */
112
- // aaaaaabb
113
- const x = input[inputIndex];
114
- inputIndex += 1;
115
- output[outputIndex] = indexToChar[x >> 2];
116
- outputIndex += 1;
117
- output[outputIndex] = indexToChar[(x & 0b11) << 4];
118
- outputIndex += 1;
119
- output[outputIndex] = paddingChar;
120
- outputIndex += 1;
121
- output[outputIndex] = paddingChar;
122
- }
123
- else if (paddingLength === 1) {
124
- /* cspell: disable-next-line */
125
- // aaaaaabb
126
- const x = input[inputIndex];
127
- inputIndex += 1;
128
- /* cspell: disable-next-line */
129
- // bbbbcccc
130
- const y = input[inputIndex];
131
- inputIndex += 1;
132
- output[outputIndex] = indexToChar[x >> 2];
133
- outputIndex += 1;
134
- output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
135
- outputIndex += 1;
136
- output[outputIndex] = indexToChar[(y & 0b1111) << 2];
137
- outputIndex += 1;
138
- output[outputIndex] = paddingChar;
139
- }
140
- }
141
- function encodeBackward(input, output, paddingLength) {
142
- let inputIndex = input.length - 1;
143
- let outputIndex = output.length - 1;
144
- if (paddingLength === 2) {
145
- /* cspell: disable-next-line */
146
- // aaaaaabb
147
- const x = input[inputIndex];
148
- inputIndex -= 1;
149
- output[outputIndex] = paddingChar;
150
- outputIndex -= 1;
151
- output[outputIndex] = paddingChar;
152
- outputIndex -= 1;
153
- output[outputIndex] = indexToChar[(x & 0b11) << 4];
154
- outputIndex -= 1;
155
- output[outputIndex] = indexToChar[x >> 2];
156
- outputIndex -= 1;
157
- }
158
- else if (paddingLength === 1) {
159
- /* cspell: disable-next-line */
160
- // bbbbcccc
161
- const y = input[inputIndex];
162
- inputIndex -= 1;
163
- /* cspell: disable-next-line */
164
- // aaaaaabb
165
- const x = input[inputIndex];
166
- inputIndex -= 1;
167
- output[outputIndex] = paddingChar;
168
- outputIndex -= 1;
169
- output[outputIndex] = indexToChar[(y & 0b1111) << 2];
170
- outputIndex -= 1;
171
- output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
172
- outputIndex -= 1;
173
- output[outputIndex] = indexToChar[x >> 2];
174
- outputIndex -= 1;
175
- }
176
- while (inputIndex >= 0) {
177
- /* cspell: disable-next-line */
178
- // ccdddddd
179
- const z = input[inputIndex];
180
- inputIndex -= 1;
181
- /* cspell: disable-next-line */
182
- // bbbbcccc
183
- const y = input[inputIndex];
184
- inputIndex -= 1;
185
- /* cspell: disable-next-line */
186
- // aaaaaabb
187
- const x = input[inputIndex];
188
- inputIndex -= 1;
189
- output[outputIndex] = indexToChar[z & 0b111111];
190
- outputIndex -= 1;
191
- output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
192
- outputIndex -= 1;
193
- output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
194
- outputIndex -= 1;
195
- output[outputIndex] = indexToChar[x >> 2];
196
- outputIndex -= 1;
197
- }
198
- }
199
- export function decodeBase64(input) {
200
- let padding;
201
- if (input[input.length - 2] === "=") {
202
- padding = 2;
203
- }
204
- else if (input[input.length - 1] === "=") {
205
- padding = 1;
206
- }
207
- else {
208
- padding = 0;
209
- }
210
- const result = new Uint8Array((input.length / 4) * 3 - padding);
211
- let sIndex = 0;
212
- let dIndex = 0;
213
- while (sIndex < input.length - (padding !== 0 ? 4 : 0)) {
214
- const a = charToIndex[input.charCodeAt(sIndex)];
215
- sIndex += 1;
216
- const b = charToIndex[input.charCodeAt(sIndex)];
217
- sIndex += 1;
218
- const c = charToIndex[input.charCodeAt(sIndex)];
219
- sIndex += 1;
220
- const d = charToIndex[input.charCodeAt(sIndex)];
221
- sIndex += 1;
222
- result[dIndex] = (a << 2) | ((b & 48) >> 4);
223
- dIndex += 1;
224
- result[dIndex] = ((b & 0b1111) << 4) | ((c & 60) >> 2);
225
- dIndex += 1;
226
- result[dIndex] = ((c & 0b11) << 6) | d;
227
- dIndex += 1;
228
- }
229
- if (padding === 1) {
230
- const a = charToIndex[input.charCodeAt(sIndex)];
231
- sIndex += 1;
232
- const b = charToIndex[input.charCodeAt(sIndex)];
233
- sIndex += 1;
234
- const c = charToIndex[input.charCodeAt(sIndex)];
235
- result[dIndex] = (a << 2) | ((b & 48) >> 4);
236
- dIndex += 1;
237
- result[dIndex] = ((b & 0b1111) << 4) | ((c & 60) >> 2);
238
- }
239
- else if (padding === 2) {
240
- const a = charToIndex[input.charCodeAt(sIndex)];
241
- sIndex += 1;
242
- const b = charToIndex[input.charCodeAt(sIndex)];
243
- result[dIndex] = (a << 2) | ((b & 48) >> 4);
244
- }
245
- return result;
246
- }
1
+ // Array is faster than object literal or `Map`
2
+ const charToIndex = [];
3
+ const indexToChar = [];
4
+ const paddingChar = "=".charCodeAt(0);
5
+ function addRange(start, end) {
6
+ const charCodeStart = start.charCodeAt(0);
7
+ const charCodeEnd = end.charCodeAt(0);
8
+ for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
9
+ charToIndex[charCode] = indexToChar.length;
10
+ indexToChar.push(charCode);
11
+ }
12
+ }
13
+ addRange("A", "Z");
14
+ addRange("a", "z");
15
+ addRange("0", "9");
16
+ addRange("+", "+");
17
+ addRange("/", "/");
18
+ /**
19
+ * Calculate the required length of the output buffer for the given input length.
20
+ *
21
+ * @param inputLength Length of the input in bytes
22
+ * @returns Length of the output in bytes
23
+ */
24
+ export function calculateBase64EncodedLength(inputLength) {
25
+ const remainder = inputLength % 3;
26
+ const paddingLength = remainder !== 0 ? 3 - remainder : 0;
27
+ return [((inputLength + paddingLength) / 3) * 4, paddingLength];
28
+ }
29
+ export function encodeBase64(input, output) {
30
+ const [outputLength, paddingLength] = calculateBase64EncodedLength(input.length);
31
+ if (!output) {
32
+ output = new Uint8Array(outputLength);
33
+ encodeForward(input, output, paddingLength);
34
+ return output;
35
+ }
36
+ else {
37
+ if (output.length < outputLength) {
38
+ throw new Error("output buffer is too small");
39
+ }
40
+ output = output.subarray(0, outputLength);
41
+ // When input and output are on same ArrayBuffer,
42
+ // we check if it's possible to encode in-place.
43
+ if (input.buffer !== output.buffer) {
44
+ encodeForward(input, output, paddingLength);
45
+ }
46
+ else if (output.byteOffset + output.length - (paddingLength + 1) <=
47
+ input.byteOffset + input.length) {
48
+ // Output ends before input ends
49
+ // So output won't catch up with input.
50
+ // Depends on padding length,
51
+ // it's possible to write 1-3 bytes after input ends.
52
+ // spell: disable-next-line
53
+ // | aaaaaabb | | | |
54
+ // | aaaaaa | bb0000 | = | = |
55
+ //
56
+ // spell: disable-next-line
57
+ // | aaaaaabb | bbbbcccc | | |
58
+ // | aaaaaa | bbbbbb | cccc00 | = |
59
+ //
60
+ // spell: disable-next-line
61
+ // | aaaaaabb | bbbbcccc | ccdddddd | |
62
+ // | aaaaaa | bbbbbb | cccccc | dddddd |
63
+ // Must encode forwards.
64
+ encodeForward(input, output, paddingLength);
65
+ }
66
+ else if (output.byteOffset >= input.byteOffset - 1) {
67
+ // Output starts after input starts
68
+ // So in backwards, output can't catch up with input.
69
+ // Because first 3 bytes becomes 4 bytes,
70
+ // it's possible to write 1 byte before input starts.
71
+ // spell: disable-next-line
72
+ // | | aaaaaabb | bbbbcccc | ccdddddd |
73
+ // | aaaaaa | bbbbbb | cccccc | dddddd |
74
+ // Must encode backwards.
75
+ encodeBackward(input, output, paddingLength);
76
+ }
77
+ else {
78
+ // Input is in the middle of output,
79
+ // not possible to read neither first or last three bytes,
80
+ throw new Error("input and output cannot overlap");
81
+ }
82
+ return outputLength;
83
+ }
84
+ }
85
+ function encodeForward(input, output, paddingLength) {
86
+ let inputIndex = 0;
87
+ let outputIndex = 0;
88
+ while (inputIndex < input.length - 2) {
89
+ /* cspell: disable-next-line */
90
+ // aaaaaabb
91
+ const x = input[inputIndex];
92
+ inputIndex += 1;
93
+ /* cspell: disable-next-line */
94
+ // bbbbcccc
95
+ const y = input[inputIndex];
96
+ inputIndex += 1;
97
+ /* cspell: disable-next-line */
98
+ // ccdddddd
99
+ const z = input[inputIndex];
100
+ inputIndex += 1;
101
+ output[outputIndex] = indexToChar[x >> 2];
102
+ outputIndex += 1;
103
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
104
+ outputIndex += 1;
105
+ output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
106
+ outputIndex += 1;
107
+ output[outputIndex] = indexToChar[z & 0b111111];
108
+ outputIndex += 1;
109
+ }
110
+ if (paddingLength === 2) {
111
+ /* cspell: disable-next-line */
112
+ // aaaaaabb
113
+ const x = input[inputIndex];
114
+ inputIndex += 1;
115
+ output[outputIndex] = indexToChar[x >> 2];
116
+ outputIndex += 1;
117
+ output[outputIndex] = indexToChar[(x & 0b11) << 4];
118
+ outputIndex += 1;
119
+ output[outputIndex] = paddingChar;
120
+ outputIndex += 1;
121
+ output[outputIndex] = paddingChar;
122
+ }
123
+ else if (paddingLength === 1) {
124
+ /* cspell: disable-next-line */
125
+ // aaaaaabb
126
+ const x = input[inputIndex];
127
+ inputIndex += 1;
128
+ /* cspell: disable-next-line */
129
+ // bbbbcccc
130
+ const y = input[inputIndex];
131
+ inputIndex += 1;
132
+ output[outputIndex] = indexToChar[x >> 2];
133
+ outputIndex += 1;
134
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
135
+ outputIndex += 1;
136
+ output[outputIndex] = indexToChar[(y & 0b1111) << 2];
137
+ outputIndex += 1;
138
+ output[outputIndex] = paddingChar;
139
+ }
140
+ }
141
+ function encodeBackward(input, output, paddingLength) {
142
+ let inputIndex = input.length - 1;
143
+ let outputIndex = output.length - 1;
144
+ if (paddingLength === 2) {
145
+ /* cspell: disable-next-line */
146
+ // aaaaaabb
147
+ const x = input[inputIndex];
148
+ inputIndex -= 1;
149
+ output[outputIndex] = paddingChar;
150
+ outputIndex -= 1;
151
+ output[outputIndex] = paddingChar;
152
+ outputIndex -= 1;
153
+ output[outputIndex] = indexToChar[(x & 0b11) << 4];
154
+ outputIndex -= 1;
155
+ output[outputIndex] = indexToChar[x >> 2];
156
+ outputIndex -= 1;
157
+ }
158
+ else if (paddingLength === 1) {
159
+ /* cspell: disable-next-line */
160
+ // bbbbcccc
161
+ const y = input[inputIndex];
162
+ inputIndex -= 1;
163
+ /* cspell: disable-next-line */
164
+ // aaaaaabb
165
+ const x = input[inputIndex];
166
+ inputIndex -= 1;
167
+ output[outputIndex] = paddingChar;
168
+ outputIndex -= 1;
169
+ output[outputIndex] = indexToChar[(y & 0b1111) << 2];
170
+ outputIndex -= 1;
171
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
172
+ outputIndex -= 1;
173
+ output[outputIndex] = indexToChar[x >> 2];
174
+ outputIndex -= 1;
175
+ }
176
+ while (inputIndex >= 0) {
177
+ /* cspell: disable-next-line */
178
+ // ccdddddd
179
+ const z = input[inputIndex];
180
+ inputIndex -= 1;
181
+ /* cspell: disable-next-line */
182
+ // bbbbcccc
183
+ const y = input[inputIndex];
184
+ inputIndex -= 1;
185
+ /* cspell: disable-next-line */
186
+ // aaaaaabb
187
+ const x = input[inputIndex];
188
+ inputIndex -= 1;
189
+ output[outputIndex] = indexToChar[z & 0b111111];
190
+ outputIndex -= 1;
191
+ output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)];
192
+ outputIndex -= 1;
193
+ output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)];
194
+ outputIndex -= 1;
195
+ output[outputIndex] = indexToChar[x >> 2];
196
+ outputIndex -= 1;
197
+ }
198
+ }
199
+ export function decodeBase64(input) {
200
+ let padding;
201
+ if (input[input.length - 2] === "=") {
202
+ padding = 2;
203
+ }
204
+ else if (input[input.length - 1] === "=") {
205
+ padding = 1;
206
+ }
207
+ else {
208
+ padding = 0;
209
+ }
210
+ const result = new Uint8Array((input.length / 4) * 3 - padding);
211
+ let sIndex = 0;
212
+ let dIndex = 0;
213
+ while (sIndex < input.length - (padding !== 0 ? 4 : 0)) {
214
+ const a = charToIndex[input.charCodeAt(sIndex)];
215
+ sIndex += 1;
216
+ const b = charToIndex[input.charCodeAt(sIndex)];
217
+ sIndex += 1;
218
+ const c = charToIndex[input.charCodeAt(sIndex)];
219
+ sIndex += 1;
220
+ const d = charToIndex[input.charCodeAt(sIndex)];
221
+ sIndex += 1;
222
+ result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
223
+ dIndex += 1;
224
+ result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2);
225
+ dIndex += 1;
226
+ result[dIndex] = ((c & 0b11) << 6) | d;
227
+ dIndex += 1;
228
+ }
229
+ if (padding === 1) {
230
+ const a = charToIndex[input.charCodeAt(sIndex)];
231
+ sIndex += 1;
232
+ const b = charToIndex[input.charCodeAt(sIndex)];
233
+ sIndex += 1;
234
+ const c = charToIndex[input.charCodeAt(sIndex)];
235
+ result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
236
+ dIndex += 1;
237
+ result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2);
238
+ }
239
+ else if (padding === 2) {
240
+ const a = charToIndex[input.charCodeAt(sIndex)];
241
+ sIndex += 1;
242
+ const b = charToIndex[input.charCodeAt(sIndex)];
243
+ result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4);
244
+ }
245
+ return result;
246
+ }
247
247
  //# sourceMappingURL=base64.js.map