@poe-platform/safe-bash 0.1.630 → 0.1.632

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 (357) hide show
  1. package/README.md +1 -0
  2. package/dist/office-package/compression.d.ts +19 -0
  3. package/dist/office-package/compression.js +186 -0
  4. package/dist/office-package/runtime.d.ts +11 -0
  5. package/dist/office-package/runtime.js +28 -0
  6. package/dist/safe-bash/chunks/{bz2-B2RXT4EX.js → bz2-ACU4EOVE.js} +2 -2
  7. package/dist/safe-bash/chunks/chunk-2E4KBFO6.js +239 -0
  8. package/dist/safe-bash/chunks/chunk-2E4KBFO6.js.map +7 -0
  9. package/dist/safe-bash/chunks/chunk-3E5M2WEL.js +33 -0
  10. package/dist/safe-bash/chunks/chunk-3E5M2WEL.js.map +7 -0
  11. package/dist/safe-bash/chunks/{chunk-KQ6J7JHQ.js → chunk-3LD67SER.js} +12 -10
  12. package/dist/safe-bash/chunks/{chunk-KQ6J7JHQ.js.map → chunk-3LD67SER.js.map} +1 -1
  13. package/dist/safe-bash/chunks/{chunk-6LSSEOG7.js → chunk-6HNK7Q66.js} +11 -7
  14. package/dist/safe-bash/chunks/{chunk-6LSSEOG7.js.map → chunk-6HNK7Q66.js.map} +1 -1
  15. package/dist/safe-bash/chunks/{chunk-AD7UAP5B.js → chunk-7EEWZY5S.js} +10 -8
  16. package/dist/safe-bash/chunks/{chunk-AD7UAP5B.js.map → chunk-7EEWZY5S.js.map} +1 -1
  17. package/dist/safe-bash/chunks/{chunk-RNKTWFEM.js → chunk-CDBQXRWL.js} +3 -3
  18. package/dist/safe-bash/chunks/{chunk-UYX72YHY.js → chunk-CHHAB5SS.js} +10 -74
  19. package/dist/safe-bash/chunks/{chunk-UYX72YHY.js.map → chunk-CHHAB5SS.js.map} +3 -3
  20. package/dist/safe-bash/chunks/{chunk-6YSBXTTJ.js → chunk-EI4X5ETX.js} +12 -10
  21. package/dist/safe-bash/chunks/{chunk-6YSBXTTJ.js.map → chunk-EI4X5ETX.js.map} +1 -1
  22. package/dist/safe-bash/chunks/{chunk-KZ7QCYNT.js → chunk-GIBLUW2U.js} +13 -9
  23. package/dist/safe-bash/chunks/{chunk-KZ7QCYNT.js.map → chunk-GIBLUW2U.js.map} +1 -1
  24. package/dist/safe-bash/chunks/chunk-GPV7ZFYS.js +1528 -0
  25. package/dist/safe-bash/chunks/chunk-GPV7ZFYS.js.map +7 -0
  26. package/dist/safe-bash/chunks/{chunk-N5CYTGBN.js → chunk-H3E67KTZ.js} +13 -9
  27. package/dist/safe-bash/chunks/{chunk-N5CYTGBN.js.map → chunk-H3E67KTZ.js.map} +1 -1
  28. package/dist/safe-bash/chunks/{chunk-AFH57PPL.js → chunk-IEKESMO4.js} +3 -3
  29. package/dist/safe-bash/chunks/{chunk-DPJWEGIX.js → chunk-JLBIUYT3.js} +2 -2
  30. package/dist/safe-bash/chunks/chunk-JZDO5MC3.js +77 -0
  31. package/dist/safe-bash/chunks/chunk-JZDO5MC3.js.map +7 -0
  32. package/dist/safe-bash/chunks/{chunk-GFZKQIPL.js → chunk-LA6BX562.js} +8 -6
  33. package/dist/safe-bash/chunks/{chunk-GFZKQIPL.js.map → chunk-LA6BX562.js.map} +1 -1
  34. package/dist/safe-bash/chunks/{chunk-PVJJFCGA.js → chunk-M3GPCYSP.js} +2 -2
  35. package/dist/safe-bash/chunks/{chunk-FWDMJTQO.js → chunk-NDCZ3UBP.js} +13 -9
  36. package/dist/safe-bash/chunks/{chunk-FWDMJTQO.js.map → chunk-NDCZ3UBP.js.map} +1 -1
  37. package/dist/safe-bash/chunks/{chunk-2KL6W6NB.js → chunk-O2EVBRKF.js} +1 -2
  38. package/dist/safe-bash/chunks/chunk-OFT77XIB.js +389 -0
  39. package/dist/safe-bash/chunks/chunk-OFT77XIB.js.map +7 -0
  40. package/dist/safe-bash/chunks/{chunk-PCLOK32J.js → chunk-PC6BEIAF.js} +13 -9
  41. package/dist/safe-bash/chunks/{chunk-PCLOK32J.js.map → chunk-PC6BEIAF.js.map} +1 -1
  42. package/dist/safe-bash/chunks/{chunk-3M5F7LD5.js → chunk-QWKP7ZU7.js} +13 -9
  43. package/dist/safe-bash/chunks/{chunk-3M5F7LD5.js.map → chunk-QWKP7ZU7.js.map} +1 -1
  44. package/dist/safe-bash/chunks/chunk-THXJ6CLF.js +53 -0
  45. package/dist/safe-bash/chunks/chunk-THXJ6CLF.js.map +7 -0
  46. package/dist/safe-bash/chunks/{chunk-K7W6Q6FN.js → chunk-V73A742N.js} +58 -16
  47. package/dist/safe-bash/chunks/chunk-V73A742N.js.map +7 -0
  48. package/dist/safe-bash/chunks/{chunk-4BYUV5PA.js → chunk-VN3ZGME3.js} +12 -8
  49. package/dist/safe-bash/chunks/{chunk-4BYUV5PA.js.map → chunk-VN3ZGME3.js.map} +1 -1
  50. package/dist/safe-bash/chunks/{chunk-3BZ5NQ73.js → chunk-WECHUK3Y.js} +369 -36
  51. package/dist/safe-bash/chunks/chunk-WECHUK3Y.js.map +7 -0
  52. package/dist/safe-bash/chunks/{chunk-X55AMTNM.js → chunk-WIOEUR7D.js} +14 -10
  53. package/dist/safe-bash/chunks/{chunk-X55AMTNM.js.map → chunk-WIOEUR7D.js.map} +1 -1
  54. package/dist/safe-bash/chunks/chunk-WPIOO4NX.js +443 -0
  55. package/dist/safe-bash/chunks/chunk-WPIOO4NX.js.map +7 -0
  56. package/dist/safe-bash/chunks/{chunk-C7QNJ3D4.js → chunk-WYTI64IU.js} +2 -2
  57. package/dist/safe-bash/chunks/{xz-AVXFDXW4.js → xz-U4QDTPZL.js} +2 -2
  58. package/dist/safe-bash/chunks/{zstd-R6RPHJYO.js → zstd-OG5RPYXO.js} +2 -2
  59. package/dist/safe-bash/commands/archive/zip/crc.d.ts +2 -0
  60. package/dist/safe-bash/commands/archive/zip/crc.d.ts.map +1 -0
  61. package/dist/safe-bash/commands/archive/zip/crc.js +7 -0
  62. package/dist/safe-bash/commands/archive/zip/crc.js.map +1 -0
  63. package/dist/safe-bash/commands/archive/zip/crypto.d.ts +4 -0
  64. package/dist/safe-bash/commands/archive/zip/crypto.d.ts.map +1 -0
  65. package/dist/safe-bash/commands/archive/zip/crypto.js +34 -0
  66. package/dist/safe-bash/commands/archive/zip/crypto.js.map +1 -0
  67. package/dist/safe-bash/commands/archive/zip/help.d.ts +3 -0
  68. package/dist/safe-bash/commands/archive/zip/help.d.ts.map +1 -0
  69. package/dist/safe-bash/commands/archive/zip/help.js +87 -0
  70. package/dist/safe-bash/commands/archive/zip/help.js.map +1 -0
  71. package/dist/safe-bash/commands/archive/zip/move.d.ts +12 -0
  72. package/dist/safe-bash/commands/archive/zip/move.d.ts.map +1 -0
  73. package/dist/safe-bash/commands/archive/zip/move.js +60 -0
  74. package/dist/safe-bash/commands/archive/zip/move.js.map +1 -0
  75. package/dist/safe-bash/commands/archive/zip/options.js +5 -5
  76. package/dist/safe-bash/commands/archive/zip/options.js.map +1 -1
  77. package/dist/safe-bash/commands/archive/zip-format.d.ts +1 -1
  78. package/dist/safe-bash/commands/archive/zip-format.d.ts.map +1 -1
  79. package/dist/safe-bash/commands/archive/zip-format.js +14 -17
  80. package/dist/safe-bash/commands/archive/zip-format.js.map +1 -1
  81. package/dist/safe-bash/commands/archive/zip.d.ts.map +1 -1
  82. package/dist/safe-bash/commands/archive/zip.js +45 -15
  83. package/dist/safe-bash/commands/archive/zip.js.map +1 -1
  84. package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts +2 -0
  85. package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts.map +1 -1
  86. package/dist/safe-bash/commands/bytes/compression/bounded-codec.js +4 -0
  87. package/dist/safe-bash/commands/bytes/compression/bounded-codec.js.map +1 -1
  88. package/dist/safe-bash/commands/bytes/compression/codec.d.ts +4 -24
  89. package/dist/safe-bash/commands/bytes/compression/codec.d.ts.map +1 -1
  90. package/dist/safe-bash/commands/bytes/compression/codec.js +12 -168
  91. package/dist/safe-bash/commands/bytes/compression/codec.js.map +1 -1
  92. package/dist/safe-bash/commands/cmp.js +1 -1
  93. package/dist/safe-bash/commands/cmp.js.map +1 -1
  94. package/dist/safe-bash/commands/csplit/index.browser.js +10 -7
  95. package/dist/safe-bash/commands/docx/index.browser.js +54 -0
  96. package/dist/safe-bash/commands/docx/index.browser.js.map +7 -0
  97. package/dist/safe-bash/commands/docx/index.d.ts +25 -0
  98. package/dist/safe-bash/commands/docx/index.d.ts.map +1 -0
  99. package/dist/safe-bash/commands/docx/index.js +42 -0
  100. package/dist/safe-bash/commands/docx/index.js.map +1 -0
  101. package/dist/safe-bash/commands/docx/io.d.ts +15 -0
  102. package/dist/safe-bash/commands/docx/io.d.ts.map +1 -0
  103. package/dist/safe-bash/commands/docx/io.js +16 -0
  104. package/dist/safe-bash/commands/docx/io.js.map +1 -0
  105. package/dist/safe-bash/commands/factor/index.browser.js +7 -5
  106. package/dist/safe-bash/commands/filesystem.d.ts.map +1 -1
  107. package/dist/safe-bash/commands/filesystem.js +9 -1
  108. package/dist/safe-bash/commands/filesystem.js.map +1 -1
  109. package/dist/safe-bash/commands/getopt/index.browser.js +7 -5
  110. package/dist/safe-bash/commands/hexdump/index.browser.js +8 -6
  111. package/dist/safe-bash/commands/iconv/index.browser.js +8 -6
  112. package/dist/safe-bash/commands/line-endings/index.browser.js +10 -7
  113. package/dist/safe-bash/commands/llm/index.browser.js +10 -8
  114. package/dist/safe-bash/commands/llm/providers/index.browser.js +3 -3
  115. package/dist/safe-bash/commands/network/index.browser.js +11 -8
  116. package/dist/safe-bash/commands/node/index.browser.js +8 -6
  117. package/dist/safe-bash/commands/op/index.browser.js +3 -3
  118. package/dist/safe-bash/commands/op/index.js +0 -1
  119. package/dist/safe-bash/commands/op/index.js.map +2 -2
  120. package/dist/safe-bash/commands/pptx/index.d.ts +29 -0
  121. package/dist/safe-bash/commands/pptx/index.d.ts.map +1 -0
  122. package/dist/safe-bash/commands/pptx/index.js +153 -0
  123. package/dist/safe-bash/commands/pptx/index.js.map +1 -0
  124. package/dist/safe-bash/commands/pr/index.browser.js +8 -6
  125. package/dist/safe-bash/commands/predicates.js +1 -1
  126. package/dist/safe-bash/commands/python/execution.d.ts +3 -0
  127. package/dist/safe-bash/commands/python/execution.d.ts.map +1 -0
  128. package/dist/safe-bash/commands/python/execution.js +193 -0
  129. package/dist/safe-bash/commands/python/execution.js.map +1 -0
  130. package/dist/safe-bash/commands/python/index.browser.js +21 -0
  131. package/dist/safe-bash/commands/python/index.browser.js.map +7 -0
  132. package/dist/safe-bash/commands/python/index.d.ts +49 -0
  133. package/dist/safe-bash/commands/python/index.d.ts.map +1 -0
  134. package/dist/safe-bash/commands/python/index.js +317 -0
  135. package/dist/safe-bash/commands/python/index.js.map +1 -0
  136. package/dist/safe-bash/commands/python/installation.d.ts +9 -0
  137. package/dist/safe-bash/commands/python/installation.d.ts.map +1 -0
  138. package/dist/safe-bash/commands/python/installation.js +80 -0
  139. package/dist/safe-bash/commands/python/installation.js.map +1 -0
  140. package/dist/safe-bash/commands/python/invocation.d.ts +10 -0
  141. package/dist/safe-bash/commands/python/invocation.d.ts.map +1 -0
  142. package/dist/safe-bash/commands/python/invocation.js +81 -0
  143. package/dist/safe-bash/commands/python/invocation.js.map +1 -0
  144. package/dist/safe-bash/commands/python/node.d.ts +12 -0
  145. package/dist/safe-bash/commands/python/node.d.ts.map +1 -0
  146. package/dist/safe-bash/commands/python/node.js +33 -0
  147. package/dist/safe-bash/commands/python/node.js.map +1 -0
  148. package/dist/safe-bash/commands/python/provisioning-runtime.d.ts +5 -0
  149. package/dist/safe-bash/commands/python/provisioning-runtime.d.ts.map +1 -0
  150. package/dist/safe-bash/commands/python/provisioning-runtime.js +179 -0
  151. package/dist/safe-bash/commands/python/provisioning-runtime.js.map +1 -0
  152. package/dist/safe-bash/commands/python/provisioning.d.ts +49 -0
  153. package/dist/safe-bash/commands/python/provisioning.d.ts.map +1 -0
  154. package/dist/safe-bash/commands/python/provisioning.js +320 -0
  155. package/dist/safe-bash/commands/python/provisioning.js.map +1 -0
  156. package/dist/safe-bash/commands/python/reply.d.ts +3 -0
  157. package/dist/safe-bash/commands/python/reply.d.ts.map +1 -0
  158. package/dist/safe-bash/commands/python/reply.js +103 -0
  159. package/dist/safe-bash/commands/python/reply.js.map +1 -0
  160. package/dist/safe-bash/commands/python/worker.browser.js +736 -0
  161. package/dist/safe-bash/commands/python/worker.browser.js.map +7 -0
  162. package/dist/safe-bash/commands/python/worker.d.ts +47 -0
  163. package/dist/safe-bash/commands/python/worker.d.ts.map +1 -0
  164. package/dist/safe-bash/commands/python/worker.js +373 -0
  165. package/dist/safe-bash/commands/python/worker.js.map +1 -0
  166. package/dist/safe-bash/commands/tsort/index.browser.js +8 -6
  167. package/dist/safe-bash/commands/xml/index.browser.js +9 -7
  168. package/dist/safe-bash/commands/yq/index.browser.js +10 -8
  169. package/dist/safe-bash/commands/yq/index.d.ts.map +1 -1
  170. package/dist/safe-bash/commands/yq/index.js +32 -4
  171. package/dist/safe-bash/commands/yq/index.js.map +1 -1
  172. package/dist/safe-bash/commands/yq/parser.d.ts.map +1 -1
  173. package/dist/safe-bash/commands/yq/parser.js +21 -5
  174. package/dist/safe-bash/commands/yq/parser.js.map +1 -1
  175. package/dist/safe-bash/contracts/command.d.ts +2 -0
  176. package/dist/safe-bash/contracts/command.d.ts.map +1 -1
  177. package/dist/safe-bash/contracts/command.js +6 -2
  178. package/dist/safe-bash/contracts/command.js.map +1 -1
  179. package/dist/safe-bash/contracts/filesystem-descriptor.d.ts +13 -0
  180. package/dist/safe-bash/contracts/filesystem-descriptor.d.ts.map +1 -0
  181. package/dist/safe-bash/contracts/filesystem-descriptor.js +189 -0
  182. package/dist/safe-bash/contracts/filesystem-descriptor.js.map +1 -0
  183. package/dist/safe-bash/contracts/filesystem-output-budget.d.ts +15 -0
  184. package/dist/safe-bash/contracts/filesystem-output-budget.d.ts.map +1 -0
  185. package/dist/safe-bash/contracts/filesystem-output-budget.js +69 -0
  186. package/dist/safe-bash/contracts/filesystem-output-budget.js.map +1 -0
  187. package/dist/safe-bash/contracts/filesystem-output.d.ts +11 -5
  188. package/dist/safe-bash/contracts/filesystem-output.d.ts.map +1 -1
  189. package/dist/safe-bash/contracts/filesystem-output.js +229 -20
  190. package/dist/safe-bash/contracts/filesystem-output.js.map +1 -1
  191. package/dist/safe-bash/contracts/io.d.ts +29 -0
  192. package/dist/safe-bash/contracts/io.d.ts.map +1 -1
  193. package/dist/safe-bash/contracts/io.js +317 -37
  194. package/dist/safe-bash/contracts/io.js.map +1 -1
  195. package/dist/safe-bash/core.browser.js +5502 -2210
  196. package/dist/safe-bash/core.browser.js.map +4 -4
  197. package/dist/safe-bash/core.d.ts +1 -0
  198. package/dist/safe-bash/core.d.ts.map +1 -1
  199. package/dist/safe-bash/core.js +1 -0
  200. package/dist/safe-bash/core.js.map +1 -1
  201. package/dist/safe-bash/opt-in/commands/cmp/compare.js +95 -0
  202. package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -0
  203. package/dist/safe-bash/opt-in/commands/cmp/index.js +99 -0
  204. package/dist/safe-bash/opt-in/commands/cmp/io.js +218 -0
  205. package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +24 -0
  206. package/dist/safe-bash/opt-in/commands/cmp/options.js +195 -0
  207. package/dist/safe-bash/opt-in/commands/dd/conversions.js +152 -0
  208. package/dist/safe-bash/opt-in/commands/dd/index.d.ts +18 -0
  209. package/dist/safe-bash/opt-in/commands/dd/index.js +561 -0
  210. package/dist/safe-bash/opt-in/commands/dd/io.d.ts +31 -0
  211. package/dist/safe-bash/opt-in/commands/dd/io.js +244 -0
  212. package/dist/safe-bash/opt-in/commands/dd/options.js +184 -0
  213. package/dist/safe-bash/opt-in/commands/dd/report.js +69 -0
  214. package/dist/safe-bash/opt-in/commands/install/arguments.js +224 -0
  215. package/dist/safe-bash/opt-in/commands/install/index.d.ts +6 -0
  216. package/dist/safe-bash/opt-in/commands/install/index.js +678 -0
  217. package/dist/safe-bash/opt-in/commands/install/mode.js +71 -0
  218. package/dist/safe-bash/opt-in/commands/install/options.d.ts +36 -0
  219. package/dist/safe-bash/opt-in/commands/install/options.js +27 -0
  220. package/dist/safe-bash/opt-in/commands/shuf/args.js +179 -0
  221. package/dist/safe-bash/opt-in/commands/shuf/index.d.ts +6 -0
  222. package/dist/safe-bash/opt-in/commands/shuf/index.js +20 -0
  223. package/dist/safe-bash/opt-in/commands/shuf/input.js +93 -0
  224. package/dist/safe-bash/opt-in/commands/shuf/options.d.ts +9 -0
  225. package/dist/safe-bash/opt-in/commands/shuf/options.js +8 -0
  226. package/dist/safe-bash/opt-in/commands/shuf/random.js +114 -0
  227. package/dist/safe-bash/opt-in/commands/shuf/shuf.d.ts +3 -0
  228. package/dist/safe-bash/opt-in/commands/shuf/shuf.js +230 -0
  229. package/dist/safe-bash/opt-in/commands/shuf/usage.js +24 -0
  230. package/dist/safe-bash/opt-in/commands/truncate/arguments.js +186 -0
  231. package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +9 -0
  232. package/dist/safe-bash/opt-in/commands/truncate/index.js +244 -0
  233. package/dist/safe-bash/opt-in/commands/yes/index.d.ts +11 -0
  234. package/dist/safe-bash/opt-in/commands/yes/index.js +167 -0
  235. package/dist/safe-bash/opt-in/commands/yq/arguments.js +177 -0
  236. package/dist/safe-bash/opt-in/commands/yq/evaluate.js +564 -0
  237. package/dist/safe-bash/opt-in/commands/yq/expression.js +183 -0
  238. package/dist/safe-bash/opt-in/commands/yq/inplace.js +65 -0
  239. package/dist/safe-bash/opt-in/commands/yq/mike.d.ts +9 -0
  240. package/dist/safe-bash/opt-in/commands/yq/mike.js +192 -0
  241. package/dist/safe-bash/opt-in/commands/yq/native-encoder.js +165 -0
  242. package/dist/safe-bash/opt-in/commands/yq/native-work.d.ts +44 -0
  243. package/dist/safe-bash/opt-in/commands/yq/native-work.js +188 -0
  244. package/dist/safe-bash/opt-in/commands/yq/nodes.js +621 -0
  245. package/dist/safe-bash/opt-in/entrypoints/arrays.d.ts +1 -0
  246. package/dist/safe-bash/opt-in/entrypoints/arrays.js +1 -0
  247. package/dist/safe-bash/opt-in/entrypoints/cmp.d.ts +2 -0
  248. package/dist/safe-bash/opt-in/entrypoints/cmp.js +1 -0
  249. package/dist/safe-bash/opt-in/entrypoints/dd.d.ts +2 -0
  250. package/dist/safe-bash/opt-in/entrypoints/dd.js +1 -0
  251. package/dist/safe-bash/opt-in/entrypoints/devices.d.ts +2 -0
  252. package/dist/safe-bash/opt-in/entrypoints/devices.js +1 -0
  253. package/dist/safe-bash/opt-in/entrypoints/install.d.ts +2 -0
  254. package/dist/safe-bash/opt-in/entrypoints/install.js +1 -0
  255. package/dist/safe-bash/opt-in/entrypoints/jobs.d.ts +1 -0
  256. package/dist/safe-bash/opt-in/entrypoints/jobs.js +1 -0
  257. package/dist/safe-bash/opt-in/entrypoints/mapfile.d.ts +1 -0
  258. package/dist/safe-bash/opt-in/entrypoints/mapfile.js +1 -0
  259. package/dist/safe-bash/opt-in/entrypoints/read.d.ts +2 -0
  260. package/dist/safe-bash/opt-in/entrypoints/read.js +1 -0
  261. package/dist/safe-bash/opt-in/entrypoints/shuf.d.ts +2 -0
  262. package/dist/safe-bash/opt-in/entrypoints/shuf.js +1 -0
  263. package/dist/safe-bash/opt-in/entrypoints/trap.d.ts +2 -0
  264. package/dist/safe-bash/opt-in/entrypoints/trap.js +1 -0
  265. package/dist/safe-bash/opt-in/entrypoints/truncate.d.ts +2 -0
  266. package/dist/safe-bash/opt-in/entrypoints/truncate.js +1 -0
  267. package/dist/safe-bash/opt-in/entrypoints/yes.d.ts +2 -0
  268. package/dist/safe-bash/opt-in/entrypoints/yes.js +1 -0
  269. package/dist/safe-bash/opt-in/entrypoints/yq.d.ts +3 -0
  270. package/dist/safe-bash/opt-in/entrypoints/yq.js +1 -0
  271. package/dist/safe-bash/opt-in/fs/devices/index.d.ts +8 -0
  272. package/dist/safe-bash/opt-in/fs/devices/index.js +292 -0
  273. package/dist/safe-bash/opt-in/optional.d.ts +28 -0
  274. package/dist/safe-bash/opt-in/optional.js +14 -0
  275. package/dist/safe-bash/opt-in/shell/extensions/arrays/index.d.ts +2 -0
  276. package/dist/safe-bash/opt-in/shell/extensions/arrays/index.js +4 -0
  277. package/dist/safe-bash/opt-in/shell/extensions/jobs/index.d.ts +2 -0
  278. package/dist/safe-bash/opt-in/shell/extensions/jobs/index.js +291 -0
  279. package/dist/safe-bash/opt-in/shell/extensions/jobs/state.js +374 -0
  280. package/dist/safe-bash/opt-in/shell/extensions/mapfile/index.d.ts +24 -0
  281. package/dist/safe-bash/opt-in/shell/extensions/mapfile/index.js +338 -0
  282. package/dist/safe-bash/opt-in/shell/extensions/read/index.d.ts +5 -0
  283. package/dist/safe-bash/opt-in/shell/extensions/read/index.js +351 -0
  284. package/dist/safe-bash/opt-in/shell/extensions/trap/index.d.ts +9 -0
  285. package/dist/safe-bash/opt-in/shell/extensions/trap/index.js +210 -0
  286. package/dist/safe-bash/optional-host.d.ts +5 -0
  287. package/dist/safe-bash/optional-host.d.ts.map +1 -0
  288. package/dist/safe-bash/optional-host.js +3 -0
  289. package/dist/safe-bash/optional-host.js.map +1 -0
  290. package/dist/safe-bash/shell/arrays/bindings.d.ts +15 -5
  291. package/dist/safe-bash/shell/arrays/bindings.d.ts.map +1 -1
  292. package/dist/safe-bash/shell/arrays/bindings.js +131 -23
  293. package/dist/safe-bash/shell/arrays/bindings.js.map +1 -1
  294. package/dist/safe-bash/shell/arrays/ledger.d.ts +1 -0
  295. package/dist/safe-bash/shell/arrays/ledger.d.ts.map +1 -1
  296. package/dist/safe-bash/shell/arrays/ledger.js +19 -0
  297. package/dist/safe-bash/shell/arrays/ledger.js.map +1 -1
  298. package/dist/safe-bash/shell/arrays/state.d.ts.map +1 -1
  299. package/dist/safe-bash/shell/arrays/state.js +3 -1
  300. package/dist/safe-bash/shell/arrays/state.js.map +1 -1
  301. package/dist/safe-bash/shell/arrays/syntax.d.ts +4 -1
  302. package/dist/safe-bash/shell/arrays/syntax.d.ts.map +1 -1
  303. package/dist/safe-bash/shell/arrays/syntax.js +3 -3
  304. package/dist/safe-bash/shell/arrays/syntax.js.map +1 -1
  305. package/dist/safe-bash/shell/conditional.js +1 -1
  306. package/dist/safe-bash/shell/descriptors.d.ts +31 -0
  307. package/dist/safe-bash/shell/descriptors.d.ts.map +1 -0
  308. package/dist/safe-bash/shell/descriptors.js +234 -0
  309. package/dist/safe-bash/shell/descriptors.js.map +1 -0
  310. package/dist/safe-bash/shell/diagnostic-name-ranges.d.ts +2 -0
  311. package/dist/safe-bash/shell/diagnostic-name-ranges.d.ts.map +1 -0
  312. package/dist/safe-bash/shell/diagnostic-name-ranges.js +717 -0
  313. package/dist/safe-bash/shell/diagnostic-name-ranges.js.map +1 -0
  314. package/dist/safe-bash/shell/diagnostic-name.d.ts +3 -0
  315. package/dist/safe-bash/shell/diagnostic-name.d.ts.map +1 -0
  316. package/dist/safe-bash/shell/diagnostic-name.js +89 -0
  317. package/dist/safe-bash/shell/diagnostic-name.js.map +1 -0
  318. package/dist/safe-bash/shell/display.js +1 -1
  319. package/dist/safe-bash/shell/display.js.map +1 -1
  320. package/dist/safe-bash/shell/extensions.d.ts +188 -0
  321. package/dist/safe-bash/shell/extensions.d.ts.map +1 -0
  322. package/dist/safe-bash/shell/extensions.js +141 -0
  323. package/dist/safe-bash/shell/extensions.js.map +1 -0
  324. package/dist/safe-bash/shell/input.d.ts +66 -14
  325. package/dist/safe-bash/shell/input.d.ts.map +1 -1
  326. package/dist/safe-bash/shell/input.js +947 -173
  327. package/dist/safe-bash/shell/input.js.map +1 -1
  328. package/dist/safe-bash/shell/parser.d.ts +38 -6
  329. package/dist/safe-bash/shell/parser.d.ts.map +1 -1
  330. package/dist/safe-bash/shell/parser.js +339 -52
  331. package/dist/safe-bash/shell/parser.js.map +1 -1
  332. package/dist/safe-bash/shell/runtime.d.ts +92 -20
  333. package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
  334. package/dist/safe-bash/shell/runtime.js +2547 -689
  335. package/dist/safe-bash/shell/runtime.js.map +1 -1
  336. package/dist/safe-bash/shell/shell.d.ts.map +1 -1
  337. package/dist/safe-bash/shell/shell.js +52 -21
  338. package/dist/safe-bash/shell/shell.js.map +1 -1
  339. package/dist/safe-bash/shell/types.d.ts +4 -0
  340. package/dist/safe-bash/shell/types.d.ts.map +1 -1
  341. package/dist/safe-bash/shell/types.js.map +1 -1
  342. package/package.json +92 -4
  343. package/dist/safe-bash/chunks/chunk-3BZ5NQ73.js.map +0 -7
  344. package/dist/safe-bash/chunks/chunk-4DBWBEU7.js +0 -194
  345. package/dist/safe-bash/chunks/chunk-4DBWBEU7.js.map +0 -7
  346. package/dist/safe-bash/chunks/chunk-CXMIIXJA.js +0 -178
  347. package/dist/safe-bash/chunks/chunk-CXMIIXJA.js.map +0 -7
  348. package/dist/safe-bash/chunks/chunk-K7W6Q6FN.js.map +0 -7
  349. /package/dist/safe-bash/chunks/{bz2-B2RXT4EX.js.map → bz2-ACU4EOVE.js.map} +0 -0
  350. /package/dist/safe-bash/chunks/{chunk-RNKTWFEM.js.map → chunk-CDBQXRWL.js.map} +0 -0
  351. /package/dist/safe-bash/chunks/{chunk-AFH57PPL.js.map → chunk-IEKESMO4.js.map} +0 -0
  352. /package/dist/safe-bash/chunks/{chunk-DPJWEGIX.js.map → chunk-JLBIUYT3.js.map} +0 -0
  353. /package/dist/safe-bash/chunks/{chunk-PVJJFCGA.js.map → chunk-M3GPCYSP.js.map} +0 -0
  354. /package/dist/safe-bash/chunks/{chunk-2KL6W6NB.js.map → chunk-O2EVBRKF.js.map} +0 -0
  355. /package/dist/safe-bash/chunks/{chunk-C7QNJ3D4.js.map → chunk-WYTI64IU.js.map} +0 -0
  356. /package/dist/safe-bash/chunks/{xz-AVXFDXW4.js.map → xz-U4QDTPZL.js.map} +0 -0
  357. /package/dist/safe-bash/chunks/{zstd-R6RPHJYO.js.map → zstd-OG5RPYXO.js.map} +0 -0
@@ -0,0 +1,561 @@
1
+ import { commandRuntimeIdentity, getCommandArguments } from "@poe-platform/safe-bash/contracts/command";
2
+ import { shellValueByteLength } from "@poe-platform/safe-bash/contracts/value";
3
+ import { assertCountedFileOutput, writeFileOutputCounted } from "@poe-platform/safe-bash/contracts/filesystem-output";
4
+ import { FsError } from "@poe-platform/safe-fs";
5
+ import { writeBytes } from "@poe-platform/safe-bash/contracts/io";
6
+ import { createOutputOperation } from "@poe-platform/safe-bash/contracts/output";
7
+ import { yieldTurn } from "@poe-platform/safe-bash/contracts/yield";
8
+ import { DdConverter } from "./conversions.js";
9
+ import { errorMessage, openDdFile, writeDdOutput } from "./io.js";
10
+ import { DdError, parseDd, quote } from "./options.js";
11
+ import { DdReporter } from "./report.js";
12
+ export { openDdFile } from "./io.js";
13
+ const help = `Usage: dd [OPERAND]...
14
+ or: dd OPTION
15
+ Copy a file, converting and formatting according to the operands.
16
+
17
+ bs=BYTES read and write up to BYTES bytes at a time (default: 512);
18
+ overrides ibs and obs
19
+ cbs=BYTES convert BYTES bytes at a time
20
+ conv=CONVS convert the file as per the comma separated symbol list
21
+ count=N copy only N input blocks
22
+ ibs=BYTES read up to BYTES bytes at a time (default: 512)
23
+ if=FILE read from FILE instead of stdin
24
+ iflag=FLAGS read as per the comma separated symbol list
25
+ obs=BYTES write BYTES bytes at a time (default: 512)
26
+ of=FILE write to FILE instead of stdout
27
+ oflag=FLAGS write as per the comma separated symbol list
28
+ seek=N (or oseek=N) skip N obs-sized output blocks
29
+ skip=N (or iseek=N) skip N ibs-sized input blocks
30
+ status=LEVEL The LEVEL of information to print to stderr;
31
+ 'none' suppresses everything but error messages,
32
+ 'noxfer' suppresses the final transfer statistics,
33
+ 'progress' shows periodic transfer statistics
34
+
35
+ N and BYTES may be followed by the following multiplicative suffixes:
36
+ c=1, w=2, b=512, kB=1000, K=1024, MB=1000*1000, M=1024*1024, xM=M,
37
+ GB=1000*1000*1000, G=1024*1024*1024, and so on for T, P, E, Z, Y, R, Q.
38
+ Binary prefixes can be used, too: KiB=K, MiB=M, and so on.
39
+ If N ends in 'B', it counts bytes not blocks.
40
+
41
+ Each CONV symbol may be:
42
+
43
+ ascii from EBCDIC to ASCII
44
+ ebcdic from ASCII to EBCDIC
45
+ ibm from ASCII to alternate EBCDIC
46
+ block pad newline-terminated records with spaces to cbs-size
47
+ unblock replace trailing spaces in cbs-size records with newline
48
+ lcase change upper case to lower case
49
+ ucase change lower case to upper case
50
+ sparse try to seek rather than write all-NUL output blocks
51
+ swab swap every pair of input bytes
52
+ sync pad every input block with NULs to ibs-size; when used
53
+ with block or unblock, pad with spaces rather than NULs
54
+ excl fail if the output file already exists
55
+ nocreat do not create the output file
56
+ notrunc do not truncate the output file
57
+ noerror continue after read errors
58
+ fdatasync physically write output file data before finishing
59
+ fsync likewise, but also write metadata
60
+
61
+ Each FLAG symbol may be:
62
+
63
+ append append mode (makes sense only for output; conv=notrunc suggested)
64
+ directory fail unless a directory
65
+ dsync use synchronized I/O for data
66
+ sync likewise, but also for metadata
67
+ fullblock accumulate full blocks of input (iflag only)
68
+ nonblock use non-blocking I/O
69
+ noctty do not assign controlling terminal from file
70
+ nofollow do not follow symlinks
71
+
72
+ Sending a INFO signal to a running 'dd' process makes it
73
+ print I/O statistics to standard error and then resume copying.
74
+
75
+ Options are:
76
+
77
+ --help display this help and exit
78
+ --version output version information and exit
79
+
80
+ GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
81
+ Report any translation bugs to <https://translationproject.org/team/>
82
+ Full documentation <https://www.gnu.org/software/coreutils/dd>
83
+ or available locally via: info '(coreutils) dd invocation'
84
+ `;
85
+ export function createDdCommand(options = {}) {
86
+ const limits = {
87
+ maxBlockBytes: options.maxBlockBytes ?? 1024 * 1024,
88
+ maxBufferBytes: options.maxBufferBytes ?? 8 * 1024 * 1024,
89
+ maxTransferBytes: options.maxTransferBytes ?? 64 * 1024 * 1024,
90
+ maxReadOperations: options.maxReadOperations ?? 1_000_000,
91
+ maxArgumentBytes: options.maxArgumentBytes ?? 65536,
92
+ };
93
+ for (const [name, value] of Object.entries(limits)) {
94
+ if (!Number.isSafeInteger(value) || value < (name === "maxTransferBytes" ? 0 : 1))
95
+ throw new RangeError(`${name} must be a ${name === "maxTransferBytes" ? "nonnegative" : "positive"} safe integer`);
96
+ }
97
+ const opener = options.openFile ?? openDdFile;
98
+ const now = options.now ?? (() => performance.now());
99
+ return { name: "dd", runtimeIdentity: commandRuntimeIdentity, description: "Copy and convert bounded byte streams and virtual files", async execute(context) {
100
+ const caller = context;
101
+ context.signal.throwIfAborted();
102
+ const diagnostic = async (message) => {
103
+ await writeBytes(context.stderr, new TextEncoder().encode(`dd: ${message}\n`), context.signal);
104
+ };
105
+ let plan;
106
+ try {
107
+ let argumentBytes = 0;
108
+ for (const argument of context.args) {
109
+ for (const character of argument) {
110
+ const point = character.codePointAt(0);
111
+ argumentBytes += point <= 0x7f ? 1 : point <= 0x7ff ? 2 : point <= 0xffff ? 3 : 4;
112
+ if (argumentBytes > limits.maxArgumentBytes)
113
+ throw new DdError("argument limit exceeded");
114
+ }
115
+ }
116
+ const argumentsValue = getCommandArguments(context);
117
+ let rawBytes = 0;
118
+ for (const value of argumentsValue.values) {
119
+ rawBytes += shellValueByteLength(value);
120
+ if (rawBytes > limits.maxArgumentBytes)
121
+ throw new DdError("argument limit exceeded");
122
+ }
123
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
124
+ const operands = [];
125
+ for (let index = 0; index < argumentsValue.args.length; index++) {
126
+ try {
127
+ operands.push(decoder.decode(argumentsValue.bytes(index)));
128
+ }
129
+ catch {
130
+ throw new DdError("operand contains invalid UTF-8 bytes; byte-path operands are not supported");
131
+ }
132
+ }
133
+ const parsed = parseDd(operands);
134
+ if (parsed === "help" || parsed === "version") {
135
+ await writeBytes(context.stdout, new TextEncoder().encode(parsed === "help" ? help : "dd (virtual-bash GNU-compatible profile)\n"), context.signal);
136
+ return { exitCode: 0 };
137
+ }
138
+ plan = parsed;
139
+ for (const warning of plan.warnings)
140
+ await diagnostic(warning);
141
+ }
142
+ catch (error) {
143
+ context.signal.throwIfAborted();
144
+ if (error instanceof DdError)
145
+ for (const warning of error.warnings)
146
+ await diagnostic(warning);
147
+ await diagnostic(errorMessage(error));
148
+ if (error instanceof DdError && error.usage)
149
+ await writeBytes(context.stderr, new TextEncoder().encode("Try 'dd --help' for more information.\n"), context.signal);
150
+ return { exitCode: 1 };
151
+ }
152
+ const operation = plan.output === undefined ? createOutputOperation(context, context.stdout) : undefined;
153
+ if (operation)
154
+ context = { ...context, signal: operation.signal, stdout: operation.output };
155
+ const handles = [];
156
+ let cleanup;
157
+ let closeFailure;
158
+ let closeDiagnosed = false;
159
+ let closed = false;
160
+ const close = () => {
161
+ closed = true;
162
+ cleanup ??= (async () => {
163
+ for (const { opening, request } of handles) {
164
+ let handle;
165
+ try {
166
+ handle = await opening;
167
+ }
168
+ catch {
169
+ continue;
170
+ }
171
+ try {
172
+ await handle.close();
173
+ }
174
+ catch (reason) {
175
+ closeFailure ??= { reason, request, handle };
176
+ }
177
+ }
178
+ if (closeFailure)
179
+ throw closeFailure.reason;
180
+ })();
181
+ return cleanup;
182
+ };
183
+ context.registerCleanup?.(async () => {
184
+ try {
185
+ await close();
186
+ }
187
+ catch (error) {
188
+ if (!closeDiagnosed)
189
+ throw error;
190
+ }
191
+ });
192
+ const acquire = (request) => {
193
+ context.signal.throwIfAborted();
194
+ if (closed)
195
+ throw new FsError("EBADF");
196
+ if (request.direction === "output" && request.path !== undefined)
197
+ assertCountedFileOutput(context);
198
+ const opening = Promise.resolve().then(() => opener(context, request));
199
+ handles.push({ opening, request });
200
+ return opening;
201
+ };
202
+ let reporter;
203
+ let syncOutput;
204
+ let failure;
205
+ let exitCode = 0;
206
+ let stage = "";
207
+ try {
208
+ const copying = plan.count !== 0n;
209
+ if (copying && [plan.ibs, plan.obs, ...(plan.convert.has("block") || plan.convert.has("unblock") ? [plan.cbs] : [])].some(size => size > BigInt(limits.maxBlockBytes)))
210
+ throw new DdError("block size limit exceeded");
211
+ const ibs = Number(plan.ibs > BigInt(limits.maxBlockBytes) ? BigInt(limits.maxBlockBytes) : plan.ibs);
212
+ const obs = Number(plan.obs > BigInt(limits.maxBlockBytes) ? BigInt(limits.maxBlockBytes) : plan.obs);
213
+ const sync = plan.convert.has("fsync") ? "all" : plan.convert.has("fdatasync") ? "data" : undefined;
214
+ const initialSeek = plan.seek * (plan.seekBytes ? 1n : plan.obs);
215
+ if (initialSeek > BigInt(limits.maxTransferBytes))
216
+ throw new DdError("output offset limit exceeded");
217
+ const common = { maxBufferBytes: limits.maxBufferBytes, maxReadOperations: limits.maxReadOperations };
218
+ stage = `failed to open ${quote(plan.input ?? "standard input")}`;
219
+ const input = await acquire({ ...common, direction: "input", ...(plan.input === undefined ? {} : { path: plan.input }), flags: plan.inputFlags,
220
+ creation: "never", truncate: false, seek: 0n, blockSize: ibs });
221
+ stage = `failed to open ${quote(plan.output ?? "standard output")}`;
222
+ const output = await acquire({ ...common, direction: "output", ...(plan.output === undefined ? {} : { path: plan.output }), flags: plan.outputFlags,
223
+ creation: plan.convert.has("excl") ? "exclusive" : plan.convert.has("nocreat") ? "never" : "allow",
224
+ truncate: !plan.convert.has("notrunc") && initialSeek === 0n, seek: initialSeek,
225
+ ...(sync === undefined ? {} : { synchronization: sync }), blockSize: obs });
226
+ syncOutput = output;
227
+ reporter = new DdReporter(context, plan.status, now);
228
+ const report = reporter;
229
+ const fsOptions = { signal: context.signal };
230
+ let position = initialSeek;
231
+ let lastSparse = false;
232
+ const appendFile = plan.output !== undefined && plan.outputFlags.has("append") && output.type === "file";
233
+ const deferredAppendSeek = appendFile && !output.seek && output.truncate !== undefined && output.getSize !== undefined;
234
+ let appendPositionKnown = true;
235
+ if (initialSeek) {
236
+ stage = `${quote(plan.output ?? "standard output")}: cannot seek`;
237
+ const appendIgnoresInitialPosition = appendFile && (!plan.convert.has("sparse") || deferredAppendSeek);
238
+ if (!output.seek && !appendIgnoresInitialPosition)
239
+ throw new FsError("ENOTSUP");
240
+ if (!plan.convert.has("notrunc") && plan.output !== undefined) {
241
+ if (!output.truncate)
242
+ throw new DdError("output truncation: Operation not supported");
243
+ await output.truncate(initialSeek, fsOptions);
244
+ }
245
+ await output.seek?.(initialSeek, fsOptions);
246
+ }
247
+ let readOperations = 0;
248
+ let inputBytes = 0n;
249
+ let inputPosition = 0n;
250
+ let previousShort = 0;
251
+ let partialRecord = 0;
252
+ let warned = false;
253
+ const read = async (size) => {
254
+ context.signal.throwIfAborted();
255
+ if (++readOperations > limits.maxReadOperations)
256
+ throw new DdError("input operation limit exceeded");
257
+ if (!input.read)
258
+ throw new FsError("EBADF");
259
+ const bytes = await input.read(size, fsOptions);
260
+ if (!(bytes instanceof Uint8Array) || bytes.length > size)
261
+ throw new DdError("input reader returned an invalid byte block");
262
+ inputBytes += BigInt(bytes.length);
263
+ inputPosition += BigInt(bytes.length);
264
+ if (inputBytes > BigInt(limits.maxTransferBytes))
265
+ throw new DdError("input transfer limit exceeded");
266
+ return bytes;
267
+ };
268
+ stage = `error reading ${quote(plan.input ?? "standard input")}`;
269
+ let skipRecords = plan.skipBytes ? plan.skip / plan.ibs : plan.skip;
270
+ let skipRemainder = plan.skipBytes ? plan.skip % plan.ibs : 0n;
271
+ const skipOffset = plan.skip * (plan.skipBytes ? 1n : plan.ibs);
272
+ if (skipOffset && input.seek) {
273
+ await input.seek(skipOffset, fsOptions);
274
+ inputPosition = skipOffset;
275
+ if (input.size !== undefined && input.size < skipOffset && plan.status !== "none")
276
+ await diagnostic(`${quote(plan.input ?? "standard input")}: cannot skip to specified offset`);
277
+ }
278
+ else if (skipOffset) {
279
+ let skipped = 0n;
280
+ while (skipRecords || skipRemainder) {
281
+ const wanted = skipRecords ? ibs : Number(skipRemainder);
282
+ let consumed = 0;
283
+ do {
284
+ const chunk = await read(wanted - consumed);
285
+ if (!chunk.length)
286
+ break;
287
+ consumed += chunk.length;
288
+ } while (plan.inputFlags.has("fullblock") && consumed < wanted);
289
+ if (consumed === 0)
290
+ break;
291
+ skipped += BigInt(consumed);
292
+ if (skipRecords)
293
+ skipRecords--;
294
+ else
295
+ skipRemainder = 0n;
296
+ await yieldTurn(context.signal);
297
+ }
298
+ if (skipped < skipOffset && plan.status !== "none")
299
+ await diagnostic(`${quote(plan.input ?? "standard input")}: cannot skip to specified offset`);
300
+ }
301
+ const writeRecord = async (bytes, fullBuffer = false) => {
302
+ stage = `${fullBuffer ? "writing to" : "error writing"} ${quote(plan.output ?? "standard output")}`;
303
+ if (report.stats.bytes + BigInt(bytes.length) > BigInt(limits.maxTransferBytes))
304
+ throw new DdError("output transfer limit exceeded");
305
+ lastSparse = false;
306
+ let written = 0;
307
+ let complete = false;
308
+ const sparseTarget = output.type === "character" || output.type === "file" && output.size !== undefined
309
+ && (output.truncate !== undefined || position + BigInt(bytes.length) <= output.size);
310
+ const zeroRecord = plan.convert.has("sparse") && bytes.every(byte => byte === 0);
311
+ if (zeroRecord && (output.seek || deferredAppendSeek) && sparseTarget && appendFile && !appendPositionKnown) {
312
+ if (!output.getPosition)
313
+ throw new DdError("sparse append cursor: Operation not supported");
314
+ const cursor = await output.getPosition(fsOptions);
315
+ context.signal.throwIfAborted();
316
+ if (typeof cursor !== "bigint" || cursor < 0n)
317
+ throw new FsError("EIO");
318
+ position = cursor;
319
+ appendPositionKnown = true;
320
+ }
321
+ if (position + BigInt(bytes.length) > BigInt(limits.maxTransferBytes))
322
+ throw new DdError("output offset limit exceeded");
323
+ if (zeroRecord && (output.seek || deferredAppendSeek) && sparseTarget) {
324
+ try {
325
+ const seek = async () => { await output.seek?.(position + BigInt(bytes.length), fsOptions); return bytes.length; };
326
+ written = plan.output === undefined ? await seek() : await writeFileOutputCounted(context, bytes, seek);
327
+ lastSparse = true;
328
+ }
329
+ catch (error) {
330
+ context.signal.throwIfAborted();
331
+ if (!(error instanceof FsError) || !["ENOTSUP", "EINVAL", "ESPIPE"].includes(error.code))
332
+ throw error;
333
+ }
334
+ }
335
+ try {
336
+ while (written < bytes.length) {
337
+ const count = await writeDdOutput(context, output, bytes.subarray(written), fsOptions, plan.output !== undefined);
338
+ if (!Number.isSafeInteger(count) || count < 0 || count > bytes.length - written)
339
+ throw new FsError("EIO");
340
+ if (count === 0)
341
+ throw new FsError("ENOSPC");
342
+ written += count;
343
+ if (appendFile)
344
+ appendPositionKnown = false;
345
+ }
346
+ complete = true;
347
+ }
348
+ finally {
349
+ report.stats.bytes += BigInt(written);
350
+ position += BigInt(written);
351
+ if (complete || plan.twoBuffers) {
352
+ if (written === obs)
353
+ report.stats.outputFull++;
354
+ else if (written)
355
+ report.stats.outputPartial++;
356
+ }
357
+ }
358
+ await yieldTurn(context.signal);
359
+ };
360
+ const outputBuffer = new Uint8Array(copying && plan.twoBuffers ? obs : 0);
361
+ let used = 0;
362
+ const emit = async (bytes) => {
363
+ if (!plan.twoBuffers) {
364
+ await writeRecord(bytes);
365
+ return;
366
+ }
367
+ for (let offset = 0; offset < bytes.length;) {
368
+ const count = Math.min(obs - used, bytes.length - offset);
369
+ outputBuffer.set(bytes.subarray(offset, offset + count), used);
370
+ offset += count;
371
+ used += count;
372
+ if (used === obs) {
373
+ await writeRecord(outputBuffer, true);
374
+ used = 0;
375
+ }
376
+ }
377
+ };
378
+ const converter = copying && plan.twoBuffers ? new DdConverter(plan, report.stats, emit, Math.min(obs, 65536)) : undefined;
379
+ const maxRecords = plan.count === undefined ? undefined : plan.countBytes ? plan.count / plan.ibs : plan.count;
380
+ const finalBytes = plan.countBytes && plan.count !== undefined ? Number(plan.count % plan.ibs) : 0;
381
+ while (copying) {
382
+ await report.progress();
383
+ const records = report.stats.inputFull + report.stats.inputPartial;
384
+ if (maxRecords !== undefined && records >= maxRecords + BigInt(finalBytes > 0))
385
+ break;
386
+ const wanted = maxRecords !== undefined && records >= maxRecords ? finalBytes : ibs;
387
+ stage = `error reading ${quote(plan.input ?? "standard input")}`;
388
+ const start = inputPosition;
389
+ const block = new Uint8Array(ibs);
390
+ if (plan.convert.has("sync") && (plan.convert.has("block") || plan.convert.has("unblock")))
391
+ block.fill(32);
392
+ let length = 0;
393
+ let failedRead = false;
394
+ try {
395
+ do {
396
+ const fragment = await read(wanted - length);
397
+ if (!fragment.length)
398
+ break;
399
+ block.set(fragment, length);
400
+ length += fragment.length;
401
+ } while (plan.inputFlags.has("fullblock") && length < wanted);
402
+ }
403
+ catch (error) {
404
+ context.signal.throwIfAborted();
405
+ previousShort = 0;
406
+ if (error instanceof DdError || !plan.convert.has("noerror")) {
407
+ if (!(error instanceof DdError)) {
408
+ await diagnostic(`${stage}: ${errorMessage(error)}`);
409
+ exitCode = 1;
410
+ break;
411
+ }
412
+ throw error;
413
+ }
414
+ if (plan.status !== "none")
415
+ await diagnostic(`${stage}: ${errorMessage(error)}`);
416
+ await report.report();
417
+ if (input.seek) {
418
+ const recoveredOffset = start + plan.ibs - BigInt(partialRecord);
419
+ await input.seek(recoveredOffset, fsOptions);
420
+ inputPosition = recoveredOffset;
421
+ }
422
+ else if (input.type !== "fifo")
423
+ throw new DdError(`${quote(plan.input ?? "standard input")}: read-error recovery not supported by this input`);
424
+ failedRead = true;
425
+ if (!plan.convert.has("sync") || partialRecord !== 0) {
426
+ await yieldTurn(context.signal);
427
+ continue;
428
+ }
429
+ }
430
+ if (!length && !failedRead)
431
+ break;
432
+ if (previousShort && !warned && length && !plan.twoBuffers && !plan.inputFlags.has("fullblock") && (plan.skip > 0n || plan.count !== undefined && plan.count > 0n)) {
433
+ if (plan.status !== "none")
434
+ await diagnostic(`warning: partial read (${previousShort} byte${previousShort === 1 ? "" : "s"}); suggest iflag=fullblock`);
435
+ warned = true;
436
+ }
437
+ previousShort = length < ibs ? length : 0;
438
+ partialRecord = failedRead ? 0 : previousShort;
439
+ if (length === ibs)
440
+ report.stats.inputFull++;
441
+ else
442
+ report.stats.inputPartial++;
443
+ const chunk = block.subarray(0, plan.convert.has("sync") ? ibs : length);
444
+ if (converter)
445
+ await converter.push(chunk);
446
+ else
447
+ await emit(chunk);
448
+ await yieldTurn(context.signal);
449
+ }
450
+ await converter?.finish();
451
+ if (used) {
452
+ await writeRecord(outputBuffer.subarray(0, used));
453
+ used = 0;
454
+ }
455
+ if (lastSparse && output.type === "file") {
456
+ const currentSize = output.getSize ? await output.getSize(fsOptions) : output.size ?? 0n;
457
+ context.signal.throwIfAborted();
458
+ if (typeof currentSize !== "bigint" || currentSize < 0n)
459
+ throw new FsError("EIO");
460
+ if (currentSize < position) {
461
+ if (!output.truncate)
462
+ throw new DdError("sparse output extension: Operation not supported");
463
+ await output.truncate(position, fsOptions);
464
+ }
465
+ }
466
+ }
467
+ catch (error) {
468
+ try {
469
+ caller.signal.throwIfAborted();
470
+ if (operation?.signal.aborted && operation.signal.reason instanceof FsError && operation.signal.reason.code === "EPIPE")
471
+ exitCode = 141;
472
+ else {
473
+ context.signal.throwIfAborted();
474
+ exitCode = 1;
475
+ await diagnostic(error instanceof DdError ? error.message : `${stage}: ${errorMessage(error)}`);
476
+ }
477
+ }
478
+ catch (reason) {
479
+ failure = { reason };
480
+ }
481
+ }
482
+ try {
483
+ if (!context.signal.aborted && syncOutput) {
484
+ let metadata = plan.convert.has("fsync");
485
+ if (plan.convert.has("fdatasync")) {
486
+ try {
487
+ if (!syncOutput.sync)
488
+ throw new FsError("ENOTSUP");
489
+ await syncOutput.sync(true, { signal: context.signal });
490
+ }
491
+ catch (error) {
492
+ context.signal.throwIfAborted();
493
+ metadata = true;
494
+ if (!(error instanceof FsError) || !["ENOSYS", "EINVAL"].includes(error.code)) {
495
+ exitCode = 1;
496
+ await diagnostic(`fdatasync failed for ${quote(plan.output ?? "standard output")}: ${errorMessage(error)}`);
497
+ }
498
+ }
499
+ }
500
+ if (metadata) {
501
+ try {
502
+ if (!syncOutput.sync)
503
+ throw new FsError("ENOTSUP");
504
+ await syncOutput.sync(false, { signal: context.signal });
505
+ }
506
+ catch (error) {
507
+ context.signal.throwIfAborted();
508
+ exitCode = 1;
509
+ await diagnostic(`fsync failed for ${quote(plan.output ?? "standard output")}: ${errorMessage(error)}`);
510
+ }
511
+ }
512
+ }
513
+ }
514
+ catch (reason) {
515
+ failure ??= { reason };
516
+ }
517
+ try {
518
+ await close();
519
+ }
520
+ catch (error) {
521
+ if (!context.signal.aborted && !failure) {
522
+ exitCode = 1;
523
+ const subject = closeFailure ? `${closeFailure.request.direction} file ${quote(closeFailure.request.path ?? `standard ${closeFailure.request.direction}`)}` : "file";
524
+ try {
525
+ await diagnostic(`closing ${subject}: ${errorMessage(error)}`);
526
+ caller.signal.throwIfAborted();
527
+ context.signal.throwIfAborted();
528
+ closeFailure?.handle.acknowledgeCloseFailure?.(closeFailure.reason);
529
+ closeDiagnosed = true;
530
+ }
531
+ catch (reason) {
532
+ failure = { reason };
533
+ }
534
+ }
535
+ }
536
+ try {
537
+ await operation?.close();
538
+ }
539
+ catch (reason) {
540
+ failure ??= { reason };
541
+ }
542
+ caller.signal.throwIfAborted();
543
+ if (failure)
544
+ throw failure.reason;
545
+ if (exitCode === 141)
546
+ return { exitCode };
547
+ context.signal.throwIfAborted();
548
+ if (!closeFailure)
549
+ await reporter?.report();
550
+ return { exitCode };
551
+ } };
552
+ }
553
+ export function createDdCommands(options = {}) {
554
+ return [createDdCommand(options)];
555
+ }
556
+ export function ddCommands(options = {}) {
557
+ const command = createDdCommand(options);
558
+ return { name: "dd-commands", setup(host) {
559
+ host.commands.register(command, { replace: options.replace ?? false });
560
+ } };
561
+ }
@@ -0,0 +1,31 @@
1
+ import type { FsOptions } from "@poe-platform/safe-fs";
2
+ import type { CommandContext } from "@poe-platform/safe-bash/contracts/command";
3
+ export interface DdFileRequest {
4
+ readonly direction: "input" | "output";
5
+ readonly path?: string;
6
+ readonly flags: ReadonlySet<string>;
7
+ readonly creation: "allow" | "exclusive" | "never";
8
+ readonly truncate: boolean;
9
+ readonly seek: bigint;
10
+ readonly synchronization?: "data" | "all";
11
+ readonly blockSize: number;
12
+ readonly maxBufferBytes: number;
13
+ readonly maxReadOperations: number;
14
+ }
15
+ export interface DdFileHandle {
16
+ readonly size?: bigint;
17
+ readonly type?: string;
18
+ read?(size: number, options: FsOptions): Promise<Uint8Array>;
19
+ write?(bytes: Uint8Array, options: FsOptions): Promise<number>;
20
+ seek?(offset: bigint, options: FsOptions): Promise<void>;
21
+ getSize?(options: FsOptions): Promise<bigint>;
22
+ getPosition?(options: FsOptions): Promise<bigint>;
23
+ truncate?(length: bigint, options: FsOptions): Promise<void>;
24
+ sync?(dataOnly: boolean, options: FsOptions): Promise<void>;
25
+ close(): Promise<void>;
26
+ acknowledgeCloseFailure?(reason: unknown): boolean;
27
+ }
28
+ export type DdFileOpener = (context: CommandContext, request: DdFileRequest) => Promise<DdFileHandle>;
29
+ export declare function writeDdOutput(context: CommandContext, handle: DdFileHandle, chunk: Uint8Array, options: FsOptions, named: boolean): Promise<number>;
30
+ export declare function errorMessage(error: unknown): string;
31
+ export declare function openDdFile(context: CommandContext, request: DdFileRequest): Promise<DdFileHandle>;