cline 1.0.0-nightly.19 → 1.0.0-nightly.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 (299) hide show
  1. package/bin/cline +0 -0
  2. package/bin/cline-darwin-amd64 +0 -0
  3. package/bin/cline-darwin-arm64 +0 -0
  4. package/bin/cline-host +0 -0
  5. package/bin/cline-host-darwin-amd64 +0 -0
  6. package/bin/cline-host-darwin-arm64 +0 -0
  7. package/bin/cline-host-linux-amd64 +0 -0
  8. package/bin/cline-host-linux-arm64 +0 -0
  9. package/bin/cline-linux-amd64 +0 -0
  10. package/bin/cline-linux-arm64 +0 -0
  11. package/cline-core.js +24841 -16621
  12. package/extension/package.json +12 -4
  13. package/node_modules/b4a/LICENSE +201 -0
  14. package/node_modules/b4a/README.md +153 -0
  15. package/node_modules/b4a/browser.js +563 -0
  16. package/node_modules/b4a/index.js +188 -0
  17. package/node_modules/b4a/lib/ascii.js +31 -0
  18. package/node_modules/b4a/lib/base64.js +65 -0
  19. package/node_modules/b4a/lib/hex.js +51 -0
  20. package/node_modules/b4a/lib/utf16le.js +40 -0
  21. package/node_modules/b4a/lib/utf8.js +141 -0
  22. package/node_modules/b4a/package.json +49 -0
  23. package/node_modules/b4a/react-native.js +5 -0
  24. package/node_modules/bare-events/LICENSE +201 -0
  25. package/node_modules/bare-events/README.md +25 -0
  26. package/node_modules/bare-events/global.d.ts +15 -0
  27. package/node_modules/bare-events/global.js +5 -0
  28. package/node_modules/bare-events/index.d.ts +94 -0
  29. package/node_modules/bare-events/index.js +355 -0
  30. package/node_modules/bare-events/lib/errors.js +32 -0
  31. package/node_modules/bare-events/package.json +61 -0
  32. package/node_modules/bare-events/web.d.ts +79 -0
  33. package/node_modules/bare-events/web.js +347 -0
  34. package/node_modules/bare-fs/CMakeLists.txt +13 -0
  35. package/node_modules/bare-fs/LICENSE +201 -0
  36. package/node_modules/bare-fs/README.md +29 -0
  37. package/node_modules/bare-fs/binding.c +2238 -0
  38. package/node_modules/bare-fs/binding.js +1 -0
  39. package/node_modules/bare-fs/index.d.ts +1115 -0
  40. package/node_modules/bare-fs/index.js +2330 -0
  41. package/node_modules/bare-fs/lib/constants.d.ts +49 -0
  42. package/node_modules/bare-fs/lib/constants.js +49 -0
  43. package/node_modules/bare-fs/lib/errors.d.ts +11 -0
  44. package/node_modules/bare-fs/lib/errors.js +55 -0
  45. package/node_modules/bare-fs/package.json +71 -0
  46. package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
  47. package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
  48. package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
  49. package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
  50. package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
  51. package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
  52. package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
  53. package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
  54. package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
  55. package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
  56. package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
  57. package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
  58. package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
  59. package/node_modules/bare-fs/promises.d.ts +282 -0
  60. package/node_modules/bare-fs/promises.js +90 -0
  61. package/node_modules/bare-os/CMakeLists.txt +13 -0
  62. package/node_modules/bare-os/LICENSE +201 -0
  63. package/node_modules/bare-os/README.md +11 -0
  64. package/node_modules/bare-os/binding.c +1119 -0
  65. package/node_modules/bare-os/binding.js +1 -0
  66. package/node_modules/bare-os/index.d.ts +109 -0
  67. package/node_modules/bare-os/index.js +99 -0
  68. package/node_modules/bare-os/lib/constants.js +6 -0
  69. package/node_modules/bare-os/lib/errors.js +22 -0
  70. package/node_modules/bare-os/package.json +46 -0
  71. package/node_modules/bare-os/prebuilds/android-arm/bare-os.bare +0 -0
  72. package/node_modules/bare-os/prebuilds/android-arm64/bare-os.bare +0 -0
  73. package/node_modules/bare-os/prebuilds/android-ia32/bare-os.bare +0 -0
  74. package/node_modules/bare-os/prebuilds/android-x64/bare-os.bare +0 -0
  75. package/node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare +0 -0
  76. package/node_modules/bare-os/prebuilds/darwin-x64/bare-os.bare +0 -0
  77. package/node_modules/bare-os/prebuilds/ios-arm64/bare-os.bare +0 -0
  78. package/node_modules/bare-os/prebuilds/ios-arm64-simulator/bare-os.bare +0 -0
  79. package/node_modules/bare-os/prebuilds/ios-x64-simulator/bare-os.bare +0 -0
  80. package/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare +0 -0
  81. package/node_modules/bare-os/prebuilds/linux-x64/bare-os.bare +0 -0
  82. package/node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare +0 -0
  83. package/node_modules/bare-os/prebuilds/win32-x64/bare-os.bare +0 -0
  84. package/node_modules/bare-path/LICENSE +201 -0
  85. package/node_modules/bare-path/NOTICE +28 -0
  86. package/node_modules/bare-path/README.md +19 -0
  87. package/node_modules/bare-path/index.js +11 -0
  88. package/node_modules/bare-path/lib/constants.js +11 -0
  89. package/node_modules/bare-path/lib/posix.js +242 -0
  90. package/node_modules/bare-path/lib/shared.js +67 -0
  91. package/node_modules/bare-path/lib/win32.js +513 -0
  92. package/node_modules/bare-path/package.json +36 -0
  93. package/node_modules/bare-stream/LICENSE +201 -0
  94. package/node_modules/bare-stream/README.md +15 -0
  95. package/node_modules/bare-stream/global.js +8 -0
  96. package/node_modules/bare-stream/index.d.ts +237 -0
  97. package/node_modules/bare-stream/index.js +355 -0
  98. package/node_modules/bare-stream/package.json +61 -0
  99. package/node_modules/bare-stream/promises.js +3 -0
  100. package/node_modules/bare-stream/web.d.ts +73 -0
  101. package/node_modules/bare-stream/web.js +229 -0
  102. package/node_modules/bare-url/CMakeLists.txt +27 -0
  103. package/node_modules/bare-url/LICENSE +201 -0
  104. package/node_modules/bare-url/README.md +19 -0
  105. package/node_modules/bare-url/binding.c +188 -0
  106. package/node_modules/bare-url/binding.js +1 -0
  107. package/node_modules/bare-url/global.d.ts +12 -0
  108. package/node_modules/bare-url/global.js +2 -0
  109. package/node_modules/bare-url/index.d.ts +39 -0
  110. package/node_modules/bare-url/index.js +450 -0
  111. package/node_modules/bare-url/lib/errors.d.ts +8 -0
  112. package/node_modules/bare-url/lib/errors.js +38 -0
  113. package/node_modules/bare-url/lib/url-search-params.d.ts +21 -0
  114. package/node_modules/bare-url/lib/url-search-params.js +176 -0
  115. package/node_modules/bare-url/package.json +51 -0
  116. package/node_modules/bare-url/prebuilds/android-arm/bare-url.bare +0 -0
  117. package/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare +0 -0
  118. package/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare +0 -0
  119. package/node_modules/bare-url/prebuilds/android-x64/bare-url.bare +0 -0
  120. package/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare +0 -0
  121. package/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare +0 -0
  122. package/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare +0 -0
  123. package/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
  124. package/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
  125. package/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare +0 -0
  126. package/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare +0 -0
  127. package/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare +0 -0
  128. package/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare +0 -0
  129. package/node_modules/better-sqlite3/deps/download.sh +1 -1
  130. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.c +122 -81
  131. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.h +45 -45
  132. package/node_modules/better-sqlite3/lib/database.js +1 -1
  133. package/node_modules/better-sqlite3/package.json +4 -7
  134. package/node_modules/better-sqlite3/src/addon.cpp +47 -0
  135. package/node_modules/better-sqlite3/src/better_sqlite3.cpp +44 -2164
  136. package/node_modules/better-sqlite3/src/objects/backup.cpp +120 -0
  137. package/node_modules/better-sqlite3/src/objects/backup.hpp +36 -0
  138. package/node_modules/better-sqlite3/src/objects/database.cpp +417 -0
  139. package/node_modules/better-sqlite3/src/objects/database.hpp +103 -0
  140. package/node_modules/better-sqlite3/src/objects/statement-iterator.cpp +113 -0
  141. package/node_modules/better-sqlite3/src/objects/statement-iterator.hpp +50 -0
  142. package/node_modules/better-sqlite3/src/objects/statement.cpp +383 -0
  143. package/node_modules/better-sqlite3/src/objects/statement.hpp +58 -0
  144. package/node_modules/better-sqlite3/src/util/bind-map.cpp +73 -0
  145. package/node_modules/better-sqlite3/src/util/binder.cpp +193 -0
  146. package/node_modules/better-sqlite3/src/util/constants.cpp +172 -0
  147. package/node_modules/better-sqlite3/src/util/custom-aggregate.cpp +121 -0
  148. package/node_modules/better-sqlite3/src/util/custom-function.cpp +59 -0
  149. package/node_modules/better-sqlite3/src/util/custom-table.cpp +409 -0
  150. package/node_modules/better-sqlite3/src/util/data-converter.cpp +17 -0
  151. package/node_modules/better-sqlite3/src/util/data.cpp +194 -0
  152. package/node_modules/better-sqlite3/src/util/helpers.cpp +109 -0
  153. package/node_modules/better-sqlite3/src/util/macros.cpp +63 -0
  154. package/node_modules/better-sqlite3/src/util/query-macros.cpp +71 -0
  155. package/node_modules/better-sqlite3/src/util/row-builder.cpp +49 -0
  156. package/node_modules/events-universal/LICENSE +201 -0
  157. package/node_modules/events-universal/README.md +17 -0
  158. package/node_modules/events-universal/bare.js +1 -0
  159. package/node_modules/events-universal/default.js +1 -0
  160. package/node_modules/events-universal/index.js +1 -0
  161. package/node_modules/events-universal/package.json +39 -0
  162. package/node_modules/events-universal/react-native.js +1 -0
  163. package/node_modules/{fs-constants → fast-fifo}/LICENSE +1 -1
  164. package/node_modules/fast-fifo/README.md +78 -0
  165. package/node_modules/fast-fifo/fixed-size.js +39 -0
  166. package/node_modules/fast-fifo/index.js +48 -0
  167. package/node_modules/fast-fifo/package.json +28 -0
  168. package/node_modules/{base64-js → streamx}/LICENSE +1 -1
  169. package/node_modules/streamx/README.md +489 -0
  170. package/node_modules/streamx/index.js +1184 -0
  171. package/node_modules/streamx/package.json +34 -0
  172. package/node_modules/tar-fs/README.md +23 -34
  173. package/node_modules/tar-fs/index.js +211 -184
  174. package/node_modules/tar-fs/package.json +27 -7
  175. package/node_modules/tar-stream/README.md +34 -19
  176. package/node_modules/tar-stream/constants.js +14 -0
  177. package/node_modules/tar-stream/extract.js +341 -192
  178. package/node_modules/tar-stream/headers.js +201 -175
  179. package/node_modules/tar-stream/pack.js +226 -194
  180. package/node_modules/tar-stream/package.json +23 -46
  181. package/node_modules/text-decoder/LICENSE +201 -0
  182. package/node_modules/text-decoder/README.md +36 -0
  183. package/node_modules/text-decoder/index.js +64 -0
  184. package/node_modules/text-decoder/lib/browser-decoder.js +17 -0
  185. package/node_modules/text-decoder/lib/pass-through-decoder.js +19 -0
  186. package/node_modules/text-decoder/lib/utf8-decoder.js +104 -0
  187. package/node_modules/text-decoder/package.json +38 -0
  188. package/package.json +2 -2
  189. package/proto/cline/account.proto +10 -8
  190. package/proto/cline/browser.proto +3 -1
  191. package/proto/cline/checkpoints.proto +5 -3
  192. package/proto/cline/commands.proto +4 -2
  193. package/proto/cline/common.proto +5 -7
  194. package/proto/cline/dictation.proto +3 -1
  195. package/proto/cline/file.proto +36 -34
  196. package/proto/cline/hooks.proto +3 -2
  197. package/proto/cline/mcp.proto +6 -4
  198. package/proto/cline/models.proto +189 -19
  199. package/proto/cline/oca_account.proto +6 -7
  200. package/proto/cline/slash.proto +3 -1
  201. package/proto/cline/state.proto +147 -292
  202. package/proto/cline/task.proto +4 -2
  203. package/proto/cline/ui.proto +25 -24
  204. package/proto/cline/web.proto +3 -1
  205. package/proto/descriptor_set.pb +0 -0
  206. package/proto/host/diff.proto +5 -4
  207. package/proto/host/env.proto +8 -7
  208. package/proto/host/testing.proto +3 -3
  209. package/proto/host/window.proto +2 -2
  210. package/proto/host/workspace.proto +24 -11
  211. package/node_modules/base64-js/README.md +0 -34
  212. package/node_modules/base64-js/base64js.min.js +0 -1
  213. package/node_modules/base64-js/index.d.ts +0 -3
  214. package/node_modules/base64-js/index.js +0 -150
  215. package/node_modules/base64-js/package.json +0 -47
  216. package/node_modules/better-sqlite3/src/better_sqlite3.hpp +0 -1036
  217. package/node_modules/bl/.travis.yml +0 -17
  218. package/node_modules/bl/BufferList.js +0 -396
  219. package/node_modules/bl/LICENSE.md +0 -13
  220. package/node_modules/bl/README.md +0 -247
  221. package/node_modules/bl/bl.js +0 -84
  222. package/node_modules/bl/package.json +0 -37
  223. package/node_modules/bl/test/convert.js +0 -21
  224. package/node_modules/bl/test/indexOf.js +0 -492
  225. package/node_modules/bl/test/isBufferList.js +0 -32
  226. package/node_modules/bl/test/test.js +0 -869
  227. package/node_modules/buffer/AUTHORS.md +0 -70
  228. package/node_modules/buffer/LICENSE +0 -21
  229. package/node_modules/buffer/README.md +0 -410
  230. package/node_modules/buffer/index.d.ts +0 -186
  231. package/node_modules/buffer/index.js +0 -1817
  232. package/node_modules/buffer/package.json +0 -96
  233. package/node_modules/chownr/LICENSE +0 -15
  234. package/node_modules/chownr/README.md +0 -3
  235. package/node_modules/chownr/chownr.js +0 -167
  236. package/node_modules/chownr/package.json +0 -29
  237. package/node_modules/fs-constants/README.md +0 -26
  238. package/node_modules/fs-constants/browser.js +0 -1
  239. package/node_modules/fs-constants/index.js +0 -1
  240. package/node_modules/fs-constants/package.json +0 -19
  241. package/node_modules/ieee754/LICENSE +0 -11
  242. package/node_modules/ieee754/README.md +0 -51
  243. package/node_modules/ieee754/index.d.ts +0 -10
  244. package/node_modules/ieee754/index.js +0 -85
  245. package/node_modules/ieee754/package.json +0 -52
  246. package/node_modules/inherits/LICENSE +0 -16
  247. package/node_modules/inherits/README.md +0 -42
  248. package/node_modules/inherits/inherits.js +0 -9
  249. package/node_modules/inherits/inherits_browser.js +0 -27
  250. package/node_modules/inherits/package.json +0 -29
  251. package/node_modules/readable-stream/CONTRIBUTING.md +0 -38
  252. package/node_modules/readable-stream/GOVERNANCE.md +0 -136
  253. package/node_modules/readable-stream/LICENSE +0 -47
  254. package/node_modules/readable-stream/README.md +0 -106
  255. package/node_modules/readable-stream/errors-browser.js +0 -127
  256. package/node_modules/readable-stream/errors.js +0 -116
  257. package/node_modules/readable-stream/experimentalWarning.js +0 -17
  258. package/node_modules/readable-stream/lib/_stream_duplex.js +0 -126
  259. package/node_modules/readable-stream/lib/_stream_passthrough.js +0 -37
  260. package/node_modules/readable-stream/lib/_stream_readable.js +0 -1027
  261. package/node_modules/readable-stream/lib/_stream_transform.js +0 -190
  262. package/node_modules/readable-stream/lib/_stream_writable.js +0 -641
  263. package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -180
  264. package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -183
  265. package/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -96
  266. package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -86
  267. package/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
  268. package/node_modules/readable-stream/lib/internal/streams/from.js +0 -52
  269. package/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -86
  270. package/node_modules/readable-stream/lib/internal/streams/state.js +0 -22
  271. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  272. package/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  273. package/node_modules/readable-stream/package.json +0 -68
  274. package/node_modules/readable-stream/readable-browser.js +0 -9
  275. package/node_modules/readable-stream/readable.js +0 -16
  276. package/node_modules/string_decoder/LICENSE +0 -48
  277. package/node_modules/string_decoder/README.md +0 -47
  278. package/node_modules/string_decoder/lib/string_decoder.js +0 -296
  279. package/node_modules/string_decoder/package.json +0 -34
  280. package/node_modules/tar-fs/.travis.yml +0 -6
  281. package/node_modules/tar-fs/test/fixtures/a/hello.txt +0 -1
  282. package/node_modules/tar-fs/test/fixtures/b/a/test.txt +0 -1
  283. package/node_modules/tar-fs/test/fixtures/d/file1 +0 -0
  284. package/node_modules/tar-fs/test/fixtures/d/file2 +0 -0
  285. package/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 +0 -0
  286. package/node_modules/tar-fs/test/fixtures/d/sub-files/file3 +0 -0
  287. package/node_modules/tar-fs/test/fixtures/d/sub-files/file4 +0 -0
  288. package/node_modules/tar-fs/test/fixtures/e/directory/.ignore +0 -0
  289. package/node_modules/tar-fs/test/fixtures/e/file +0 -0
  290. package/node_modules/tar-fs/test/fixtures/invalid.tar +0 -0
  291. package/node_modules/tar-fs/test/index.js +0 -346
  292. package/node_modules/tar-stream/sandbox.js +0 -11
  293. package/node_modules/util-deprecate/History.md +0 -16
  294. package/node_modules/util-deprecate/LICENSE +0 -24
  295. package/node_modules/util-deprecate/README.md +0 -53
  296. package/node_modules/util-deprecate/browser.js +0 -67
  297. package/node_modules/util-deprecate/node.js +0 -6
  298. package/node_modules/util-deprecate/package.json +0 -27
  299. package/test-startup.sh +0 -14
@@ -1,17 +1,163 @@
1
- var alloc = Buffer.alloc
2
-
3
- var ZEROS = '0000000000000000000'
4
- var SEVENS = '7777777777777777777'
5
- var ZERO_OFFSET = '0'.charCodeAt(0)
6
- var USTAR_MAGIC = Buffer.from('ustar\x00', 'binary')
7
- var USTAR_VER = Buffer.from('00', 'binary')
8
- var GNU_MAGIC = Buffer.from('ustar\x20', 'binary')
9
- var GNU_VER = Buffer.from('\x20\x00', 'binary')
10
- var MASK = parseInt('7777', 8)
11
- var MAGIC_OFFSET = 257
12
- var VERSION_OFFSET = 263
13
-
14
- var clamp = function (index, len, defaultValue) {
1
+ const b4a = require('b4a')
2
+
3
+ const ZEROS = '0000000000000000000'
4
+ const SEVENS = '7777777777777777777'
5
+ const ZERO_OFFSET = '0'.charCodeAt(0)
6
+ const USTAR_MAGIC = b4a.from([0x75, 0x73, 0x74, 0x61, 0x72, 0x00]) // ustar\x00
7
+ const USTAR_VER = b4a.from([ZERO_OFFSET, ZERO_OFFSET])
8
+ const GNU_MAGIC = b4a.from([0x75, 0x73, 0x74, 0x61, 0x72, 0x20]) // ustar\x20
9
+ const GNU_VER = b4a.from([0x20, 0x00])
10
+ const MASK = 0o7777
11
+ const MAGIC_OFFSET = 257
12
+ const VERSION_OFFSET = 263
13
+
14
+ exports.decodeLongPath = function decodeLongPath (buf, encoding) {
15
+ return decodeStr(buf, 0, buf.length, encoding)
16
+ }
17
+
18
+ exports.encodePax = function encodePax (opts) { // TODO: encode more stuff in pax
19
+ let result = ''
20
+ if (opts.name) result += addLength(' path=' + opts.name + '\n')
21
+ if (opts.linkname) result += addLength(' linkpath=' + opts.linkname + '\n')
22
+ const pax = opts.pax
23
+ if (pax) {
24
+ for (const key in pax) {
25
+ result += addLength(' ' + key + '=' + pax[key] + '\n')
26
+ }
27
+ }
28
+ return b4a.from(result)
29
+ }
30
+
31
+ exports.decodePax = function decodePax (buf) {
32
+ const result = {}
33
+
34
+ while (buf.length) {
35
+ let i = 0
36
+ while (i < buf.length && buf[i] !== 32) i++
37
+ const len = parseInt(b4a.toString(buf.subarray(0, i)), 10)
38
+ if (!len) return result
39
+
40
+ const b = b4a.toString(buf.subarray(i + 1, len - 1))
41
+ const keyIndex = b.indexOf('=')
42
+ if (keyIndex === -1) return result
43
+ result[b.slice(0, keyIndex)] = b.slice(keyIndex + 1)
44
+
45
+ buf = buf.subarray(len)
46
+ }
47
+
48
+ return result
49
+ }
50
+
51
+ exports.encode = function encode (opts) {
52
+ const buf = b4a.alloc(512)
53
+ let name = opts.name
54
+ let prefix = ''
55
+
56
+ if (opts.typeflag === 5 && name[name.length - 1] !== '/') name += '/'
57
+ if (b4a.byteLength(name) !== name.length) return null // utf-8
58
+
59
+ while (b4a.byteLength(name) > 100) {
60
+ const i = name.indexOf('/')
61
+ if (i === -1) return null
62
+ prefix += prefix ? '/' + name.slice(0, i) : name.slice(0, i)
63
+ name = name.slice(i + 1)
64
+ }
65
+
66
+ if (b4a.byteLength(name) > 100 || b4a.byteLength(prefix) > 155) return null
67
+ if (opts.linkname && b4a.byteLength(opts.linkname) > 100) return null
68
+
69
+ b4a.write(buf, name)
70
+ b4a.write(buf, encodeOct(opts.mode & MASK, 6), 100)
71
+ b4a.write(buf, encodeOct(opts.uid, 6), 108)
72
+ b4a.write(buf, encodeOct(opts.gid, 6), 116)
73
+ encodeSize(opts.size, buf, 124)
74
+ b4a.write(buf, encodeOct((opts.mtime.getTime() / 1000) | 0, 11), 136)
75
+
76
+ buf[156] = ZERO_OFFSET + toTypeflag(opts.type)
77
+
78
+ if (opts.linkname) b4a.write(buf, opts.linkname, 157)
79
+
80
+ b4a.copy(USTAR_MAGIC, buf, MAGIC_OFFSET)
81
+ b4a.copy(USTAR_VER, buf, VERSION_OFFSET)
82
+ if (opts.uname) b4a.write(buf, opts.uname, 265)
83
+ if (opts.gname) b4a.write(buf, opts.gname, 297)
84
+ b4a.write(buf, encodeOct(opts.devmajor || 0, 6), 329)
85
+ b4a.write(buf, encodeOct(opts.devminor || 0, 6), 337)
86
+
87
+ if (prefix) b4a.write(buf, prefix, 345)
88
+
89
+ b4a.write(buf, encodeOct(cksum(buf), 6), 148)
90
+
91
+ return buf
92
+ }
93
+
94
+ exports.decode = function decode (buf, filenameEncoding, allowUnknownFormat) {
95
+ let typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET
96
+
97
+ let name = decodeStr(buf, 0, 100, filenameEncoding)
98
+ const mode = decodeOct(buf, 100, 8)
99
+ const uid = decodeOct(buf, 108, 8)
100
+ const gid = decodeOct(buf, 116, 8)
101
+ const size = decodeOct(buf, 124, 12)
102
+ const mtime = decodeOct(buf, 136, 12)
103
+ const type = toType(typeflag)
104
+ const linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100, filenameEncoding)
105
+ const uname = decodeStr(buf, 265, 32)
106
+ const gname = decodeStr(buf, 297, 32)
107
+ const devmajor = decodeOct(buf, 329, 8)
108
+ const devminor = decodeOct(buf, 337, 8)
109
+
110
+ const c = cksum(buf)
111
+
112
+ // checksum is still initial value if header was null.
113
+ if (c === 8 * 32) return null
114
+
115
+ // valid checksum
116
+ if (c !== decodeOct(buf, 148, 8)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?')
117
+
118
+ if (isUSTAR(buf)) {
119
+ // ustar (posix) format.
120
+ // prepend prefix, if present.
121
+ if (buf[345]) name = decodeStr(buf, 345, 155, filenameEncoding) + '/' + name
122
+ } else if (isGNU(buf)) {
123
+ // 'gnu'/'oldgnu' format. Similar to ustar, but has support for incremental and
124
+ // multi-volume tarballs.
125
+ } else {
126
+ if (!allowUnknownFormat) {
127
+ throw new Error('Invalid tar header: unknown format.')
128
+ }
129
+ }
130
+
131
+ // to support old tar versions that use trailing / to indicate dirs
132
+ if (typeflag === 0 && name && name[name.length - 1] === '/') typeflag = 5
133
+
134
+ return {
135
+ name,
136
+ mode,
137
+ uid,
138
+ gid,
139
+ size,
140
+ mtime: new Date(1000 * mtime),
141
+ type,
142
+ linkname,
143
+ uname,
144
+ gname,
145
+ devmajor,
146
+ devminor,
147
+ pax: null
148
+ }
149
+ }
150
+
151
+ function isUSTAR (buf) {
152
+ return b4a.equals(USTAR_MAGIC, buf.subarray(MAGIC_OFFSET, MAGIC_OFFSET + 6))
153
+ }
154
+
155
+ function isGNU (buf) {
156
+ return b4a.equals(GNU_MAGIC, buf.subarray(MAGIC_OFFSET, MAGIC_OFFSET + 6)) &&
157
+ b4a.equals(GNU_VER, buf.subarray(VERSION_OFFSET, VERSION_OFFSET + 2))
158
+ }
159
+
160
+ function clamp (index, len, defaultValue) {
15
161
  if (typeof index !== 'number') return defaultValue
16
162
  index = ~~index // Coerce to integer.
17
163
  if (index >= len) return len
@@ -21,7 +167,7 @@ var clamp = function (index, len, defaultValue) {
21
167
  return 0
22
168
  }
23
169
 
24
- var toType = function (flag) {
170
+ function toType (flag) {
25
171
  switch (flag) {
26
172
  case 0:
27
173
  return 'file'
@@ -53,7 +199,7 @@ var toType = function (flag) {
53
199
  return null
54
200
  }
55
201
 
56
- var toTypeflag = function (flag) {
202
+ function toTypeflag (flag) {
57
203
  switch (flag) {
58
204
  case 'file':
59
205
  return 0
@@ -78,24 +224,40 @@ var toTypeflag = function (flag) {
78
224
  return 0
79
225
  }
80
226
 
81
- var indexOf = function (block, num, offset, end) {
227
+ function indexOf (block, num, offset, end) {
82
228
  for (; offset < end; offset++) {
83
229
  if (block[offset] === num) return offset
84
230
  }
85
231
  return end
86
232
  }
87
233
 
88
- var cksum = function (block) {
89
- var sum = 8 * 32
90
- for (var i = 0; i < 148; i++) sum += block[i]
91
- for (var j = 156; j < 512; j++) sum += block[j]
234
+ function cksum (block) {
235
+ let sum = 8 * 32
236
+ for (let i = 0; i < 148; i++) sum += block[i]
237
+ for (let j = 156; j < 512; j++) sum += block[j]
92
238
  return sum
93
239
  }
94
240
 
95
- var encodeOct = function (val, n) {
241
+ function encodeOct (val, n) {
96
242
  val = val.toString(8)
97
243
  if (val.length > n) return SEVENS.slice(0, n) + ' '
98
- else return ZEROS.slice(0, n - val.length) + val + ' '
244
+ return ZEROS.slice(0, n - val.length) + val + ' '
245
+ }
246
+
247
+ function encodeSizeBin (num, buf, off) {
248
+ buf[off] = 0x80
249
+ for (let i = 11; i > 0; i--) {
250
+ buf[off + i] = num & 0xff
251
+ num = Math.floor(num / 0x100)
252
+ }
253
+ }
254
+
255
+ function encodeSize (num, buf, off) {
256
+ if (num.toString(8).length > 11) {
257
+ encodeSizeBin(num, buf, off)
258
+ } else {
259
+ b4a.write(buf, encodeOct(num, 11), off)
260
+ }
99
261
  }
100
262
 
101
263
  /* Copied from the node-tar repo and modified to meet
@@ -106,21 +268,22 @@ var encodeOct = function (val, n) {
106
268
  function parse256 (buf) {
107
269
  // first byte MUST be either 80 or FF
108
270
  // 80 for positive, FF for 2's comp
109
- var positive
271
+ let positive
110
272
  if (buf[0] === 0x80) positive = true
111
273
  else if (buf[0] === 0xFF) positive = false
112
274
  else return null
113
275
 
114
276
  // build up a base-256 tuple from the least sig to the highest
115
- var tuple = []
116
- for (var i = buf.length - 1; i > 0; i--) {
117
- var byte = buf[i]
277
+ const tuple = []
278
+ let i
279
+ for (i = buf.length - 1; i > 0; i--) {
280
+ const byte = buf[i]
118
281
  if (positive) tuple.push(byte)
119
282
  else tuple.push(0xFF - byte)
120
283
  }
121
284
 
122
- var sum = 0
123
- var l = tuple.length
285
+ let sum = 0
286
+ const l = tuple.length
124
287
  for (i = 0; i < l; i++) {
125
288
  sum += tuple[i] * Math.pow(256, i)
126
289
  }
@@ -128,8 +291,8 @@ function parse256 (buf) {
128
291
  return positive ? sum : -1 * sum
129
292
  }
130
293
 
131
- var decodeOct = function (val, offset, length) {
132
- val = val.slice(offset, offset + length)
294
+ function decodeOct (val, offset, length) {
295
+ val = val.subarray(offset, offset + length)
133
296
  offset = 0
134
297
 
135
298
  // If prefixed with 0x80 then parse as a base-256 integer
@@ -138,158 +301,21 @@ var decodeOct = function (val, offset, length) {
138
301
  } else {
139
302
  // Older versions of tar can prefix with spaces
140
303
  while (offset < val.length && val[offset] === 32) offset++
141
- var end = clamp(indexOf(val, 32, offset, val.length), val.length, val.length)
304
+ const end = clamp(indexOf(val, 32, offset, val.length), val.length, val.length)
142
305
  while (offset < end && val[offset] === 0) offset++
143
306
  if (end === offset) return 0
144
- return parseInt(val.slice(offset, end).toString(), 8)
307
+ return parseInt(b4a.toString(val.subarray(offset, end)), 8)
145
308
  }
146
309
  }
147
310
 
148
- var decodeStr = function (val, offset, length, encoding) {
149
- return val.slice(offset, indexOf(val, 0, offset, offset + length)).toString(encoding)
311
+ function decodeStr (val, offset, length, encoding) {
312
+ return b4a.toString(val.subarray(offset, indexOf(val, 0, offset, offset + length)), encoding)
150
313
  }
151
314
 
152
- var addLength = function (str) {
153
- var len = Buffer.byteLength(str)
154
- var digits = Math.floor(Math.log(len) / Math.log(10)) + 1
315
+ function addLength (str) {
316
+ const len = b4a.byteLength(str)
317
+ let digits = Math.floor(Math.log(len) / Math.log(10)) + 1
155
318
  if (len + digits >= Math.pow(10, digits)) digits++
156
319
 
157
320
  return (len + digits) + str
158
321
  }
159
-
160
- exports.decodeLongPath = function (buf, encoding) {
161
- return decodeStr(buf, 0, buf.length, encoding)
162
- }
163
-
164
- exports.encodePax = function (opts) { // TODO: encode more stuff in pax
165
- var result = ''
166
- if (opts.name) result += addLength(' path=' + opts.name + '\n')
167
- if (opts.linkname) result += addLength(' linkpath=' + opts.linkname + '\n')
168
- var pax = opts.pax
169
- if (pax) {
170
- for (var key in pax) {
171
- result += addLength(' ' + key + '=' + pax[key] + '\n')
172
- }
173
- }
174
- return Buffer.from(result)
175
- }
176
-
177
- exports.decodePax = function (buf) {
178
- var result = {}
179
-
180
- while (buf.length) {
181
- var i = 0
182
- while (i < buf.length && buf[i] !== 32) i++
183
- var len = parseInt(buf.slice(0, i).toString(), 10)
184
- if (!len) return result
185
-
186
- var b = buf.slice(i + 1, len - 1).toString()
187
- var keyIndex = b.indexOf('=')
188
- if (keyIndex === -1) return result
189
- result[b.slice(0, keyIndex)] = b.slice(keyIndex + 1)
190
-
191
- buf = buf.slice(len)
192
- }
193
-
194
- return result
195
- }
196
-
197
- exports.encode = function (opts) {
198
- var buf = alloc(512)
199
- var name = opts.name
200
- var prefix = ''
201
-
202
- if (opts.typeflag === 5 && name[name.length - 1] !== '/') name += '/'
203
- if (Buffer.byteLength(name) !== name.length) return null // utf-8
204
-
205
- while (Buffer.byteLength(name) > 100) {
206
- var i = name.indexOf('/')
207
- if (i === -1) return null
208
- prefix += prefix ? '/' + name.slice(0, i) : name.slice(0, i)
209
- name = name.slice(i + 1)
210
- }
211
-
212
- if (Buffer.byteLength(name) > 100 || Buffer.byteLength(prefix) > 155) return null
213
- if (opts.linkname && Buffer.byteLength(opts.linkname) > 100) return null
214
-
215
- buf.write(name)
216
- buf.write(encodeOct(opts.mode & MASK, 6), 100)
217
- buf.write(encodeOct(opts.uid, 6), 108)
218
- buf.write(encodeOct(opts.gid, 6), 116)
219
- buf.write(encodeOct(opts.size, 11), 124)
220
- buf.write(encodeOct((opts.mtime.getTime() / 1000) | 0, 11), 136)
221
-
222
- buf[156] = ZERO_OFFSET + toTypeflag(opts.type)
223
-
224
- if (opts.linkname) buf.write(opts.linkname, 157)
225
-
226
- USTAR_MAGIC.copy(buf, MAGIC_OFFSET)
227
- USTAR_VER.copy(buf, VERSION_OFFSET)
228
- if (opts.uname) buf.write(opts.uname, 265)
229
- if (opts.gname) buf.write(opts.gname, 297)
230
- buf.write(encodeOct(opts.devmajor || 0, 6), 329)
231
- buf.write(encodeOct(opts.devminor || 0, 6), 337)
232
-
233
- if (prefix) buf.write(prefix, 345)
234
-
235
- buf.write(encodeOct(cksum(buf), 6), 148)
236
-
237
- return buf
238
- }
239
-
240
- exports.decode = function (buf, filenameEncoding, allowUnknownFormat) {
241
- var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET
242
-
243
- var name = decodeStr(buf, 0, 100, filenameEncoding)
244
- var mode = decodeOct(buf, 100, 8)
245
- var uid = decodeOct(buf, 108, 8)
246
- var gid = decodeOct(buf, 116, 8)
247
- var size = decodeOct(buf, 124, 12)
248
- var mtime = decodeOct(buf, 136, 12)
249
- var type = toType(typeflag)
250
- var linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100, filenameEncoding)
251
- var uname = decodeStr(buf, 265, 32)
252
- var gname = decodeStr(buf, 297, 32)
253
- var devmajor = decodeOct(buf, 329, 8)
254
- var devminor = decodeOct(buf, 337, 8)
255
-
256
- var c = cksum(buf)
257
-
258
- // checksum is still initial value if header was null.
259
- if (c === 8 * 32) return null
260
-
261
- // valid checksum
262
- if (c !== decodeOct(buf, 148, 8)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?')
263
-
264
- if (USTAR_MAGIC.compare(buf, MAGIC_OFFSET, MAGIC_OFFSET + 6) === 0) {
265
- // ustar (posix) format.
266
- // prepend prefix, if present.
267
- if (buf[345]) name = decodeStr(buf, 345, 155, filenameEncoding) + '/' + name
268
- } else if (GNU_MAGIC.compare(buf, MAGIC_OFFSET, MAGIC_OFFSET + 6) === 0 &&
269
- GNU_VER.compare(buf, VERSION_OFFSET, VERSION_OFFSET + 2) === 0) {
270
- // 'gnu'/'oldgnu' format. Similar to ustar, but has support for incremental and
271
- // multi-volume tarballs.
272
- } else {
273
- if (!allowUnknownFormat) {
274
- throw new Error('Invalid tar header: unknown format.')
275
- }
276
- }
277
-
278
- // to support old tar versions that use trailing / to indicate dirs
279
- if (typeflag === 0 && name && name[name.length - 1] === '/') typeflag = 5
280
-
281
- return {
282
- name,
283
- mode,
284
- uid,
285
- gid,
286
- size,
287
- mtime: new Date(1000 * mtime),
288
- type,
289
- linkname,
290
- uname,
291
- gname,
292
- devmajor,
293
- devminor
294
- }
295
- }