tar 7.5.24 → 8.0.1

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 (330) hide show
  1. package/README.md +1712 -1147
  2. package/dist/commonjs/bytes.d.ts +21 -0
  3. package/dist/commonjs/bytes.d.ts.map +1 -0
  4. package/dist/commonjs/bytes.js +83 -0
  5. package/dist/commonjs/bytes.js.map +1 -0
  6. package/dist/commonjs/codec.d.ts +53 -0
  7. package/dist/commonjs/codec.d.ts.map +1 -0
  8. package/dist/commonjs/codec.js +35 -0
  9. package/dist/commonjs/codec.js.map +1 -0
  10. package/dist/commonjs/concat.d.ts +3 -0
  11. package/dist/commonjs/concat.d.ts.map +1 -0
  12. package/dist/commonjs/concat.js +20 -0
  13. package/dist/commonjs/concat.js.map +1 -0
  14. package/dist/commonjs/create.d.ts +39 -2
  15. package/dist/commonjs/create.d.ts.map +1 -1
  16. package/dist/commonjs/create.js +150 -64
  17. package/dist/commonjs/create.js.map +1 -1
  18. package/dist/commonjs/dealias.d.ts +79 -0
  19. package/dist/commonjs/dealias.d.ts.map +1 -0
  20. package/dist/commonjs/dealias.js +50 -0
  21. package/dist/commonjs/dealias.js.map +1 -0
  22. package/dist/commonjs/delete.d.ts +19 -0
  23. package/dist/commonjs/delete.d.ts.map +1 -0
  24. package/dist/commonjs/delete.js +121 -0
  25. package/dist/commonjs/delete.js.map +1 -0
  26. package/dist/commonjs/entries.d.ts +82 -0
  27. package/dist/commonjs/entries.d.ts.map +1 -0
  28. package/dist/commonjs/entries.js +398 -0
  29. package/dist/commonjs/entries.js.map +1 -0
  30. package/dist/commonjs/extract.d.ts +14 -2
  31. package/dist/commonjs/extract.d.ts.map +1 -1
  32. package/dist/commonjs/extract.js +40 -81
  33. package/dist/commonjs/extract.js.map +1 -1
  34. package/dist/commonjs/fs.d.ts +201 -0
  35. package/dist/commonjs/fs.d.ts.map +1 -0
  36. package/dist/commonjs/fs.js +5 -0
  37. package/dist/commonjs/fs.js.map +1 -0
  38. package/dist/commonjs/header.d.ts +4 -4
  39. package/dist/commonjs/header.d.ts.map +1 -1
  40. package/dist/commonjs/header.js +38 -42
  41. package/dist/commonjs/header.js.map +1 -1
  42. package/dist/commonjs/index.d.ts +25 -18
  43. package/dist/commonjs/index.d.ts.map +1 -1
  44. package/dist/commonjs/index.js +46 -18
  45. package/dist/commonjs/index.js.map +1 -1
  46. package/dist/commonjs/index.min.js +2 -3
  47. package/dist/commonjs/index.min.js.map +4 -4
  48. package/dist/commonjs/large-numbers.d.ts +2 -2
  49. package/dist/commonjs/large-numbers.d.ts.map +1 -1
  50. package/dist/commonjs/large-numbers.js +4 -4
  51. package/dist/commonjs/large-numbers.js.map +1 -1
  52. package/dist/commonjs/list.d.ts +23 -6
  53. package/dist/commonjs/list.d.ts.map +1 -1
  54. package/dist/commonjs/list.js +99 -138
  55. package/dist/commonjs/list.js.map +1 -1
  56. package/dist/commonjs/mkdir.d.ts +16 -11
  57. package/dist/commonjs/mkdir.d.ts.map +1 -1
  58. package/dist/commonjs/mkdir.js +121 -159
  59. package/dist/commonjs/mkdir.js.map +1 -1
  60. package/dist/commonjs/options.d.ts +284 -513
  61. package/dist/commonjs/options.d.ts.map +1 -1
  62. package/dist/commonjs/options.js +20 -61
  63. package/dist/commonjs/options.js.map +1 -1
  64. package/dist/commonjs/pack.d.ts +150 -96
  65. package/dist/commonjs/pack.d.ts.map +1 -1
  66. package/dist/commonjs/pack.js +752 -445
  67. package/dist/commonjs/pack.js.map +1 -1
  68. package/dist/commonjs/parser.d.ts +94 -0
  69. package/dist/commonjs/parser.d.ts.map +1 -0
  70. package/dist/commonjs/parser.js +381 -0
  71. package/dist/commonjs/parser.js.map +1 -0
  72. package/dist/commonjs/path-reservations.d.ts +17 -7
  73. package/dist/commonjs/path-reservations.d.ts.map +1 -1
  74. package/dist/commonjs/path-reservations.js +96 -119
  75. package/dist/commonjs/path-reservations.js.map +1 -1
  76. package/dist/commonjs/path.d.ts +19 -0
  77. package/dist/commonjs/path.d.ts.map +1 -0
  78. package/dist/commonjs/path.js +90 -0
  79. package/dist/commonjs/path.js.map +1 -0
  80. package/dist/commonjs/pax.d.ts +3 -1
  81. package/dist/commonjs/pax.d.ts.map +1 -1
  82. package/dist/commonjs/pax.js +53 -43
  83. package/dist/commonjs/pax.js.map +1 -1
  84. package/dist/commonjs/read-entry.d.ts +97 -11
  85. package/dist/commonjs/read-entry.d.ts.map +1 -1
  86. package/dist/commonjs/read-entry.js +248 -97
  87. package/dist/commonjs/read-entry.js.map +1 -1
  88. package/dist/commonjs/read-file.d.ts +22 -0
  89. package/dist/commonjs/read-file.d.ts.map +1 -0
  90. package/dist/commonjs/read-file.js +104 -0
  91. package/dist/commonjs/read-file.js.map +1 -0
  92. package/dist/commonjs/replace.d.ts +45 -1
  93. package/dist/commonjs/replace.d.ts.map +1 -1
  94. package/dist/commonjs/replace.js +165 -211
  95. package/dist/commonjs/replace.js.map +1 -1
  96. package/dist/commonjs/server/codecs.d.ts +38 -0
  97. package/dist/commonjs/server/codecs.d.ts.map +1 -0
  98. package/dist/commonjs/server/codecs.js +252 -0
  99. package/dist/commonjs/server/codecs.js.map +1 -0
  100. package/dist/commonjs/server/index.d.ts +115 -0
  101. package/dist/commonjs/server/index.d.ts.map +1 -0
  102. package/dist/commonjs/server/index.js +166 -0
  103. package/dist/commonjs/server/index.js.map +1 -0
  104. package/dist/commonjs/server/index.min.js +3 -0
  105. package/dist/commonjs/server/index.min.js.map +7 -0
  106. package/dist/commonjs/strip-absolute-path.d.ts +8 -0
  107. package/dist/commonjs/strip-absolute-path.d.ts.map +1 -1
  108. package/dist/commonjs/strip-absolute-path.js +17 -20
  109. package/dist/commonjs/strip-absolute-path.js.map +1 -1
  110. package/dist/commonjs/to-stream.d.ts +7 -0
  111. package/dist/commonjs/to-stream.d.ts.map +1 -0
  112. package/dist/commonjs/to-stream.js +22 -0
  113. package/dist/commonjs/to-stream.js.map +1 -0
  114. package/dist/commonjs/types.d.ts +4 -3
  115. package/dist/commonjs/types.d.ts.map +1 -1
  116. package/dist/commonjs/types.js +4 -3
  117. package/dist/commonjs/types.js.map +1 -1
  118. package/dist/commonjs/unpack.d.ts +143 -89
  119. package/dist/commonjs/unpack.d.ts.map +1 -1
  120. package/dist/commonjs/unpack.js +782 -725
  121. package/dist/commonjs/unpack.js.map +1 -1
  122. package/dist/commonjs/update.d.ts +11 -1
  123. package/dist/commonjs/update.d.ts.map +1 -1
  124. package/dist/commonjs/update.js +37 -28
  125. package/dist/commonjs/update.js.map +1 -1
  126. package/dist/commonjs/warn.d.ts +27 -0
  127. package/dist/commonjs/warn.d.ts.map +1 -0
  128. package/dist/commonjs/warn.js +36 -0
  129. package/dist/commonjs/warn.js.map +1 -0
  130. package/dist/commonjs/win32-path.d.ts +16 -0
  131. package/dist/commonjs/win32-path.d.ts.map +1 -0
  132. package/dist/commonjs/win32-path.js +67 -0
  133. package/dist/commonjs/win32-path.js.map +1 -0
  134. package/dist/commonjs/write-entry.d.ts +64 -111
  135. package/dist/commonjs/write-entry.d.ts.map +1 -1
  136. package/dist/commonjs/write-entry.js +108 -672
  137. package/dist/commonjs/write-entry.js.map +1 -1
  138. package/dist/commonjs/write-flag.d.ts +18 -0
  139. package/dist/commonjs/write-flag.d.ts.map +1 -0
  140. package/dist/commonjs/write-flag.js +29 -0
  141. package/dist/commonjs/write-flag.js.map +1 -0
  142. package/dist/esm/bytes.d.ts +21 -0
  143. package/dist/esm/bytes.d.ts.map +1 -0
  144. package/dist/esm/bytes.js +72 -0
  145. package/dist/esm/bytes.js.map +1 -0
  146. package/dist/esm/codec.d.ts +53 -0
  147. package/dist/esm/codec.d.ts.map +1 -0
  148. package/dist/esm/codec.js +32 -0
  149. package/dist/esm/codec.js.map +1 -0
  150. package/dist/esm/concat.d.ts +3 -0
  151. package/dist/esm/concat.d.ts.map +1 -0
  152. package/dist/esm/concat.js +16 -0
  153. package/dist/esm/concat.js.map +1 -0
  154. package/dist/esm/create.d.ts +39 -2
  155. package/dist/esm/create.d.ts.map +1 -1
  156. package/dist/esm/create.js +144 -61
  157. package/dist/esm/create.js.map +1 -1
  158. package/dist/esm/dealias.d.ts +79 -0
  159. package/dist/esm/dealias.d.ts.map +1 -0
  160. package/dist/esm/dealias.js +46 -0
  161. package/dist/esm/dealias.js.map +1 -0
  162. package/dist/esm/delete.d.ts +19 -0
  163. package/dist/esm/delete.d.ts.map +1 -0
  164. package/dist/esm/delete.js +117 -0
  165. package/dist/esm/delete.js.map +1 -0
  166. package/dist/esm/entries.d.ts +82 -0
  167. package/dist/esm/entries.d.ts.map +1 -0
  168. package/dist/esm/entries.js +388 -0
  169. package/dist/esm/entries.js.map +1 -0
  170. package/dist/esm/extract.d.ts +14 -2
  171. package/dist/esm/extract.d.ts.map +1 -1
  172. package/dist/esm/extract.js +37 -44
  173. package/dist/esm/extract.js.map +1 -1
  174. package/dist/esm/fs.d.ts +201 -0
  175. package/dist/esm/fs.d.ts.map +1 -0
  176. package/dist/esm/fs.js +4 -0
  177. package/dist/esm/fs.js.map +1 -0
  178. package/dist/esm/header.d.ts +4 -4
  179. package/dist/esm/header.d.ts.map +1 -1
  180. package/dist/esm/header.js +38 -42
  181. package/dist/esm/header.js.map +1 -1
  182. package/dist/esm/index.d.ts +25 -18
  183. package/dist/esm/index.d.ts.map +1 -1
  184. package/dist/esm/index.js +23 -18
  185. package/dist/esm/index.js.map +1 -1
  186. package/dist/esm/index.min.js +2 -3
  187. package/dist/esm/index.min.js.map +4 -4
  188. package/dist/esm/large-numbers.d.ts +2 -2
  189. package/dist/esm/large-numbers.d.ts.map +1 -1
  190. package/dist/esm/large-numbers.js +4 -4
  191. package/dist/esm/large-numbers.js.map +1 -1
  192. package/dist/esm/list.d.ts +23 -6
  193. package/dist/esm/list.d.ts.map +1 -1
  194. package/dist/esm/list.js +96 -101
  195. package/dist/esm/list.js.map +1 -1
  196. package/dist/esm/mkdir.d.ts +16 -11
  197. package/dist/esm/mkdir.d.ts.map +1 -1
  198. package/dist/esm/mkdir.js +119 -154
  199. package/dist/esm/mkdir.js.map +1 -1
  200. package/dist/esm/options.d.ts +284 -513
  201. package/dist/esm/options.d.ts.map +1 -1
  202. package/dist/esm/options.js +17 -51
  203. package/dist/esm/options.js.map +1 -1
  204. package/dist/esm/pack.d.ts +150 -96
  205. package/dist/esm/pack.d.ts.map +1 -1
  206. package/dist/esm/pack.js +750 -441
  207. package/dist/esm/pack.js.map +1 -1
  208. package/dist/esm/parser.d.ts +94 -0
  209. package/dist/esm/parser.d.ts.map +1 -0
  210. package/dist/esm/parser.js +377 -0
  211. package/dist/esm/parser.js.map +1 -0
  212. package/dist/esm/path-reservations.d.ts +17 -7
  213. package/dist/esm/path-reservations.d.ts.map +1 -1
  214. package/dist/esm/path-reservations.js +96 -119
  215. package/dist/esm/path-reservations.js.map +1 -1
  216. package/dist/esm/path.d.ts +19 -0
  217. package/dist/esm/path.d.ts.map +1 -0
  218. package/dist/esm/path.js +80 -0
  219. package/dist/esm/path.js.map +1 -0
  220. package/dist/esm/pax.d.ts +3 -1
  221. package/dist/esm/pax.d.ts.map +1 -1
  222. package/dist/esm/pax.js +52 -42
  223. package/dist/esm/pax.js.map +1 -1
  224. package/dist/esm/read-entry.d.ts +97 -11
  225. package/dist/esm/read-entry.d.ts.map +1 -1
  226. package/dist/esm/read-entry.js +245 -96
  227. package/dist/esm/read-entry.js.map +1 -1
  228. package/dist/esm/read-file.d.ts +22 -0
  229. package/dist/esm/read-file.d.ts.map +1 -0
  230. package/dist/esm/read-file.js +99 -0
  231. package/dist/esm/read-file.js.map +1 -0
  232. package/dist/esm/replace.d.ts +45 -1
  233. package/dist/esm/replace.d.ts.map +1 -1
  234. package/dist/esm/replace.js +161 -207
  235. package/dist/esm/replace.js.map +1 -1
  236. package/dist/esm/server/codecs.d.ts +38 -0
  237. package/dist/esm/server/codecs.d.ts.map +1 -0
  238. package/dist/esm/server/codecs.js +214 -0
  239. package/dist/esm/server/codecs.js.map +1 -0
  240. package/dist/esm/server/index.d.ts +115 -0
  241. package/dist/esm/server/index.d.ts.map +1 -0
  242. package/dist/esm/server/index.js +102 -0
  243. package/dist/esm/server/index.js.map +1 -0
  244. package/dist/esm/server/index.min.js +3 -0
  245. package/dist/esm/server/index.min.js.map +7 -0
  246. package/dist/esm/strip-absolute-path.d.ts +8 -0
  247. package/dist/esm/strip-absolute-path.d.ts.map +1 -1
  248. package/dist/esm/strip-absolute-path.js +17 -20
  249. package/dist/esm/strip-absolute-path.js.map +1 -1
  250. package/dist/esm/to-stream.d.ts +7 -0
  251. package/dist/esm/to-stream.d.ts.map +1 -0
  252. package/dist/esm/to-stream.js +18 -0
  253. package/dist/esm/to-stream.js.map +1 -0
  254. package/dist/esm/types.d.ts +4 -3
  255. package/dist/esm/types.d.ts.map +1 -1
  256. package/dist/esm/types.js +4 -3
  257. package/dist/esm/types.js.map +1 -1
  258. package/dist/esm/unpack.d.ts +143 -89
  259. package/dist/esm/unpack.d.ts.map +1 -1
  260. package/dist/esm/unpack.js +778 -719
  261. package/dist/esm/unpack.js.map +1 -1
  262. package/dist/esm/update.d.ts +11 -1
  263. package/dist/esm/update.d.ts.map +1 -1
  264. package/dist/esm/update.js +35 -28
  265. package/dist/esm/update.js.map +1 -1
  266. package/dist/esm/warn.d.ts +27 -0
  267. package/dist/esm/warn.d.ts.map +1 -0
  268. package/dist/esm/warn.js +31 -0
  269. package/dist/esm/warn.js.map +1 -0
  270. package/dist/esm/win32-path.d.ts +16 -0
  271. package/dist/esm/win32-path.d.ts.map +1 -0
  272. package/dist/esm/win32-path.js +60 -0
  273. package/dist/esm/win32-path.js.map +1 -0
  274. package/dist/esm/write-entry.d.ts +64 -111
  275. package/dist/esm/write-entry.d.ts.map +1 -1
  276. package/dist/esm/write-entry.js +107 -633
  277. package/dist/esm/write-entry.js.map +1 -1
  278. package/dist/esm/write-flag.d.ts +18 -0
  279. package/dist/esm/write-flag.d.ts.map +1 -0
  280. package/dist/esm/write-flag.js +25 -0
  281. package/dist/esm/write-flag.js.map +1 -0
  282. package/package.json +68 -224
  283. package/dist/commonjs/get-write-flag.d.ts +0 -2
  284. package/dist/commonjs/get-write-flag.d.ts.map +0 -1
  285. package/dist/commonjs/get-write-flag.js +0 -32
  286. package/dist/commonjs/get-write-flag.js.map +0 -1
  287. package/dist/commonjs/make-command.d.ts +0 -49
  288. package/dist/commonjs/make-command.d.ts.map +0 -1
  289. package/dist/commonjs/make-command.js +0 -52
  290. package/dist/commonjs/make-command.js.map +0 -1
  291. package/dist/commonjs/normalize-windows-path.d.ts +0 -2
  292. package/dist/commonjs/normalize-windows-path.d.ts.map +0 -1
  293. package/dist/commonjs/normalize-windows-path.js +0 -12
  294. package/dist/commonjs/normalize-windows-path.js.map +0 -1
  295. package/dist/commonjs/parse.d.ts +0 -92
  296. package/dist/commonjs/parse.d.ts.map +0 -1
  297. package/dist/commonjs/parse.js +0 -655
  298. package/dist/commonjs/parse.js.map +0 -1
  299. package/dist/commonjs/process-umask.d.ts +0 -2
  300. package/dist/commonjs/process-umask.d.ts.map +0 -1
  301. package/dist/commonjs/process-umask.js +0 -7
  302. package/dist/commonjs/process-umask.js.map +0 -1
  303. package/dist/commonjs/warn-method.d.ts +0 -24
  304. package/dist/commonjs/warn-method.d.ts.map +0 -1
  305. package/dist/commonjs/warn-method.js +0 -31
  306. package/dist/commonjs/warn-method.js.map +0 -1
  307. package/dist/esm/get-write-flag.d.ts +0 -2
  308. package/dist/esm/get-write-flag.d.ts.map +0 -1
  309. package/dist/esm/get-write-flag.js +0 -26
  310. package/dist/esm/get-write-flag.js.map +0 -1
  311. package/dist/esm/make-command.d.ts +0 -49
  312. package/dist/esm/make-command.d.ts.map +0 -1
  313. package/dist/esm/make-command.js +0 -48
  314. package/dist/esm/make-command.js.map +0 -1
  315. package/dist/esm/normalize-windows-path.d.ts +0 -2
  316. package/dist/esm/normalize-windows-path.d.ts.map +0 -1
  317. package/dist/esm/normalize-windows-path.js +0 -9
  318. package/dist/esm/normalize-windows-path.js.map +0 -1
  319. package/dist/esm/parse.d.ts +0 -92
  320. package/dist/esm/parse.d.ts.map +0 -1
  321. package/dist/esm/parse.js +0 -651
  322. package/dist/esm/parse.js.map +0 -1
  323. package/dist/esm/process-umask.d.ts +0 -2
  324. package/dist/esm/process-umask.d.ts.map +0 -1
  325. package/dist/esm/process-umask.js +0 -3
  326. package/dist/esm/process-umask.js.map +0 -1
  327. package/dist/esm/warn-method.d.ts +0 -24
  328. package/dist/esm/warn-method.d.ts.map +0 -1
  329. package/dist/esm/warn-method.js +0 -27
  330. package/dist/esm/warn-method.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/replace.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS;AACT,qDAAkE;AAElE,sDAAwB;AACxB,0DAA4B;AAC5B,2CAAoC;AACpC,uCAAgC;AAChC,uDAA+C;AAE/C,6CAAqC;AACrC,uCAA0C;AAE1C,kDAAkD;AAClD,mEAAmE;AACnE,iEAAiE;AACjE,iBAAiB;AACjB,4CAA4C;AAE5C,MAAM,WAAW,GAAG,CAAC,GAAuB,EAAE,KAAe,EAAE,EAAE;IAC/D,MAAM,CAAC,GAAG,IAAI,kBAAQ,CAAC,GAAG,CAAC,CAAA;IAE3B,IAAI,KAAK,GAAG,IAAI,CAAA;IAChB,IAAI,EAAE,CAAA;IACN,IAAI,QAAQ,CAAA;IAEZ,IAAI,CAAC;QACH,IAAI,CAAC;YACH,EAAE,GAAG,iBAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,IAAK,EAA4B,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACrD,EAAE,GAAG,iBAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAClC,CAAC;iBAAM,CAAC;gBACN,MAAM,EAAE,CAAA;YACV,CAAC;QACH,CAAC;QAED,MAAM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AG,CAAC,IAAI,CAAC,CAAA;QACb,CAAC;IACH,CAAC;IACD,CAAC,CAAC,GAAG,EAAE,CAAA;AACT,CAAC,CAAA;AAEY,QAAA,OAAO,GAAG,IAAA,6BAAW,EAChC,WAAW,EACX,YAAY;AACZ,qBAAqB;AACrB,GAAU,EAAE;IACV,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAA;AACzC,CAAC,EACD,GAAU,EAAE;IACV,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAA;AACzC,CAAC;AACD,oBAAoB;AACpB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;IACf,IAAI,CAAC,IAAA,mBAAM,EAAC,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAA;IACzC,CAAC;IAED,IACE,GAAG,CAAC,IAAI;QACR,GAAG,CAAC,MAAM;QACV,GAAG,CAAC,IAAI;QACR,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QACxB,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EACzB,CAAC;QACD,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAA;IAC7D,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC,CACF,CAAA","sourcesContent":["// tar -r\nimport { WriteStream, WriteStreamSync } from '@isaacs/fs-minipass'\nimport type { Minipass } from 'minipass'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { Header } from './header.js'\nimport { list } from './list.js'\nimport { makeCommand } from './make-command.js'\nimport type { TarOptionsFile, TarOptionsSyncFile } from './options.js'\nimport { isFile } from './options.js'\nimport { Pack, PackSync } from './pack.js'\n\n// starting at the head of the file, read a Header\n// If the checksum is invalid, that's our position to start writing\n// If it is, jump forward by the specified size (round up to 512)\n// and try again.\n// Write the new Pack stream starting there.\n\nconst replaceSync = (opt: TarOptionsSyncFile, files: string[]) => {\n const p = new PackSync(opt)\n\n let threw = true\n let fd\n let position\n\n try {\n try {\n fd = fs.openSync(opt.file, 'r+')\n } catch (er) {\n if ((er as NodeJS.ErrnoException)?.code === 'ENOENT') {\n fd = fs.openSync(opt.file, 'w+')\n } else {\n throw er\n }\n }\n\n const st = fs.fstatSync(fd)\n const headBuf = Buffer.alloc(512)\n\n POSITION: for (position = 0; position < st.size; position += 512) {\n for (let bufPos = 0, bytes = 0; bufPos < 512; bufPos += bytes) {\n bytes = fs.readSync(\n fd,\n headBuf,\n bufPos,\n headBuf.length - bufPos,\n position + bufPos,\n )\n\n if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b) {\n throw new Error('cannot append to compressed archives')\n }\n\n if (!bytes) {\n break POSITION\n }\n }\n\n const h = new Header(headBuf)\n if (!h.cksumValid) {\n break\n }\n const entryBlockSize = 512 * Math.ceil((h.size || 0) / 512)\n if (position + entryBlockSize + 512 > st.size) {\n break\n }\n // the 512 for the header we just parsed will be added as well\n // also jump ahead all the blocks for the body\n position += entryBlockSize\n if (opt.mtimeCache && h.mtime) {\n opt.mtimeCache.set(String(h.path), h.mtime)\n }\n }\n threw = false\n\n streamSync(opt, p, position, fd, files)\n } finally {\n if (threw) {\n try {\n fs.closeSync(fd as number)\n } catch {}\n }\n }\n}\n\nconst streamSync = (\n opt: TarOptionsSyncFile,\n p: Pack,\n position: number,\n fd: number,\n files: string[],\n) => {\n const stream = new WriteStreamSync(opt.file, {\n fd: fd,\n start: position,\n })\n p.pipe(stream as unknown as Minipass.Writable)\n addFilesSync(p, files)\n}\n\nconst replaceAsync = (\n opt: TarOptionsFile,\n files: string[],\n): Promise<void> => {\n files = Array.from(files)\n const p = new Pack(opt)\n\n const getPos = (\n fd: number,\n size: number,\n cb_: (er?: null | Error, pos?: number) => void,\n ) => {\n const cb = (er?: Error | null, pos?: number) => {\n if (er) {\n fs.close(fd, _ => cb_(er))\n } else {\n cb_(null, pos)\n }\n }\n\n let position = 0\n if (size === 0) {\n return cb(null, 0)\n }\n\n let bufPos = 0\n const headBuf = Buffer.alloc(512)\n const onread = (er?: null | Error, bytes?: number): void => {\n if (er || bytes === undefined) {\n return cb(er)\n }\n bufPos += bytes\n if (bufPos < 512 && bytes) {\n return fs.read(\n fd,\n headBuf,\n bufPos,\n headBuf.length - bufPos,\n position + bufPos,\n onread,\n )\n }\n\n if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b) {\n return cb(new Error('cannot append to compressed archives'))\n }\n\n // truncated header\n if (bufPos < 512) {\n return cb(null, position)\n }\n\n const h = new Header(headBuf)\n if (!h.cksumValid) {\n return cb(null, position)\n }\n\n /* c8 ignore next */\n const entryBlockSize = 512 * Math.ceil((h.size ?? 0) / 512)\n if (position + entryBlockSize + 512 > size) {\n return cb(null, position)\n }\n\n position += entryBlockSize + 512\n if (position >= size) {\n return cb(null, position)\n }\n\n if (opt.mtimeCache && h.mtime) {\n opt.mtimeCache.set(String(h.path), h.mtime)\n }\n bufPos = 0\n fs.read(fd, headBuf, 0, 512, position, onread)\n }\n fs.read(fd, headBuf, 0, 512, position, onread)\n }\n\n const promise = new Promise<void>((resolve, reject) => {\n p.on('error', reject)\n let flag = 'r+'\n const onopen = (er?: NodeJS.ErrnoException | null, fd?: number) => {\n if (er && er.code === 'ENOENT' && flag === 'r+') {\n flag = 'w+'\n return fs.open(opt.file, flag, onopen)\n }\n\n if (er || !fd) {\n return reject(er)\n }\n\n fs.fstat(fd, (er, st) => {\n if (er) {\n return fs.close(fd, () => reject(er))\n }\n\n getPos(fd, st.size, (er, position) => {\n if (er) {\n return reject(er)\n }\n const stream = new WriteStream(opt.file, {\n fd: fd,\n start: position,\n })\n p.pipe(stream as unknown as Minipass.Writable)\n stream.on('error', reject)\n stream.on('close', resolve)\n addFilesAsync(p, files)\n })\n })\n }\n fs.open(opt.file, flag, onopen)\n })\n\n return promise\n}\n\nconst addFilesSync = (p: Pack, files: string[]) => {\n files.forEach(file => {\n if (file.charAt(0) === '@') {\n list({\n file: path.resolve(p.cwd, file.slice(1)),\n sync: true,\n noResume: true,\n onReadEntry: entry => p.add(entry),\n })\n } else {\n p.add(file)\n }\n })\n p.end()\n}\n\nconst addFilesAsync = async (p: Pack, files: string[]): Promise<void> => {\n for (const file of files) {\n if (file.charAt(0) === '@') {\n await list({\n file: path.resolve(String(p.cwd), file.slice(1)),\n noResume: true,\n onReadEntry: entry => p.add(entry),\n })\n } else {\n p.add(file)\n }\n }\n p.end()\n}\n\nexport const replace = makeCommand(\n replaceSync,\n replaceAsync,\n /* c8 ignore start */\n (): never => {\n throw new TypeError('file is required')\n },\n (): never => {\n throw new TypeError('file is required')\n },\n /* c8 ignore stop */\n (opt, entries) => {\n if (!isFile(opt)) {\n throw new TypeError('file is required')\n }\n\n if (\n opt.gzip ||\n opt.brotli ||\n opt.zstd ||\n opt.file.endsWith('.br') ||\n opt.file.endsWith('.tbr')\n ) {\n throw new TypeError('cannot append to compressed archives')\n }\n\n if (!entries?.length) {\n throw new TypeError('no paths specified to add/replace')\n }\n },\n)\n"]}
1
+ {"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/replace.ts"],"names":[],"mappings":";;;AAAA,yCAA6C;AAC7C,6CAAwD;AACxD,2CAKoB;AAGpB,2CAAoC;AAEpC,uDAAuD;AACvD,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,CAAA;AACvB,qEAAqE;AACrE,MAAM,IAAI,GAAG,EAAE,CAAA;AACf,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;AAE1E,MAAM,KAAK,GAAG,CACZ,GAAwC,EACxC,KAAgB,EAChB,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;IACpB,IAAI,CAAC,IAAI;QAAE,MAAM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,IAAI,CAAC,CAAA;IAC9B,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,IAAK,EAAwB,EAAE,IAAI,KAAK,QAAQ;YAAE,MAAM,EAAE,CAAA;QAC1D,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,KAAK,CAAC,CAAA;IACjD,CAAC;IACD,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QACjC,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC,CAAA;QAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAAC,CAAC;QACrE,IAAA,2BAAe,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC9C,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAClB,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QACV,MAAM,EAAE,CAAA;IACV,CAAC;IACD,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;AAClB,CAAC,CAAA;AA5BY,QAAA,WAAW,eA4BvB","sourcesContent":["import { gzip, type Codec } from './codec.js'\nimport { dealias, type WithAliases } from './dealias.js'\nimport {\n packFiles,\n packFilesSync,\n writeChunks,\n writeChunksSync,\n} from './create.js'\nimport type { ReplaceOptions, ReplaceOptionsSync } from './options.js'\nimport type { PackInput, PackInputSync } from './pack.js'\nimport { Parser } from './parser.js'\n\n// The most bytes to read from the archive at one time.\nconst CHUNK = 64 * 1024\n// Thrown in the parser to stop at the first block that is not valid.\nconst STOP = {}\nconst noop = () => {}\n\nconst compressed = () => new Error('cannot append to compressed archives')\n\nconst check = (\n opt: ReplaceOptions | ReplaceOptionsSync,\n files: unknown[],\n) => {\n const { file } = opt\n if (!file) throw new TypeError('file is required')\n if (\n opt.gzip ||\n opt.brotli ||\n opt.zstd ||\n file.endsWith('.br') ||\n file.endsWith('.tbr')\n ) {\n throw new TypeError(compressed().message)\n }\n if (!files?.length) {\n throw new TypeError('no paths specified to add/replace')\n }\n}\n\n/**\n * Finds the place in an archive file where new entries go: the end\n * of the last complete entry before the first block that is not a\n * valid header. A PAX or GNU header with no entry after it is not a\n * complete entry.\n *\n * Read the file into `buf` at `pos`, and call `push()`, until it\n * returns false. The bodies of the entries are not read.\n */\nexport class AppendScan {\n buf: Uint8Array = new Uint8Array(CHUNK)\n /** The place in the file of the next read. */\n pos: number = 0\n #size: number\n #parser: Parser\n #codecs: Codec[]\n #mtimes?: Map<string, Date>\n\n /**\n * @param size the size of the file\n * @param mtimes gets the path and the `mtime` of each complete entry\n */\n constructor(\n size: number,\n codecs: Codec[] = [],\n mtimes?: Map<string, Date>,\n ) {\n this.#size = size\n this.#codecs = [...codecs, gzip]\n this.#mtimes = mtimes\n this.#parser = new Parser({\n // The parser must not give the bodies.\n filter: () => false,\n onwarn: (_code, _message, data) => {\n // An error of the header code goes to the caller.\n throw data instanceof Error ? data : STOP\n },\n })\n }\n\n /** The place in the file where new entries go. */\n get position(): number {\n return this.#parser.position\n }\n\n /** The number of bytes to read into `buf` at `pos`. */\n get want(): number {\n return Math.min(CHUNK, this.#size - this.pos)\n }\n\n /**\n * Parse the first `length` bytes of `buf`. False if the place is\n * found. Throws if the file is compressed.\n */\n push(length: number): boolean {\n const chunk = this.buf.subarray(0, length)\n if (this.pos === 0 && this.#codecs.some(c => c.detect(chunk))) {\n throw compressed()\n }\n const parser = this.#parser\n this.pos += length\n // the end of the body of the last entry in the chunk\n let end = 0\n parser.push(chunk)\n try {\n for (let ev; (ev = parser.next()); ) {\n if (ev.type !== 'entry') return false\n const { entry } = ev\n end = parser.offset + 512 * Math.ceil(entry.size / 512)\n if (end > this.#size) return false\n if (entry.mtime) this.#mtimes?.set(entry.path, entry.mtime)\n }\n // The rest of the body of the last entry is not read.\n if (this.pos < end) {\n parser.skipBody()\n this.pos = end\n }\n } catch (er) {\n if (er !== STOP) throw er\n return false\n }\n return length > 0 && this.pos < this.#size\n }\n}\n\n/**\n * Add the files to the end of an archive file that is not\n * compressed. The files are the same as for `create`. If the archive\n * does not exist, it is made.\n *\n * The new entries go after the last complete entry of the archive.\n * A reader of the archive gets the old entry and then the new entry\n * of a path that is in it two times.\n */\nexport const replace = async (\n options: WithAliases<ReplaceOptions>,\n files: PackInput[],\n): Promise<void> => {\n const opt = dealias<ReplaceOptions>(options)\n check(opt, files)\n const { fs, file } = opt\n const pack = packFiles(opt, files)\n if (pack.codec) throw new TypeError(compressed().message)\n const handle = await fs.open(file, 'r+').catch(er => {\n if ((er as { code?: string })?.code !== 'ENOENT') throw er\n return fs.open(file, 'w+', opt.mode || 0o666)\n })\n let ok = false\n try {\n const { size } = await handle.stat()\n const scan = new AppendScan(size, opt.codecs, opt.mtimeCache)\n while (\n scan.push(\n (await handle.read(scan.buf, 0, scan.want, scan.pos)).bytesRead,\n )\n );\n await writeChunks(handle, pack, scan.position)\n ok = true\n } finally {\n const closed = handle.close()\n await (ok ? closed : closed.catch(noop))\n }\n}\n\n/** The sync form of `replace`. */\nexport const replaceSync = (\n options: WithAliases<ReplaceOptionsSync>,\n files: PackInputSync[],\n): void => {\n const opt = dealias<ReplaceOptionsSync>(options)\n check(opt, files)\n const { fs, file } = opt\n const pack = packFilesSync(opt, files)\n if (pack.codec) throw new TypeError(compressed().message)\n let fd: number\n try {\n fd = fs.openSync(file, 'r+')\n } catch (er) {\n if ((er as { code?: string })?.code !== 'ENOENT') throw er\n fd = fs.openSync(file, 'w+', opt.mode || 0o666)\n }\n try {\n const { size } = fs.fstatSync(fd)\n const scan = new AppendScan(size, opt.codecs, opt.mtimeCache)\n while (scan.push(fs.readSync(fd, scan.buf, 0, scan.want, scan.pos)));\n writeChunksSync(fs, fd, pack, scan.position)\n } catch (er) {\n try {\n fs.closeSync(fd)\n } catch {}\n throw er\n }\n fs.closeSync(fd)\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import type { Transform } from 'node:stream';
2
+ import * as nodeZlib from 'node:zlib';
3
+ import type { Codec, CodecStream } from '../codec.js';
4
+ /**
5
+ * The functions of `node:zlib` that the codecs use. A runtime can
6
+ * have no brotli functions or no zstd functions.
7
+ */
8
+ export type ZlibModule = Pick<typeof nodeZlib, 'createGzip' | 'createGunzip' | 'gzipSync' | 'gunzipSync'> & Partial<Pick<typeof nodeZlib, 'createBrotliCompress' | 'createBrotliDecompress' | 'brotliCompressSync' | 'brotliDecompressSync' | 'createZstdCompress' | 'createZstdDecompress' | 'zstdCompressSync' | 'zstdDecompressSync'>>;
9
+ /**
10
+ * Make the two web streams of a `node:zlib` stream, or of another
11
+ * `Transform` stream of `node:stream`. The result fits the
12
+ * `transform` option of `extract`.
13
+ *
14
+ * As with a `TransformStream`, a write is complete only when the
15
+ * reader asks for more output than the stream has. The zlib stream
16
+ * makes output only until its buffer is full. So the reader of an
17
+ * archive can stop before more is decompressed.
18
+ *
19
+ * @param batch put small chunks of input together for one write.
20
+ * Each write is a task for a thread.
21
+ * @param first called with the first chunk of output
22
+ */
23
+ export declare const codecStream: (stream: Transform, batch?: boolean, first?: (chunk: Uint8Array) => void) => CodecStream;
24
+ /**
25
+ * The codecs of a `node:zlib` module: gzip, then brotli and zstd if
26
+ * the module has their functions.
27
+ *
28
+ * The value of a `gzip`, `brotli`, or `zstd` option of `create` goes
29
+ * to the zlib function as its options. A gzip codec reads the tar
30
+ * option `portable` in its options: it makes output that does not
31
+ * name the system.
32
+ *
33
+ * A brotli archive has no magic number. The readers use the brotli
34
+ * codec for a file with a name that ends in `.tar.br` or `.tbr`, if
35
+ * the file does not start with a tar header.
36
+ */
37
+ export declare const zlibCodecs: (z?: ZlibModule) => Codec[];
38
+ //# sourceMappingURL=codecs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../../src/server/codecs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAErD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,OAAO,QAAQ,EACf,YAAY,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAC1D,GACC,OAAO,CACL,IAAI,CACF,OAAO,QAAQ,EACb,sBAAsB,GACtB,wBAAwB,GACxB,oBAAoB,GACpB,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,GACtB,kBAAkB,GAClB,oBAAoB,CACvB,CACF,CAAA;AAQH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,SAAS,EACjB,QAAO,OAAe,EACtB,QAAQ,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,KAClC,WAyGF,CAAA;AAwCD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,IAAG,UAAqB,KAAG,KAAK,EAgF1D,CAAA"}
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.zlibCodecs = exports.codecStream = void 0;
37
+ const node_buffer_1 = require("node:buffer");
38
+ const nodeZlib = __importStar(require("node:zlib"));
39
+ // The size of each chunk of decompressed output, and the size below
40
+ // which chunks of input to compress are put together.
41
+ const CHUNK = 64 * 1024;
42
+ /**
43
+ * Make the two web streams of a `node:zlib` stream, or of another
44
+ * `Transform` stream of `node:stream`. The result fits the
45
+ * `transform` option of `extract`.
46
+ *
47
+ * As with a `TransformStream`, a write is complete only when the
48
+ * reader asks for more output than the stream has. The zlib stream
49
+ * makes output only until its buffer is full. So the reader of an
50
+ * archive can stop before more is decompressed.
51
+ *
52
+ * @param batch put small chunks of input together for one write.
53
+ * Each write is a task for a thread.
54
+ * @param first called with the first chunk of output
55
+ */
56
+ const codecStream = (stream, batch = false, first) => {
57
+ let output;
58
+ let input;
59
+ // True while the reader waits for output.
60
+ let wanted = false;
61
+ // True when the zlib stream is closed.
62
+ let done = false;
63
+ // settles the write or the close that waits for the zlib stream
64
+ let settle;
65
+ // settles the write that waits for the reader
66
+ let wake;
67
+ const held = batch ? new Uint8Array(CHUNK) : undefined;
68
+ let used = 0;
69
+ const write = (chunk) => new Promise(res => {
70
+ settle = res;
71
+ stream.write(chunk, () => res());
72
+ });
73
+ const flush = async (held) => {
74
+ if (used)
75
+ await write(held.subarray(0, used));
76
+ used = 0;
77
+ };
78
+ // A write has no callback when the zlib stream fails or is
79
+ // destroyed.
80
+ const release = () => {
81
+ done = true;
82
+ settle?.();
83
+ wake?.();
84
+ };
85
+ const stop = () => {
86
+ release();
87
+ stream.destroy();
88
+ };
89
+ stream.pause();
90
+ stream.on('data', (chunk) => {
91
+ first?.(chunk);
92
+ first = undefined;
93
+ wanted = false;
94
+ stream.pause();
95
+ output.enqueue(chunk);
96
+ });
97
+ // On Deno, a zlib stream that already has all its output emits
98
+ // 'end' after it is destroyed. The output is then closed already.
99
+ stream.on('end', () => {
100
+ if (!done)
101
+ output.close();
102
+ });
103
+ stream.on('error', er => {
104
+ output.error(er);
105
+ input.error(er);
106
+ release();
107
+ });
108
+ stream.on('close', release);
109
+ return {
110
+ readable: new ReadableStream({
111
+ start: controller => {
112
+ output = controller;
113
+ },
114
+ pull: () => {
115
+ wanted = true;
116
+ wake?.();
117
+ stream.resume();
118
+ },
119
+ cancel: reason => {
120
+ // Stop the source of the input also.
121
+ input.error(reason);
122
+ stop();
123
+ },
124
+ }, { highWaterMark: 0 }),
125
+ writable: new WritableStream({
126
+ start: controller => {
127
+ input = controller;
128
+ // An abort does not wait for a write that waits.
129
+ const { signal } = controller;
130
+ signal.addEventListener('abort', () => {
131
+ output.error(signal.reason);
132
+ stop();
133
+ });
134
+ },
135
+ write: async (chunk) => {
136
+ if (!held)
137
+ await write(chunk);
138
+ else {
139
+ if (used + chunk.length > CHUNK)
140
+ await flush(held);
141
+ if (chunk.length > CHUNK)
142
+ await write(chunk);
143
+ else {
144
+ held.set(chunk, used);
145
+ used += chunk.length;
146
+ }
147
+ }
148
+ // As with a `TransformStream`, the write waits until the
149
+ // reader wants output. Then a pipe from the source does not
150
+ // start a write to a stream that the reader canceled.
151
+ if (!wanted && !done)
152
+ await new Promise(res => (wake = res));
153
+ },
154
+ close: async () => {
155
+ if (held)
156
+ await flush(held);
157
+ await new Promise(res => {
158
+ settle = res;
159
+ stream.end();
160
+ });
161
+ },
162
+ }),
163
+ };
164
+ };
165
+ exports.codecStream = codecStream;
166
+ // The option of the sync functions that limits the output. They
167
+ // refuse a number that is not in the range of a buffer length.
168
+ const limit = (max) => max >= node_buffer_1.constants.MAX_LENGTH ?
169
+ {}
170
+ : { maxOutputLength: Math.max(1, Math.floor(max)) };
171
+ const make = (base, compress, decompress, compressSync, decompressSync) => ({
172
+ ...base,
173
+ decompress: () => (0, exports.codecStream)(decompress({ chunkSize: CHUNK })),
174
+ compress: options => (0, exports.codecStream)(compress(options), true),
175
+ decompressSync: (data, { maxOutputLength }) => {
176
+ try {
177
+ return decompressSync(data, limit(maxOutputLength));
178
+ }
179
+ catch (er) {
180
+ if (er?.code !== 'ERR_BUFFER_TOO_LARGE') {
181
+ throw er;
182
+ }
183
+ throw new Error(`max decompression ratio exceeded: the output is larger than ${maxOutputLength} bytes`);
184
+ }
185
+ },
186
+ compressSync,
187
+ });
188
+ // Byte 9 of a gzip stream names the system that made it. Set it to
189
+ // 255, "unknown", so that each system makes the same bytes.
190
+ const portable = (chunk) => {
191
+ chunk[9] = 255;
192
+ };
193
+ /**
194
+ * The codecs of a `node:zlib` module: gzip, then brotli and zstd if
195
+ * the module has their functions.
196
+ *
197
+ * The value of a `gzip`, `brotli`, or `zstd` option of `create` goes
198
+ * to the zlib function as its options. A gzip codec reads the tar
199
+ * option `portable` in its options: it makes output that does not
200
+ * name the system.
201
+ *
202
+ * A brotli archive has no magic number. The readers use the brotli
203
+ * codec for a file with a name that ends in `.tar.br` or `.tbr`, if
204
+ * the file does not start with a tar header.
205
+ */
206
+ const zlibCodecs = (z = nodeZlib) => {
207
+ const { createBrotliCompress, createBrotliDecompress, brotliCompressSync, brotliDecompressSync, createZstdCompress, createZstdDecompress, zstdCompressSync, zstdDecompressSync, } = z;
208
+ const gzip = make({
209
+ name: 'gzip',
210
+ headLength: 2,
211
+ detect: head => head[0] === 0x1f && head[1] === 0x8b,
212
+ }, z.createGzip, z.createGunzip, z.gzipSync, z.gunzipSync);
213
+ const codecs = [
214
+ {
215
+ ...gzip,
216
+ compress: ({ portable: p, ...options } = {}) => (0, exports.codecStream)(z.createGzip(options), true, p ? portable : undefined),
217
+ compressSync: (data, { portable: p, ...options } = {}) => {
218
+ const out = z.gzipSync(data, options);
219
+ if (p)
220
+ portable(out);
221
+ return out;
222
+ },
223
+ },
224
+ ];
225
+ if (createBrotliCompress &&
226
+ createBrotliDecompress &&
227
+ brotliCompressSync &&
228
+ brotliDecompressSync) {
229
+ codecs.push(make({
230
+ name: 'brotli',
231
+ headLength: 0,
232
+ detect: () => false,
233
+ extensions: ['.tar.br', '.tbr'],
234
+ }, createBrotliCompress, createBrotliDecompress, brotliCompressSync, brotliDecompressSync));
235
+ }
236
+ if (createZstdCompress &&
237
+ createZstdDecompress &&
238
+ zstdCompressSync &&
239
+ zstdDecompressSync) {
240
+ codecs.push(make({
241
+ name: 'zstd',
242
+ headLength: 4,
243
+ detect: head => head[0] === 0x28 &&
244
+ head[1] === 0xb5 &&
245
+ head[2] === 0x2f &&
246
+ head[3] === 0xfd,
247
+ }, createZstdCompress, createZstdDecompress, zstdCompressSync, zstdDecompressSync));
248
+ }
249
+ return codecs;
250
+ };
251
+ exports.zlibCodecs = zlibCodecs;
252
+ //# sourceMappingURL=codecs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codecs.js","sourceRoot":"","sources":["../../../src/server/codecs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAuC;AAEvC,oDAAqC;AA2BrC,oEAAoE;AACpE,sDAAsD;AACtD,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,CAAA;AAEvB;;;;;;;;;;;;;GAaG;AACI,MAAM,WAA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AU,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;SAChC,EACD,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,CACrB,CACF,CAAA;IACH,CAAC;IACD,IACE,kBAAkB;QAClB,oBAAoB;QACpB,gBAAgB;QAChB,kBAAkB,EAClB,CAAC;QACD,MAAM,CAAC,IAAI,CACT,IAAI,CACF;YACE,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,IAAI,CAAC,EAAE,CACb,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;gBAChB,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;gBAChB,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;gBAChB,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;SACnB,EACD,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,CACnB,CACF,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAhFY,QAAA,UAAU,cAgFtB","sourcesContent":["import { constants } from 'node:buffer'\nimport type { Transform } from 'node:stream'\nimport * as nodeZlib from 'node:zlib'\nimport type { Codec, CodecStream } from '../codec.js'\n\n/**\n * The functions of `node:zlib` that the codecs use. A runtime can\n * have no brotli functions or no zstd functions.\n */\nexport type ZlibModule = Pick<\n typeof nodeZlib,\n 'createGzip' | 'createGunzip' | 'gzipSync' | 'gunzipSync'\n> &\n Partial<\n Pick<\n typeof nodeZlib,\n | 'createBrotliCompress'\n | 'createBrotliDecompress'\n | 'brotliCompressSync'\n | 'brotliDecompressSync'\n | 'createZstdCompress'\n | 'createZstdDecompress'\n | 'zstdCompressSync'\n | 'zstdDecompressSync'\n >\n >\n\ntype Options = Record<string, unknown>\n\n// The size of each chunk of decompressed output, and the size below\n// which chunks of input to compress are put together.\nconst CHUNK = 64 * 1024\n\n/**\n * Make the two web streams of a `node:zlib` stream, or of another\n * `Transform` stream of `node:stream`. The result fits the\n * `transform` option of `extract`.\n *\n * As with a `TransformStream`, a write is complete only when the\n * reader asks for more output than the stream has. The zlib stream\n * makes output only until its buffer is full. So the reader of an\n * archive can stop before more is decompressed.\n *\n * @param batch put small chunks of input together for one write.\n * Each write is a task for a thread.\n * @param first called with the first chunk of output\n */\nexport const codecStream = (\n stream: Transform,\n batch: boolean = false,\n first?: (chunk: Uint8Array) => void,\n): CodecStream => {\n let output!: ReadableStreamDefaultController<Uint8Array>\n let input!: WritableStreamDefaultController\n // True while the reader waits for output.\n let wanted = false\n // True when the zlib stream is closed.\n let done = false\n // settles the write or the close that waits for the zlib stream\n let settle: (() => void) | undefined\n // settles the write that waits for the reader\n let wake: (() => void) | undefined\n const held = batch ? new Uint8Array(CHUNK) : undefined\n let used = 0\n const write = (chunk: Uint8Array) =>\n new Promise<void>(res => {\n settle = res\n stream.write(chunk, () => res())\n })\n const flush = async (held: Uint8Array) => {\n if (used) await write(held.subarray(0, used))\n used = 0\n }\n // A write has no callback when the zlib stream fails or is\n // destroyed.\n const release = () => {\n done = true\n settle?.()\n wake?.()\n }\n const stop = () => {\n release()\n stream.destroy()\n }\n stream.pause()\n stream.on('data', (chunk: Uint8Array) => {\n first?.(chunk)\n first = undefined\n wanted = false\n stream.pause()\n output.enqueue(chunk)\n })\n // On Deno, a zlib stream that already has all its output emits\n // 'end' after it is destroyed. The output is then closed already.\n stream.on('end', () => {\n if (!done) output.close()\n })\n stream.on('error', er => {\n output.error(er)\n input.error(er)\n release()\n })\n stream.on('close', release)\n return {\n readable: new ReadableStream<Uint8Array>(\n {\n start: controller => {\n output = controller\n },\n pull: () => {\n wanted = true\n wake?.()\n stream.resume()\n },\n cancel: reason => {\n // Stop the source of the input also.\n input.error(reason)\n stop()\n },\n },\n { highWaterMark: 0 },\n ),\n writable: new WritableStream<Uint8Array>({\n start: controller => {\n input = controller\n // An abort does not wait for a write that waits.\n const { signal } = controller\n signal.addEventListener('abort', () => {\n output.error(signal.reason)\n stop()\n })\n },\n write: async chunk => {\n if (!held) await write(chunk)\n else {\n if (used + chunk.length > CHUNK) await flush(held)\n if (chunk.length > CHUNK) await write(chunk)\n else {\n held.set(chunk, used)\n used += chunk.length\n }\n }\n // As with a `TransformStream`, the write waits until the\n // reader wants output. Then a pipe from the source does not\n // start a write to a stream that the reader canceled.\n if (!wanted && !done) await new Promise<void>(res => (wake = res))\n },\n close: async () => {\n if (held) await flush(held)\n await new Promise<void>(res => {\n settle = res\n stream.end()\n })\n },\n }),\n }\n}\n\n// The option of the sync functions that limits the output. They\n// refuse a number that is not in the range of a buffer length.\nconst limit = (max: number) =>\n max >= constants.MAX_LENGTH ?\n {}\n : { maxOutputLength: Math.max(1, Math.floor(max)) }\n\nconst make = (\n base: Pick<Codec, 'name' | 'headLength' | 'detect' | 'extensions'>,\n compress: (options?: Options) => Transform,\n decompress: (options: Options) => Transform,\n compressSync: (data: Uint8Array, options?: Options) => Uint8Array,\n decompressSync: (data: Uint8Array, options: Options) => Uint8Array,\n): Codec => ({\n ...base,\n decompress: () => codecStream(decompress({ chunkSize: CHUNK })),\n compress: options => codecStream(compress(options), true),\n decompressSync: (data, { maxOutputLength }) => {\n try {\n return decompressSync(data, limit(maxOutputLength))\n } catch (er) {\n if ((er as { code?: string })?.code !== 'ERR_BUFFER_TOO_LARGE') {\n throw er\n }\n throw new Error(\n `max decompression ratio exceeded: the output is larger than ${maxOutputLength} bytes`,\n )\n }\n },\n compressSync,\n})\n\n// Byte 9 of a gzip stream names the system that made it. Set it to\n// 255, \"unknown\", so that each system makes the same bytes.\nconst portable = (chunk: Uint8Array) => {\n chunk[9] = 255\n}\n\n/**\n * The codecs of a `node:zlib` module: gzip, then brotli and zstd if\n * the module has their functions.\n *\n * The value of a `gzip`, `brotli`, or `zstd` option of `create` goes\n * to the zlib function as its options. A gzip codec reads the tar\n * option `portable` in its options: it makes output that does not\n * name the system.\n *\n * A brotli archive has no magic number. The readers use the brotli\n * codec for a file with a name that ends in `.tar.br` or `.tbr`, if\n * the file does not start with a tar header.\n */\nexport const zlibCodecs = (z: ZlibModule = nodeZlib): Codec[] => {\n const {\n createBrotliCompress,\n createBrotliDecompress,\n brotliCompressSync,\n brotliDecompressSync,\n createZstdCompress,\n createZstdDecompress,\n zstdCompressSync,\n zstdDecompressSync,\n } = z\n const gzip = make(\n {\n name: 'gzip',\n headLength: 2,\n detect: head => head[0] === 0x1f && head[1] === 0x8b,\n },\n z.createGzip,\n z.createGunzip,\n z.gzipSync,\n z.gunzipSync,\n )\n const codecs: Codec[] = [\n {\n ...gzip,\n compress: ({ portable: p, ...options }: Options = {}) =>\n codecStream(z.createGzip(options), true, p ? portable : undefined),\n compressSync: (data, { portable: p, ...options }: Options = {}) => {\n const out = z.gzipSync(data, options)\n if (p) portable(out)\n return out\n },\n },\n ]\n if (\n createBrotliCompress &&\n createBrotliDecompress &&\n brotliCompressSync &&\n brotliDecompressSync\n ) {\n codecs.push(\n make(\n {\n name: 'brotli',\n headLength: 0,\n detect: () => false,\n extensions: ['.tar.br', '.tbr'],\n },\n createBrotliCompress,\n createBrotliDecompress,\n brotliCompressSync,\n brotliDecompressSync,\n ),\n )\n }\n if (\n createZstdCompress &&\n createZstdDecompress &&\n zstdCompressSync &&\n zstdDecompressSync\n ) {\n codecs.push(\n make(\n {\n name: 'zstd',\n headLength: 4,\n detect: head =>\n head[0] === 0x28 &&\n head[1] === 0xb5 &&\n head[2] === 0x2f &&\n head[3] === 0xfd,\n },\n createZstdCompress,\n createZstdDecompress,\n zstdCompressSync,\n zstdDecompressSync,\n ),\n )\n }\n return codecs\n}\n"]}
@@ -0,0 +1,115 @@
1
+ import type { BrotliOptions, ZlibOptions, ZstdOptions } from 'node:zlib';
2
+ import * as core from '../index.js';
3
+ import { type FileOption, type NoFileOption, type WithAliases } from '../dealias.js';
4
+ import type { PackInput, PackInputSync } from '../pack.js';
5
+ import type { ReadEntry, ReadEntrySync } from '../read-entry.js';
6
+ export * from '../index.js';
7
+ export { TarReaderSync } from '../entries.js';
8
+ export { PackSync } from '../pack.js';
9
+ export { ReadEntrySync } from '../read-entry.js';
10
+ export { UnpackSync } from '../unpack.js';
11
+ export { zlibCodecs, codecStream, type ZlibModule } from './codecs.js';
12
+ /** Each member of the option type `T`, with `fs` and `cwd` optional. */
13
+ export type Loose<T> = T extends unknown ? Omit<T, 'fs' | 'cwd'> & Partial<Pick<T, Extract<keyof T, 'fs' | 'cwd'>>> : never;
14
+ /** The compression options, with the option types of `node:zlib`. */
15
+ export type Zip = {
16
+ /** Compress with gzip. An object is the options of `zlib.createGzip`. */
17
+ gzip?: boolean | ZlibOptions;
18
+ /**
19
+ * Compress with brotli. An object is the options of
20
+ * `zlib.createBrotliCompress`.
21
+ */
22
+ brotli?: boolean | BrotliOptions;
23
+ /**
24
+ * Compress with zstd. An object is the options of
25
+ * `zlib.createZstdCompress`.
26
+ */
27
+ zstd?: boolean | ZstdOptions;
28
+ };
29
+ /** `Loose<T>`, with the compression options of `Zip`. */
30
+ export type Packing<T> = Omit<Loose<T>, keyof Zip> & Zip;
31
+ /** The options of `entries`. */
32
+ export type ReadOptions = core.ReadOptions;
33
+ /** The options of `entriesSync`. */
34
+ export type ReadOptionsSync = core.ReadOptionsSync;
35
+ /** The options of `list`. Set `input` or `file`. */
36
+ export type ListOptions = Loose<core.ListOptions>;
37
+ /** The options of `listSync`. Set `input` or `file`. */
38
+ export type ListOptionsSync = Loose<core.ListOptionsSync>;
39
+ /** The options of `extract`. The default of `cwd` is `process.cwd()`. */
40
+ export type ExtractOptions = Loose<core.ExtractOptions>;
41
+ /** The options of `extractSync`. */
42
+ export type ExtractOptionsSync = Loose<core.ExtractOptionsSync>;
43
+ /** The options of `create`. The default of `cwd` is `process.cwd()`. */
44
+ export type CreateOptions = Packing<core.CreateOptions>;
45
+ /** The options of `createSync`. */
46
+ export type CreateOptionsSync = Packing<core.CreateOptionsSync>;
47
+ /** The options of `replace` and `update`. */
48
+ export type ReplaceOptions = Packing<core.ReplaceOptions>;
49
+ /** The options of `replaceSync` and `updateSync`. */
50
+ export type ReplaceOptionsSync = Packing<core.ReplaceOptionsSync>;
51
+ /** The options of `delete`. */
52
+ export type DeleteOptions = Loose<core.DeleteOptions>;
53
+ /** The options of `deleteSync`. */
54
+ export type DeleteOptionsSync = Loose<core.DeleteOptionsSync>;
55
+ /**
56
+ * Read the entries of an archive. Gzip, brotli, and zstd input is
57
+ * decompressed, if the runtime has the format.
58
+ */
59
+ export declare const entries: (input: core.TarInput, opt?: ReadOptions) => AsyncIterableIterator<ReadEntry, undefined>;
60
+ /** The sync form of `entries`. */
61
+ export declare const entriesSync: (input: core.TarInputSync, opt?: ReadOptionsSync) => IterableIterator<ReadEntrySync, undefined>;
62
+ /**
63
+ * Call `opt.onEntry` with each entry of an archive. If `files` is
64
+ * set, only with the entries that it lists, and the entries in the
65
+ * directories that it lists.
66
+ */
67
+ export declare const list: (opt: WithAliases<ListOptions>, files?: string[]) => Promise<void>;
68
+ /** The sync form of `list`. */
69
+ export declare const listSync: (opt: WithAliases<ListOptionsSync>, files?: string[]) => void;
70
+ /**
71
+ * Extract the entries of an archive into the directory `opt.cwd`.
72
+ * If `files` is set, only the entries that it lists, and the entries
73
+ * in the directories that it lists.
74
+ */
75
+ export declare const extract: (opt: WithAliases<ExtractOptions>, files?: string[]) => Promise<void>;
76
+ /** The sync form of `extract`. */
77
+ export declare const extractSync: (opt: WithAliases<ExtractOptionsSync>, files?: string[]) => void;
78
+ /**
79
+ * Make an archive of the files. With `opt.file`, the archive is
80
+ * written to that path. With no `opt.file`, the result is a stream
81
+ * of the bytes of the archive.
82
+ */
83
+ export declare function create(opt: WithAliases<CreateOptions> & FileOption, files: PackInput[]): Promise<void>;
84
+ export declare function create(opt: WithAliases<CreateOptions> & NoFileOption, files: PackInput[]): ReadableStream<Uint8Array>;
85
+ export declare function create(opt: WithAliases<CreateOptions>, files: PackInput[]): Promise<void> | ReadableStream<Uint8Array>;
86
+ /**
87
+ * The sync form of `create`. With no `opt.file`, the result is an
88
+ * iterator of the bytes of the archive.
89
+ */
90
+ export declare function createSync(opt: WithAliases<CreateOptionsSync> & FileOption, files: PackInputSync[]): void;
91
+ export declare function createSync(opt: WithAliases<CreateOptionsSync> & NoFileOption, files: PackInputSync[]): IterableIterator<Uint8Array, undefined>;
92
+ export declare function createSync(opt: WithAliases<CreateOptionsSync>, files: PackInputSync[]): void | IterableIterator<Uint8Array, undefined>;
93
+ /** Add the files to the end of an archive file that is not compressed. */
94
+ export declare const replace: (opt: WithAliases<ReplaceOptions>, files: PackInput[]) => Promise<void>;
95
+ /** The sync form of `replace`. */
96
+ export declare const replaceSync: (opt: WithAliases<ReplaceOptionsSync>, files: PackInputSync[]) => void;
97
+ /**
98
+ * The same as `replace`, but a file is added only if it is newer than
99
+ * the last entry of the archive that has its path. A directory is
100
+ * always added, and each path in it is checked.
101
+ */
102
+ export declare const update: (opt: WithAliases<ReplaceOptions>, files: PackInput[]) => Promise<void>;
103
+ /** The sync form of `update`. */
104
+ export declare const updateSync: (opt: WithAliases<ReplaceOptionsSync>, files: PackInputSync[]) => void;
105
+ /**
106
+ * Remove entries from an archive file: each entry that `files` lists,
107
+ * and each entry in a directory that it lists. With `opt.filter`,
108
+ * only if the filter also returns true.
109
+ */
110
+ declare const del: (opt: WithAliases<DeleteOptions>, files?: string[]) => Promise<void>;
111
+ /** The sync form of `delete`. */
112
+ export declare const deleteSync: (opt: WithAliases<DeleteOptionsSync>, files?: string[]) => void;
113
+ export { del as delete };
114
+ export { create as c, extract as x, list as t, replace as r, update as u };
115
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAExE,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AAGnC,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MA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