@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.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 (622) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +6 -0
  3. package/README.md +440 -2
  4. package/dist/argument-error.d.ts +15 -0
  5. package/dist/argument-error.js +15 -0
  6. package/dist/argument-error.js.map +1 -0
  7. package/dist/array.d.ts +415 -0
  8. package/dist/array.js +1330 -0
  9. package/dist/array.js.map +1 -0
  10. package/dist/async-context-adapter.d.ts +19 -0
  11. package/dist/async-context-adapter.js +139 -0
  12. package/dist/async-context-adapter.js.map +1 -0
  13. package/dist/backtrace-location.d.ts +77 -0
  14. package/dist/backtrace-location.js +155 -0
  15. package/dist/backtrace-location.js.map +1 -0
  16. package/dist/base64.d.ts +73 -0
  17. package/dist/base64.js +164 -0
  18. package/dist/base64.js.map +1 -0
  19. package/dist/benchmark.d.ts +19 -0
  20. package/dist/benchmark.js +16 -0
  21. package/dist/benchmark.js.map +1 -0
  22. package/dist/big-decimal.d.ts +110 -0
  23. package/dist/big-decimal.js +582 -0
  24. package/dist/big-decimal.js.map +1 -0
  25. package/dist/bundler.d.ts +44 -0
  26. package/dist/bundler.js +101 -0
  27. package/dist/bundler.js.map +1 -0
  28. package/dist/cgi.d.ts +89 -0
  29. package/dist/cgi.js +168 -0
  30. package/dist/cgi.js.map +1 -0
  31. package/dist/child-process-adapter.d.ts +110 -0
  32. package/dist/child-process-adapter.js +272 -0
  33. package/dist/child-process-adapter.js.map +1 -0
  34. package/dist/class-module.d.ts +10 -0
  35. package/dist/class-module.js +10 -0
  36. package/dist/class-module.js.map +1 -0
  37. package/dist/classpath.d.ts +90 -0
  38. package/dist/classpath.js +207 -0
  39. package/dist/classpath.js.map +1 -0
  40. package/dist/closed-queue-error.d.ts +10 -0
  41. package/dist/closed-queue-error.js +10 -0
  42. package/dist/closed-queue-error.js.map +1 -0
  43. package/dist/comparable.d.ts +127 -0
  44. package/dist/comparable.js +376 -0
  45. package/dist/comparable.js.map +1 -0
  46. package/dist/complex.d.ts +48 -0
  47. package/dist/complex.js +162 -0
  48. package/dist/complex.js.map +1 -0
  49. package/dist/concurrent/atomic-boolean.d.ts +24 -0
  50. package/dist/concurrent/atomic-boolean.js +43 -0
  51. package/dist/concurrent/atomic-boolean.js.map +1 -0
  52. package/dist/concurrent/atomic-fixnum.d.ts +21 -0
  53. package/dist/concurrent/atomic-fixnum.js +35 -0
  54. package/dist/concurrent/atomic-fixnum.js.map +1 -0
  55. package/dist/concurrent/count-down-latch.d.ts +20 -0
  56. package/dist/concurrent/count-down-latch.js +50 -0
  57. package/dist/concurrent/count-down-latch.js.map +1 -0
  58. package/dist/concurrent/cyclic-barrier.d.ts +18 -0
  59. package/dist/concurrent/cyclic-barrier.js +50 -0
  60. package/dist/concurrent/cyclic-barrier.js.map +1 -0
  61. package/dist/concurrent/event.d.ts +19 -0
  62. package/dist/concurrent/event.js +31 -0
  63. package/dist/concurrent/event.js.map +1 -0
  64. package/dist/concurrent/map.d.ts +149 -0
  65. package/dist/concurrent/map.js +202 -0
  66. package/dist/concurrent/map.js.map +1 -0
  67. package/dist/concurrent/read-write-lock.d.ts +25 -0
  68. package/dist/concurrent/read-write-lock.js +70 -0
  69. package/dist/concurrent/read-write-lock.js.map +1 -0
  70. package/dist/concurrent/semaphore.d.ts +24 -0
  71. package/dist/concurrent/semaphore.js +74 -0
  72. package/dist/concurrent/semaphore.js.map +1 -0
  73. package/dist/concurrent/timer-task.d.ts +52 -0
  74. package/dist/concurrent/timer-task.js +112 -0
  75. package/dist/concurrent/timer-task.js.map +1 -0
  76. package/dist/constants.generated.d.ts +2 -0
  77. package/dist/constants.generated.js +64 -0
  78. package/dist/constants.generated.js.map +1 -0
  79. package/dist/converter-not-found-error.d.ts +14 -0
  80. package/dist/converter-not-found-error.js +14 -0
  81. package/dist/converter-not-found-error.js.map +1 -0
  82. package/dist/crypto-adapter.d.ts +64 -0
  83. package/dist/crypto-adapter.js +365 -0
  84. package/dist/crypto-adapter.js.map +1 -0
  85. package/dist/delegate.d.ts +156 -0
  86. package/dist/delegate.js +306 -0
  87. package/dist/delegate.js.map +1 -0
  88. package/dist/digest.d.ts +99 -0
  89. package/dist/digest.js +131 -0
  90. package/dist/digest.js.map +1 -0
  91. package/dist/dir.d.ts +218 -0
  92. package/dist/dir.js +599 -0
  93. package/dist/dir.js.map +1 -0
  94. package/dist/encoding-error.d.ts +14 -0
  95. package/dist/encoding-error.js +17 -0
  96. package/dist/encoding-error.js.map +1 -0
  97. package/dist/encoding.d.ts +121 -0
  98. package/dist/encoding.js +306 -0
  99. package/dist/encoding.js.map +1 -0
  100. package/dist/ensure.d.ts +15 -0
  101. package/dist/ensure.js +35 -0
  102. package/dist/ensure.js.map +1 -0
  103. package/dist/enumerable.d.ts +375 -0
  104. package/dist/enumerable.js +1100 -0
  105. package/dist/enumerable.js.map +1 -0
  106. package/dist/enumerator.d.ts +321 -0
  107. package/dist/enumerator.js +642 -0
  108. package/dist/enumerator.js.map +1 -0
  109. package/dist/eof-error.d.ts +14 -0
  110. package/dist/eof-error.js +14 -0
  111. package/dist/eof-error.js.map +1 -0
  112. package/dist/errno.d.ts +327 -0
  113. package/dist/errno.js +452 -0
  114. package/dist/errno.js.map +1 -0
  115. package/dist/exc-detailed-message.d.ts +15 -0
  116. package/dist/exc-detailed-message.js +106 -0
  117. package/dist/exc-detailed-message.js.map +1 -0
  118. package/dist/exc-to-s.d.ts +10 -0
  119. package/dist/exc-to-s.js +21 -0
  120. package/dist/exc-to-s.js.map +1 -0
  121. package/dist/exception.d.ts +34 -0
  122. package/dist/exception.js +99 -0
  123. package/dist/exception.js.map +1 -0
  124. package/dist/fiber-error.d.ts +12 -0
  125. package/dist/fiber-error.js +12 -0
  126. package/dist/fiber-error.js.map +1 -0
  127. package/dist/fiber.d.ts +51 -0
  128. package/dist/fiber.js +178 -0
  129. package/dist/fiber.js.map +1 -0
  130. package/dist/file-utils.d.ts +480 -0
  131. package/dist/file-utils.js +1823 -0
  132. package/dist/file-utils.js.map +1 -0
  133. package/dist/file.d.ts +635 -0
  134. package/dist/file.js +1312 -0
  135. package/dist/file.js.map +1 -0
  136. package/dist/float-domain-error.d.ts +17 -0
  137. package/dist/float-domain-error.js +17 -0
  138. package/dist/float-domain-error.js.map +1 -0
  139. package/dist/fork-children.d.ts +23 -0
  140. package/dist/fork-children.js +32 -0
  141. package/dist/fork-children.js.map +1 -0
  142. package/dist/frozen-error.d.ts +33 -0
  143. package/dist/frozen-error.js +42 -0
  144. package/dist/frozen-error.js.map +1 -0
  145. package/dist/fs-adapter.d.ts +158 -0
  146. package/dist/fs-adapter.js +253 -0
  147. package/dist/fs-adapter.js.map +1 -0
  148. package/dist/gem/deprecate.d.ts +10 -0
  149. package/dist/gem/deprecate.js +8 -0
  150. package/dist/gem/deprecate.js.map +1 -0
  151. package/dist/gem/requirement.d.ts +64 -0
  152. package/dist/gem/requirement.js +91 -0
  153. package/dist/gem/requirement.js.map +1 -0
  154. package/dist/gem/version.d.ts +50 -0
  155. package/dist/gem/version.js +148 -0
  156. package/dist/gem/version.js.map +1 -0
  157. package/dist/gem.d.ts +59 -0
  158. package/dist/gem.js +82 -0
  159. package/dist/gem.js.map +1 -0
  160. package/dist/hash.d.ts +967 -0
  161. package/dist/hash.js +1572 -0
  162. package/dist/hash.js.map +1 -0
  163. package/dist/http-adapter.d.ts +123 -0
  164. package/dist/http-adapter.js +220 -0
  165. package/dist/http-adapter.js.map +1 -0
  166. package/dist/immediate-executor.d.ts +20 -0
  167. package/dist/immediate-executor.js +39 -0
  168. package/dist/immediate-executor.js.map +1 -0
  169. package/dist/include.d.ts +778 -0
  170. package/dist/include.js +2195 -0
  171. package/dist/include.js.map +1 -0
  172. package/dist/index-error.d.ts +13 -0
  173. package/dist/index-error.js +13 -0
  174. package/dist/index-error.js.map +1 -0
  175. package/dist/index.d.ts +174 -0
  176. package/dist/index.js +166 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/invalid-byte-sequence-error.d.ts +62 -0
  179. package/dist/invalid-byte-sequence-error.js +75 -0
  180. package/dist/invalid-byte-sequence-error.js.map +1 -0
  181. package/dist/io-error.d.ts +14 -0
  182. package/dist/io-error.js +17 -0
  183. package/dist/io-error.js.map +1 -0
  184. package/dist/io.d.ts +867 -0
  185. package/dist/io.js +1960 -0
  186. package/dist/io.js.map +1 -0
  187. package/dist/ipaddr.d.ts +79 -0
  188. package/dist/ipaddr.js +405 -0
  189. package/dist/ipaddr.js.map +1 -0
  190. package/dist/json.d.ts +67 -0
  191. package/dist/json.js +185 -0
  192. package/dist/json.js.map +1 -0
  193. package/dist/kernel-catch.d.ts +59 -0
  194. package/dist/kernel-catch.js +184 -0
  195. package/dist/kernel-catch.js.map +1 -0
  196. package/dist/kernel-float.d.ts +19 -0
  197. package/dist/kernel-float.js +54 -0
  198. package/dist/kernel-float.js.map +1 -0
  199. package/dist/kernel-fork.d.ts +30 -0
  200. package/dist/kernel-fork.js +72 -0
  201. package/dist/kernel-fork.js.map +1 -0
  202. package/dist/kernel-format.d.ts +27 -0
  203. package/dist/kernel-format.js +901 -0
  204. package/dist/kernel-format.js.map +1 -0
  205. package/dist/kernel-hash.d.ts +7 -0
  206. package/dist/kernel-hash.js +33 -0
  207. package/dist/kernel-hash.js.map +1 -0
  208. package/dist/kernel-integer.d.ts +49 -0
  209. package/dist/kernel-integer.js +170 -0
  210. package/dist/kernel-integer.js.map +1 -0
  211. package/dist/kernel-rand.d.ts +16 -0
  212. package/dist/kernel-rand.js +237 -0
  213. package/dist/kernel-rand.js.map +1 -0
  214. package/dist/kernel-system.d.ts +40 -0
  215. package/dist/kernel-system.js +97 -0
  216. package/dist/kernel-system.js.map +1 -0
  217. package/dist/kernel-warn.d.ts +35 -0
  218. package/dist/kernel-warn.js +73 -0
  219. package/dist/kernel-warn.js.map +1 -0
  220. package/dist/key-error.d.ts +44 -0
  221. package/dist/key-error.js +59 -0
  222. package/dist/key-error.js.map +1 -0
  223. package/dist/keyword-splat.d.ts +41 -0
  224. package/dist/keyword-splat.js +65 -0
  225. package/dist/keyword-splat.js.map +1 -0
  226. package/dist/load-error.d.ts +19 -0
  227. package/dist/load-error.js +19 -0
  228. package/dist/load-error.js.map +1 -0
  229. package/dist/load.d.ts +121 -0
  230. package/dist/load.js +263 -0
  231. package/dist/load.js.map +1 -0
  232. package/dist/loaded-features.d.ts +13 -0
  233. package/dist/loaded-features.js +15 -0
  234. package/dist/loaded-features.js.map +1 -0
  235. package/dist/local-jump-error.d.ts +12 -0
  236. package/dist/local-jump-error.js +12 -0
  237. package/dist/local-jump-error.js.map +1 -0
  238. package/dist/logger/formatter.d.ts +21 -0
  239. package/dist/logger/formatter.js +43 -0
  240. package/dist/logger/formatter.js.map +1 -0
  241. package/dist/logger/log-device.d.ts +52 -0
  242. package/dist/logger/log-device.js +104 -0
  243. package/dist/logger/log-device.js.map +1 -0
  244. package/dist/logger/severity.d.ts +23 -0
  245. package/dist/logger/severity.js +42 -0
  246. package/dist/logger/severity.js.map +1 -0
  247. package/dist/logger.d.ts +127 -0
  248. package/dist/logger.js +215 -0
  249. package/dist/logger.js.map +1 -0
  250. package/dist/marshal.d.ts +83 -0
  251. package/dist/marshal.js +1487 -0
  252. package/dist/marshal.js.map +1 -0
  253. package/dist/match-data.d.ts +161 -0
  254. package/dist/match-data.js +284 -0
  255. package/dist/match-data.js.map +1 -0
  256. package/dist/method-cache.d.ts +17 -0
  257. package/dist/method-cache.js +19 -0
  258. package/dist/method-cache.js.map +1 -0
  259. package/dist/method-missing-proxy.d.ts +53 -0
  260. package/dist/method-missing-proxy.js +154 -0
  261. package/dist/method-missing-proxy.js.map +1 -0
  262. package/dist/method.d.ts +132 -0
  263. package/dist/method.js +320 -0
  264. package/dist/method.js.map +1 -0
  265. package/dist/monitor.d.ts +114 -0
  266. package/dist/monitor.js +270 -0
  267. package/dist/monitor.js.map +1 -0
  268. package/dist/mutex.d.ts +51 -0
  269. package/dist/mutex.js +150 -0
  270. package/dist/mutex.js.map +1 -0
  271. package/dist/name-error.d.ts +45 -0
  272. package/dist/name-error.js +54 -0
  273. package/dist/name-error.js.map +1 -0
  274. package/dist/net/http/exceptions.d.ts +31 -0
  275. package/dist/net/http/exceptions.js +46 -0
  276. package/dist/net/http/exceptions.js.map +1 -0
  277. package/dist/net/http/request.d.ts +137 -0
  278. package/dist/net/http/request.js +559 -0
  279. package/dist/net/http/request.js.map +1 -0
  280. package/dist/net/http/requests.d.ts +197 -0
  281. package/dist/net/http/requests.js +197 -0
  282. package/dist/net/http/requests.js.map +1 -0
  283. package/dist/net/http/response.d.ts +141 -0
  284. package/dist/net/http/response.js +416 -0
  285. package/dist/net/http/response.js.map +1 -0
  286. package/dist/net/http/responses.d.ts +345 -0
  287. package/dist/net/http/responses.js +486 -0
  288. package/dist/net/http/responses.js.map +1 -0
  289. package/dist/net/http.d.ts +278 -0
  290. package/dist/net/http.js +760 -0
  291. package/dist/net/http.js.map +1 -0
  292. package/dist/net/protocol.d.ts +227 -0
  293. package/dist/net/protocol.js +392 -0
  294. package/dist/net/protocol.js.map +1 -0
  295. package/dist/nil-class.d.ts +10 -0
  296. package/dist/nil-class.js +27 -0
  297. package/dist/nil-class.js.map +1 -0
  298. package/dist/no-method-error.d.ts +38 -0
  299. package/dist/no-method-error.js +45 -0
  300. package/dist/no-method-error.js.map +1 -0
  301. package/dist/not-implemented-error.d.ts +13 -0
  302. package/dist/not-implemented-error.js +14 -0
  303. package/dist/not-implemented-error.js.map +1 -0
  304. package/dist/numeric.d.ts +211 -0
  305. package/dist/numeric.js +802 -0
  306. package/dist/numeric.js.map +1 -0
  307. package/dist/object-space.d.ts +34 -0
  308. package/dist/object-space.js +152 -0
  309. package/dist/object-space.js.map +1 -0
  310. package/dist/object.d.ts +908 -0
  311. package/dist/object.js +2238 -0
  312. package/dist/object.js.map +1 -0
  313. package/dist/open-uri.d.ts +180 -0
  314. package/dist/open-uri.js +402 -0
  315. package/dist/open-uri.js.map +1 -0
  316. package/dist/open3.d.ts +69 -0
  317. package/dist/open3.js +134 -0
  318. package/dist/open3.js.map +1 -0
  319. package/dist/openssl.d.ts +479 -0
  320. package/dist/openssl.js +1052 -0
  321. package/dist/openssl.js.map +1 -0
  322. package/dist/optparse.d.ts +130 -0
  323. package/dist/optparse.js +457 -0
  324. package/dist/optparse.js.map +1 -0
  325. package/dist/os-adapter.d.ts +20 -0
  326. package/dist/os-adapter.js +95 -0
  327. package/dist/os-adapter.js.map +1 -0
  328. package/dist/pathname.d.ts +71 -0
  329. package/dist/pathname.js +394 -0
  330. package/dist/pathname.js.map +1 -0
  331. package/dist/pp.d.ts +60 -0
  332. package/dist/pp.js +195 -0
  333. package/dist/pp.js.map +1 -0
  334. package/dist/pretty-print.d.ts +89 -0
  335. package/dist/pretty-print.js +232 -0
  336. package/dist/pretty-print.js.map +1 -0
  337. package/dist/process-adapter.d.ts +224 -0
  338. package/dist/process-adapter.js +878 -0
  339. package/dist/process-adapter.js.map +1 -0
  340. package/dist/process.d.ts +192 -0
  341. package/dist/process.js +403 -0
  342. package/dist/process.js.map +1 -0
  343. package/dist/psych/class-loader.d.ts +92 -0
  344. package/dist/psych/class-loader.js +139 -0
  345. package/dist/psych/class-loader.js.map +1 -0
  346. package/dist/psych/coder.d.ts +144 -0
  347. package/dist/psych/coder.js +176 -0
  348. package/dist/psych/coder.js.map +1 -0
  349. package/dist/psych/core-ext.d.ts +8 -0
  350. package/dist/psych/core-ext.js +10 -0
  351. package/dist/psych/core-ext.js.map +1 -0
  352. package/dist/psych/emitter.d.ts +116 -0
  353. package/dist/psych/emitter.js +1130 -0
  354. package/dist/psych/emitter.js.map +1 -0
  355. package/dist/psych/exception.d.ts +43 -0
  356. package/dist/psych/exception.js +54 -0
  357. package/dist/psych/exception.js.map +1 -0
  358. package/dist/psych/handler.d.ts +59 -0
  359. package/dist/psych/handler.js +95 -0
  360. package/dist/psych/handler.js.map +1 -0
  361. package/dist/psych/handlers/document-stream.d.ts +17 -0
  362. package/dist/psych/handlers/document-stream.js +26 -0
  363. package/dist/psych/handlers/document-stream.js.map +1 -0
  364. package/dist/psych/nodes/alias.d.ts +15 -0
  365. package/dist/psych/nodes/alias.js +22 -0
  366. package/dist/psych/nodes/alias.js.map +1 -0
  367. package/dist/psych/nodes/document.d.ts +23 -0
  368. package/dist/psych/nodes/document.js +35 -0
  369. package/dist/psych/nodes/document.js.map +1 -0
  370. package/dist/psych/nodes/mapping.d.ts +25 -0
  371. package/dist/psych/nodes/mapping.js +35 -0
  372. package/dist/psych/nodes/mapping.js.map +1 -0
  373. package/dist/psych/nodes/node.d.ts +59 -0
  374. package/dist/psych/nodes/node.js +79 -0
  375. package/dist/psych/nodes/node.js.map +1 -0
  376. package/dist/psych/nodes/scalar.d.ts +35 -0
  377. package/dist/psych/nodes/scalar.js +47 -0
  378. package/dist/psych/nodes/scalar.js.map +1 -0
  379. package/dist/psych/nodes/sequence.d.ts +25 -0
  380. package/dist/psych/nodes/sequence.js +35 -0
  381. package/dist/psych/nodes/sequence.js.map +1 -0
  382. package/dist/psych/nodes/stream.d.ts +23 -0
  383. package/dist/psych/nodes/stream.js +31 -0
  384. package/dist/psych/nodes/stream.js.map +1 -0
  385. package/dist/psych/omap.d.ts +9 -0
  386. package/dist/psych/omap.js +9 -0
  387. package/dist/psych/omap.js.map +1 -0
  388. package/dist/psych/parser.d.ts +41 -0
  389. package/dist/psych/parser.js +139 -0
  390. package/dist/psych/parser.js.map +1 -0
  391. package/dist/psych/scalar-scanner.d.ts +35 -0
  392. package/dist/psych/scalar-scanner.js +173 -0
  393. package/dist/psych/scalar-scanner.js.map +1 -0
  394. package/dist/psych/syntax-error.d.ts +23 -0
  395. package/dist/psych/syntax-error.js +35 -0
  396. package/dist/psych/syntax-error.js.map +1 -0
  397. package/dist/psych/tree-builder.d.ts +51 -0
  398. package/dist/psych/tree-builder.js +118 -0
  399. package/dist/psych/tree-builder.js.map +1 -0
  400. package/dist/psych/visitors/depth-first.d.ts +27 -0
  401. package/dist/psych/visitors/depth-first.js +37 -0
  402. package/dist/psych/visitors/depth-first.js.map +1 -0
  403. package/dist/psych/visitors/emitter.d.ts +32 -0
  404. package/dist/psych/visitors/emitter.js +63 -0
  405. package/dist/psych/visitors/emitter.js.map +1 -0
  406. package/dist/psych/visitors/to-ruby.d.ts +110 -0
  407. package/dist/psych/visitors/to-ruby.js +396 -0
  408. package/dist/psych/visitors/to-ruby.js.map +1 -0
  409. package/dist/psych/visitors/visitor.d.ts +11 -0
  410. package/dist/psych/visitors/visitor.js +17 -0
  411. package/dist/psych/visitors/visitor.js.map +1 -0
  412. package/dist/psych/visitors/yaml-tree.d.ts +182 -0
  413. package/dist/psych/visitors/yaml-tree.js +593 -0
  414. package/dist/psych/visitors/yaml-tree.js.map +1 -0
  415. package/dist/psych-adapter.d.ts +65 -0
  416. package/dist/psych-adapter.js +121 -0
  417. package/dist/psych-adapter.js.map +1 -0
  418. package/dist/psych-yaml.d.ts +2 -0
  419. package/dist/psych-yaml.js +5 -0
  420. package/dist/psych-yaml.js.map +1 -0
  421. package/dist/psych.d.ts +257 -0
  422. package/dist/psych.js +332 -0
  423. package/dist/psych.js.map +1 -0
  424. package/dist/queue.d.ts +129 -0
  425. package/dist/queue.js +215 -0
  426. package/dist/queue.js.map +1 -0
  427. package/dist/racc/parser.d.ts +70 -0
  428. package/dist/racc/parser.js +206 -0
  429. package/dist/racc/parser.js.map +1 -0
  430. package/dist/range-error.d.ts +15 -0
  431. package/dist/range-error.js +15 -0
  432. package/dist/range-error.js.map +1 -0
  433. package/dist/range.d.ts +166 -0
  434. package/dist/range.js +421 -0
  435. package/dist/range.js.map +1 -0
  436. package/dist/rational.d.ts +167 -0
  437. package/dist/rational.js +379 -0
  438. package/dist/rational.js.map +1 -0
  439. package/dist/rb-config.d.ts +33 -0
  440. package/dist/rb-config.js +53 -0
  441. package/dist/rb-config.js.map +1 -0
  442. package/dist/rb-equal.d.ts +66 -0
  443. package/dist/rb-equal.js +261 -0
  444. package/dist/rb-equal.js.map +1 -0
  445. package/dist/rb-hash.d.ts +26 -0
  446. package/dist/rb-hash.js +108 -0
  447. package/dist/rb-hash.js.map +1 -0
  448. package/dist/regexp.d.ts +82 -0
  449. package/dist/regexp.js +191 -0
  450. package/dist/regexp.js.map +1 -0
  451. package/dist/repl-adapter.d.ts +188 -0
  452. package/dist/repl-adapter.js +388 -0
  453. package/dist/repl-adapter.js.map +1 -0
  454. package/dist/resolv.d.ts +30 -0
  455. package/dist/resolv.js +48 -0
  456. package/dist/resolv.js.map +1 -0
  457. package/dist/ruby-empty.d.ts +28 -0
  458. package/dist/ruby-empty.js +40 -0
  459. package/dist/ruby-empty.js.map +1 -0
  460. package/dist/ruby-platform.d.ts +39 -0
  461. package/dist/ruby-platform.js +49 -0
  462. package/dist/ruby-platform.js.map +1 -0
  463. package/dist/runtime-error.d.ts +15 -0
  464. package/dist/runtime-error.js +16 -0
  465. package/dist/runtime-error.js.map +1 -0
  466. package/dist/scheduled-task.d.ts +73 -0
  467. package/dist/scheduled-task.js +150 -0
  468. package/dist/scheduled-task.js.map +1 -0
  469. package/dist/secure-random.d.ts +33 -0
  470. package/dist/secure-random.js +78 -0
  471. package/dist/secure-random.js.map +1 -0
  472. package/dist/set.d.ts +158 -0
  473. package/dist/set.js +352 -0
  474. package/dist/set.js.map +1 -0
  475. package/dist/shellwords.d.ts +27 -0
  476. package/dist/shellwords.js +53 -0
  477. package/dist/shellwords.js.map +1 -0
  478. package/dist/signal-exception.d.ts +21 -0
  479. package/dist/signal-exception.js +21 -0
  480. package/dist/signal-exception.js.map +1 -0
  481. package/dist/socket.d.ts +230 -0
  482. package/dist/socket.js +484 -0
  483. package/dist/socket.js.map +1 -0
  484. package/dist/standard-error.d.ts +18 -0
  485. package/dist/standard-error.js +23 -0
  486. package/dist/standard-error.js.map +1 -0
  487. package/dist/stop-iteration.d.ts +10 -0
  488. package/dist/stop-iteration.js +10 -0
  489. package/dist/stop-iteration.js.map +1 -0
  490. package/dist/string/b.d.ts +19 -0
  491. package/dist/string/b.js +28 -0
  492. package/dist/string/b.js.map +1 -0
  493. package/dist/string/byte-methods.d.ts +57 -0
  494. package/dist/string/byte-methods.js +266 -0
  495. package/dist/string/byte-methods.js.map +1 -0
  496. package/dist/string/bytes.d.ts +35 -0
  497. package/dist/string/bytes.js +123 -0
  498. package/dist/string/bytes.js.map +1 -0
  499. package/dist/string/case-mapping.d.ts +57 -0
  500. package/dist/string/case-mapping.js +192 -0
  501. package/dist/string/case-mapping.js.map +1 -0
  502. package/dist/string/chomp.d.ts +15 -0
  503. package/dist/string/chomp.js +32 -0
  504. package/dist/string/chomp.js.map +1 -0
  505. package/dist/string/convert.d.ts +55 -0
  506. package/dist/string/convert.js +316 -0
  507. package/dist/string/convert.js.map +1 -0
  508. package/dist/string/delete.d.ts +14 -0
  509. package/dist/string/delete.js +17 -0
  510. package/dist/string/delete.js.map +1 -0
  511. package/dist/string/each.d.ts +108 -0
  512. package/dist/string/each.js +305 -0
  513. package/dist/string/each.js.map +1 -0
  514. package/dist/string/encode.d.ts +37 -0
  515. package/dist/string/encode.js +268 -0
  516. package/dist/string/encode.js.map +1 -0
  517. package/dist/string/force-encoding.d.ts +72 -0
  518. package/dist/string/force-encoding.js +147 -0
  519. package/dist/string/force-encoding.js.map +1 -0
  520. package/dist/string/inspect.d.ts +17 -0
  521. package/dist/string/inspect.js +81 -0
  522. package/dist/string/inspect.js.map +1 -0
  523. package/dist/string/method-table.d.ts +174 -0
  524. package/dist/string/method-table.js +805 -0
  525. package/dist/string/method-table.js.map +1 -0
  526. package/dist/string/scrub.d.ts +12 -0
  527. package/dist/string/scrub.js +33 -0
  528. package/dist/string/scrub.js.map +1 -0
  529. package/dist/string/slice.d.ts +26 -0
  530. package/dist/string/slice.js +73 -0
  531. package/dist/string/slice.js.map +1 -0
  532. package/dist/string/split.d.ts +11 -0
  533. package/dist/string/split.js +44 -0
  534. package/dist/string/split.js.map +1 -0
  535. package/dist/string/sub.d.ts +114 -0
  536. package/dist/string/sub.js +371 -0
  537. package/dist/string/sub.js.map +1 -0
  538. package/dist/string/succ.d.ts +14 -0
  539. package/dist/string/succ.js +118 -0
  540. package/dist/string/succ.js.map +1 -0
  541. package/dist/string/support.d.ts +135 -0
  542. package/dist/string/support.js +283 -0
  543. package/dist/string/support.js.map +1 -0
  544. package/dist/string/tr.d.ts +46 -0
  545. package/dist/string/tr.js +156 -0
  546. package/dist/string/tr.js.map +1 -0
  547. package/dist/string-io.d.ts +166 -0
  548. package/dist/string-io.js +248 -0
  549. package/dist/string-io.js.map +1 -0
  550. package/dist/string-scanner.d.ts +133 -0
  551. package/dist/string-scanner.js +248 -0
  552. package/dist/string-scanner.js.map +1 -0
  553. package/dist/struct.d.ts +54 -0
  554. package/dist/struct.js +222 -0
  555. package/dist/struct.js.map +1 -0
  556. package/dist/symbol.d.ts +48 -0
  557. package/dist/symbol.js +107 -0
  558. package/dist/symbol.js.map +1 -0
  559. package/dist/tempfile.d.ts +173 -0
  560. package/dist/tempfile.js +290 -0
  561. package/dist/tempfile.js.map +1 -0
  562. package/dist/temporal-tag.d.ts +23 -0
  563. package/dist/temporal-tag.js +29 -0
  564. package/dist/temporal-tag.js.map +1 -0
  565. package/dist/thread-error.d.ts +13 -0
  566. package/dist/thread-error.js +13 -0
  567. package/dist/thread-error.js.map +1 -0
  568. package/dist/thread-pool-executor.d.ts +119 -0
  569. package/dist/thread-pool-executor.js +250 -0
  570. package/dist/thread-pool-executor.js.map +1 -0
  571. package/dist/thread.d.ts +211 -0
  572. package/dist/thread.js +495 -0
  573. package/dist/thread.js.map +1 -0
  574. package/dist/timeout.d.ts +29 -0
  575. package/dist/timeout.js +41 -0
  576. package/dist/timeout.js.map +1 -0
  577. package/dist/tse.d.ts +40 -0
  578. package/dist/tse.js +62 -0
  579. package/dist/tse.js.map +1 -0
  580. package/dist/type-error.d.ts +14 -0
  581. package/dist/type-error.js +15 -0
  582. package/dist/type-error.js.map +1 -0
  583. package/dist/undefined-conversion-error.d.ts +10 -0
  584. package/dist/undefined-conversion-error.js +10 -0
  585. package/dist/undefined-conversion-error.js.map +1 -0
  586. package/dist/uri/common.d.ts +209 -0
  587. package/dist/uri/common.js +369 -0
  588. package/dist/uri/common.js.map +1 -0
  589. package/dist/uri/generic.d.ts +283 -0
  590. package/dist/uri/generic.js +810 -0
  591. package/dist/uri/generic.js.map +1 -0
  592. package/dist/uri/http.d.ts +23 -0
  593. package/dist/uri/http.js +30 -0
  594. package/dist/uri/http.js.map +1 -0
  595. package/dist/uri/https.d.ts +13 -0
  596. package/dist/uri/https.js +15 -0
  597. package/dist/uri/https.js.map +1 -0
  598. package/dist/uri/rfc2396-parser.d.ts +70 -0
  599. package/dist/uri/rfc2396-parser.js +264 -0
  600. package/dist/uri/rfc2396-parser.js.map +1 -0
  601. package/dist/uri/rfc3986-parser.d.ts +46 -0
  602. package/dist/uri/rfc3986-parser.js +171 -0
  603. package/dist/uri/rfc3986-parser.js.map +1 -0
  604. package/dist/uri.d.ts +13 -0
  605. package/dist/uri.js +13 -0
  606. package/dist/uri.js.map +1 -0
  607. package/dist/variable.d.ts +183 -0
  608. package/dist/variable.js +463 -0
  609. package/dist/variable.js.map +1 -0
  610. package/dist/verbose.d.ts +21 -0
  611. package/dist/verbose.js +26 -0
  612. package/dist/verbose.js.map +1 -0
  613. package/dist/yaml.d.ts +9 -0
  614. package/dist/yaml.js +9 -0
  615. package/dist/yaml.js.map +1 -0
  616. package/dist/zlib-adapter.d.ts +117 -0
  617. package/dist/zlib-adapter.js +250 -0
  618. package/dist/zlib-adapter.js.map +1 -0
  619. package/dist/zlib.d.ts +248 -0
  620. package/dist/zlib.js +362 -0
  621. package/dist/zlib.js.map +1 -0
  622. package/package.json +82 -3
package/dist/io.js ADDED
@@ -0,0 +1,1960 @@
1
+ import { rbInspect, rbObjAsString, rtest } from "./object.js";
2
+ import { ConverterNotFoundError } from "./converter-not-found-error.js";
3
+ import { InvalidByteSequenceError } from "./invalid-byte-sequence-error.js";
4
+ import { Encoding } from "./encoding.js";
5
+ import { b } from "./string/b.js";
6
+ import { getFs, getPath } from "./fs-adapter.js";
7
+ import { EOFError } from "./eof-error.js";
8
+ import { IOError } from "./io-error.js";
9
+ import { ArgumentError } from "./argument-error.js";
10
+ import { env, stderr, stdout } from "./process-adapter.js";
11
+ import { rbStrToI } from "./string/convert.js";
12
+ import { verbose } from "./verbose.js";
13
+ import { Errno } from "./errno.js";
14
+ import { format } from "./kernel-format.js";
15
+ import { NotImplementedError } from "./not-implemented-error.js";
16
+ import { Process, rbExecargNew, rbLastStatusSet } from "./process.js";
17
+ import { StringIO } from "./string-io.js";
18
+ /** The `rb_exec_recursive` guard `io_puts_ary` (`vendor/ruby/v3.3.11/io.c:8880`) is called through. */
19
+ const putsAryInFlight = new Set();
20
+ /**
21
+ * `rb_io_puts` (`vendor/ruby/v3.3.11/io.c:8947`), reached both as `IO#puts`
22
+ * (`io.c:15459`) and, through `IO::generic_writable`, as `StringIO#puts`
23
+ * (`vendor/ruby/v3.3.11/ext/stringio/stringio.c:1530`) — one body, two receivers, which
24
+ * is why it lives here rather than beside `StringIO`.
25
+ *
26
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#puts` (`vendor/ruby/v3.3.11/io.c:8947`).
27
+ */
28
+ export function puts(...args) {
29
+ if (args.length === 0) {
30
+ this.write("\n");
31
+ return null;
32
+ }
33
+ for (let i = 0; i < args.length; i++) {
34
+ let line;
35
+ if (typeof args[i] === "string") {
36
+ line = args[i];
37
+ }
38
+ else if (Array.isArray(args[i])) {
39
+ ioPutsAry.call(this, args[i]);
40
+ continue;
41
+ }
42
+ else {
43
+ line = args[i] == null ? "" : String(args[i]);
44
+ }
45
+ if (line.length === 0) {
46
+ this.write("\n");
47
+ }
48
+ else {
49
+ this.write(line);
50
+ if (!line.endsWith("\n"))
51
+ this.write("\n");
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+ /**
57
+ * `io_puts_ary` (`vendor/ruby/v3.3.11/io.c:8880`), the recursion guard `rb_io_puts`
58
+ * reaches an Array argument through.
59
+ *
60
+ * @noRailsEquivalent PERMANENT — Ruby core `io_puts_ary`
61
+ * (`vendor/ruby/v3.3.11/io.c:8880`).
62
+ */
63
+ export function ioPutsAry(ary) {
64
+ if (putsAryInFlight.has(ary)) {
65
+ puts.call(this, "[...]");
66
+ return;
67
+ }
68
+ putsAryInFlight.add(ary);
69
+ try {
70
+ for (let i = 0; i < ary.length; i++) {
71
+ puts.call(this, ary[i]);
72
+ }
73
+ }
74
+ finally {
75
+ putsAryInFlight.delete(ary);
76
+ }
77
+ }
78
+ /**
79
+ * `rb_io_print` (`vendor/ruby/v3.3.11/io.c:8715`) with `$,` nil: each
80
+ * argument's `to_s`, written with no separator, answering `nil`. Shared by
81
+ * `IO#print` and `StringIO#print` the way {@link puts} is.
82
+ *
83
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#print` (`vendor/ruby/v3.3.11/io.c:8715`).
84
+ */
85
+ export function print(...args) {
86
+ for (const arg of args)
87
+ this.write(arg == null ? "" : String(arg));
88
+ if (args.length > 0 && rbOutputRs.value != null)
89
+ this.write(rbOutputRs.value);
90
+ return null;
91
+ }
92
+ /**
93
+ * `rb_io_printf` (`vendor/ruby/v3.3.11/io.c:8589`), `IO#printf`:
94
+ * `rb_f_sprintf`'s String, written to the receiver, answering `nil`. The
95
+ * `printf(io, format_string, *objects)` form and the no-argument `nil` belong
96
+ * to `Kernel#printf` (`rb_f_printf`, `vendor/ruby/v3.3.11/io.c:8630`), a
97
+ * separate function that is not ported; `rb_f_sprintf` raises "too few
98
+ * arguments" for an `IO#printf` with none, which `fmt` being required stands
99
+ * in for.
100
+ *
101
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#printf` (`vendor/ruby/v3.3.11/io.c:8589`).
102
+ */
103
+ export function printf(fmt, ...argv) {
104
+ this.write(format(fmt, ...argv));
105
+ return null;
106
+ }
107
+ /**
108
+ * `$\` (`rb_output_rs`, `vendor/ruby/v3.3.11/io.c:195`).
109
+ *
110
+ * @noRailsEquivalent PERMANENT
111
+ */
112
+ export const rbOutputRs = { value: null };
113
+ /** `vendor/ruby/v3.3.11/io.c:160` `IO_RBUF_CAPA_MIN`, the read buffer Ruby fills. */
114
+ const READ_CHUNK = 8192;
115
+ /**
116
+ * The ASCII-8BIT String a binary read answers (`rb_ascii8bit_encoding`,
117
+ * `vendor/ruby/v3.3.11/io.c:12257`): one character per byte. It is assembled a
118
+ * character at a time because no `TextDecoder` encoding gives it — its
119
+ * "latin1" is windows-1252, which remaps 0x80-0x9F.
120
+ *
121
+ * @noRailsEquivalent PERMANENT
122
+ */
123
+ export function binaryString(bytes, length = bytes.length) {
124
+ let part = "";
125
+ for (let i = 0; i < length; i++)
126
+ part += String.fromCharCode(bytes[i]);
127
+ return part;
128
+ }
129
+ /**
130
+ * The bytes `io_write_m` (`vendor/ruby/v3.3.11/io.c:2263`) sends an ASCII-8BIT String as.
131
+ *
132
+ * @noRailsEquivalent PERMANENT
133
+ */
134
+ export function binaryBytes(string) {
135
+ const buffer = new Uint8Array(string.length);
136
+ for (let i = 0; i < string.length; i++)
137
+ buffer[i] = string.charCodeAt(i) & 0xff;
138
+ return buffer;
139
+ }
140
+ /**
141
+ * `io_enc_str` (`vendor/ruby/v3.3.11/io.c:3123`), which tags the String a read
142
+ * assembled with `io_read_encoding` (`io.c:1010`). ASCII-8BIT is the one
143
+ * encoding assembled a character at a time (see {@link binaryString}); every
144
+ * other reaches the platform decoder its registry row names. An encoding whose
145
+ * row names no decoder is a converter this platform lacks and MRI has, so it
146
+ * raises what `rb_econv_open_exc` (`vendor/ruby/v3.3.11/transcode.c:2097-2105`) raises
147
+ * — the treatment {@link doWriteconv} already gives the write half — rather
148
+ * than leaking `TextDecoder`'s own `RangeError`; the two UTF-32 seats are
149
+ * decoded here instead, being a four-byte-per-code-point read, and the two
150
+ * dummy seats `UTF-16` and `UTF-32` dispatch on the BOM the way
151
+ * {@link funSiFromUtf16} and {@link funSiFromUtf32} do, so a BOM-prefixed
152
+ * stream reads through the concrete seat the BOM names.
153
+ */
154
+ function ioEncStr(bytes, length, enc, destination = null) {
155
+ if (enc === Encoding.ASCII_8BIT)
156
+ return bytes.slice(0, length);
157
+ const read = bytes.subarray(0, length);
158
+ if (enc.decoderLabel === null) {
159
+ if (destination === null && (enc.name === "UTF-16" || enc.name === "UTF-32")) {
160
+ return binaryString(bytes, length);
161
+ }
162
+ if (enc.name === "UTF-32BE" || enc.name === "UTF-32LE") {
163
+ return utf32Str(read, enc.name === "UTF-32LE");
164
+ }
165
+ if (enc.name === "UTF-16") {
166
+ const sp = funSiFromUtf16(read);
167
+ if (sp !== 0) {
168
+ if (read.length % 2 !== 0) {
169
+ throw invalidByteSequence(read.subarray(read.length - 1), enc, destination);
170
+ }
171
+ return new TextDecoder(sp === LE ? "utf-16le" : "utf-16be").decode(read.subarray(2));
172
+ }
173
+ if (read.length === 0)
174
+ return "";
175
+ throw invalidByteSequence(read.subarray(0, 2), enc, destination);
176
+ }
177
+ if (enc.name === "UTF-32") {
178
+ const sp = funSiFromUtf32(read);
179
+ if (sp !== 0) {
180
+ if (read.length % 4 !== 0) {
181
+ throw invalidByteSequence(read.subarray(read.length - (read.length % 4)), enc, destination);
182
+ }
183
+ return utf32Str(read.subarray(4), sp === LE);
184
+ }
185
+ if (read.length === 0)
186
+ return "";
187
+ throw invalidByteSequence(read.subarray(0, 4), enc, destination);
188
+ }
189
+ throw new ConverterNotFoundError(`code converter not found (${enc} to UTF-8)`);
190
+ }
191
+ return new TextDecoder(enc.decoderLabel).decode(read);
192
+ }
193
+ /**
194
+ * `rb_str_dump` (`vendor/ruby/v3.3.11/string.c:6901`) over the bytes of an ASCII-8BIT
195
+ * String, as `rb_econv_open_exc`'s sibling `make_econv_exception`
196
+ * (`vendor/ruby/v3.3.11/transcode.c:2116`) quotes the bytes a converter rejected.
197
+ */
198
+ function rbStrDump(bytes) {
199
+ const escapes = {
200
+ 0x22: '\\"',
201
+ 0x5c: "\\\\",
202
+ 0x0a: "\\n",
203
+ 0x0d: "\\r",
204
+ 0x09: "\\t",
205
+ 0x0c: "\\f",
206
+ 0x0b: "\\v",
207
+ 0x08: "\\b",
208
+ 0x07: "\\a",
209
+ 0x1b: "\\e",
210
+ };
211
+ let result = '"';
212
+ for (let i = 0; i < bytes.length; i++) {
213
+ const c = bytes[i];
214
+ if (escapes[c] !== undefined)
215
+ result += escapes[c];
216
+ else if (c === 0x23 &&
217
+ i + 1 < bytes.length &&
218
+ "$@{".includes(String.fromCharCode(bytes[i + 1])))
219
+ result += "\\#";
220
+ else if (c >= 0x20 && c < 0x7f)
221
+ result += String.fromCharCode(c);
222
+ else
223
+ result += `\\x${c.toString(16).toUpperCase().padStart(2, "0")}`;
224
+ }
225
+ return result + '"';
226
+ }
227
+ /**
228
+ * The `econv_invalid_byte_sequence` / `econv_incomplete_input` arm of
229
+ * `make_econv_exception` (`vendor/ruby/v3.3.11/transcode.c:2111-2144`): a dummy seat's
230
+ * converter rejects its first code unit, or runs out of input before one is
231
+ * whole (`vendor/ruby/v3.3.11/enc/trans/utf_16_32.trans:290,310`).
232
+ */
233
+ function invalidByteSequence(errorBytes, source, destination) {
234
+ const incompleteInput = errorBytes.length < (source.name === "UTF-16" ? 2 : 4);
235
+ const dumped = rbStrDump(errorBytes);
236
+ const mesg = incompleteInput ? `incomplete ${dumped} on ${source}` : `${dumped} on ${source}`;
237
+ const exc = new InvalidByteSequenceError(mesg);
238
+ exc._errorBytes = binaryString(errorBytes, errorBytes.length);
239
+ exc._readagainBytes = null;
240
+ exc._incompleteInput = incompleteInput;
241
+ exc._sourceEncoding = source;
242
+ exc._destinationEncoding = destination;
243
+ return exc;
244
+ }
245
+ /** `BE` (`vendor/ruby/v3.3.11/enc/trans/utf_16_32.trans:281`). */
246
+ const BE = 1;
247
+ /** `LE` (`vendor/ruby/v3.3.11/enc/trans/utf_16_32.trans:282`). */
248
+ const LE = 2;
249
+ /**
250
+ * `fun_si_from_utf_16` (`vendor/ruby/v3.3.11/enc/trans/utf_16_32.trans:278`) — the
251
+ * state function MRI's dummy `UTF-16` decodes through: a leading `FE FF`
252
+ * re-points the stream at the `UTF-16BE` seat and `FF FE` at the `UTF-16LE`
253
+ * one, the BOM itself producing no output (`ZERObt`), and a stream carrying
254
+ * neither takes the `INVALID` arm. The registry row stays `null` because
255
+ * WHATWG's `utf-16` label is a plain alias of `utf-16le` and mojibakes
256
+ * BE-BOM'd bytes; the BOM dispatch is what the row is missing, not a label.
257
+ */
258
+ function funSiFromUtf16(s) {
259
+ if (s.length >= 2) {
260
+ if (s[0] === 0xfe && s[1] === 0xff)
261
+ return BE;
262
+ if (s[0] === 0xff && s[1] === 0xfe)
263
+ return LE;
264
+ }
265
+ return 0;
266
+ }
267
+ /**
268
+ * `fun_si_from_utf_32` (`vendor/ruby/v3.3.11/enc/trans/utf_16_32.trans:327`), the
269
+ * four-byte twin of {@link funSiFromUtf16}: `00 00 FE FF` re-points at the
270
+ * `UTF-32BE` seat and `FF FE 00 00` at the `UTF-32LE` one.
271
+ */
272
+ function funSiFromUtf32(s) {
273
+ if (s.length >= 4) {
274
+ if (s[0] === 0 && s[1] === 0 && s[2] === 0xfe && s[3] === 0xff)
275
+ return BE;
276
+ if (s[0] === 0xff && s[1] === 0xfe && s[2] === 0 && s[3] === 0)
277
+ return LE;
278
+ }
279
+ return 0;
280
+ }
281
+ /**
282
+ * The `UTF-32BE` / `UTF-32LE` decode `TextDecoder` has no label for: four
283
+ * bytes per code point (`vendor/ruby/v3.3.11/enc/utf_32le.c:44` `utf32le_mbc_to_code`,
284
+ * `enc/utf_32be.c:43`), which is a small enough transcode to carry rather
285
+ * than raising where MRI reads. A code point outside Unicode takes the
286
+ * replacement character its sibling arm's `TextDecoder` substitutes for
287
+ * malformed input, rather than `String.fromCodePoint`'s own `RangeError`.
288
+ */
289
+ function utf32Str(bytes, littleEndian) {
290
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
291
+ let string = "";
292
+ for (let at = 0; at + 4 <= view.byteLength; at += 4) {
293
+ const code = view.getUint32(at, littleEndian);
294
+ const valid = code <= 0x10ffff && (code < 0xd800 || code > 0xdfff);
295
+ string += valid ? String.fromCodePoint(code) : "\ufffd";
296
+ }
297
+ return string;
298
+ }
299
+ /**
300
+ * `do_writeconv` (`vendor/ruby/v3.3.11/io.c:1904`) over `NEED_WRITECONV`
301
+ * (`io.c:714`): a stream carrying an external encoding other than ASCII-8BIT
302
+ * transcodes the String to it (`common_encoding`, `io.c:1925-1926`), and one
303
+ * carrying none — or carrying ASCII-8BIT — writes the String's own bytes,
304
+ * which for a JS string, a UTF-8 String, is its UTF-8: binmode suppresses the
305
+ * transcode and nothing else. An ASCII-8BIT String's bytes reach
306
+ * {@link IO#write} as a `Uint8Array`.
307
+ * `TextEncoder` produces UTF-8 and nothing else, so UTF-8 is the only
308
+ * `common_encoding` the transcode arm can reach; every other raises what
309
+ * `rb_econv_open` raises for a pair it has no converter for
310
+ * (`rb_econv_open_exc`, `vendor/ruby/v3.3.11/transcode.c:2097-2105`) rather than
311
+ * writing the bytes of an encoding the stream did not ask for.
312
+ */
313
+ function doWriteconv(string, enc) {
314
+ if (enc !== null && enc !== Encoding.ASCII_8BIT && enc !== Encoding.UTF_8) {
315
+ throw new ConverterNotFoundError(`code converter not found (UTF-8 to ${enc})`);
316
+ }
317
+ return new TextEncoder().encode(string);
318
+ }
319
+ /** `FMODE_READABLE` (`vendor/ruby/v3.3.11/include/ruby/io.h:270`). */
320
+ const FMODE_READABLE = 0x00000001;
321
+ /** `FMODE_WRITABLE` (`vendor/ruby/v3.3.11/include/ruby/io.h:273`). */
322
+ const FMODE_WRITABLE = 0x00000002;
323
+ /** `FMODE_READWRITE` (`vendor/ruby/v3.3.11/include/ruby/io.h:276`). */
324
+ const FMODE_READWRITE = FMODE_READABLE | FMODE_WRITABLE;
325
+ /** `FMODE_BINMODE` (`vendor/ruby/v3.3.11/include/ruby/io.h:287`). */
326
+ const FMODE_BINMODE = 0x00000004;
327
+ /** `FMODE_SYNC` (`vendor/ruby/v3.3.11/include/ruby/io.h:294`). */
328
+ const FMODE_SYNC = 0x00000008;
329
+ /** `FMODE_APPEND` (`vendor/ruby/v3.3.11/include/ruby/io.h:315`). */
330
+ const FMODE_APPEND = 0x00000040;
331
+ /** `FMODE_CREATE` (`vendor/ruby/v3.3.11/include/ruby/io.h:323`). */
332
+ const FMODE_CREATE = 0x00000080;
333
+ /** `FMODE_EXCL` (`vendor/ruby/v3.3.11/include/ruby/io.h:331`). */
334
+ const FMODE_EXCL = 0x00000400;
335
+ /** `FMODE_TRUNC` (`vendor/ruby/v3.3.11/include/ruby/io.h:337`). */
336
+ const FMODE_TRUNC = 0x00000800;
337
+ /** `FMODE_TEXTMODE` (`vendor/ruby/v3.3.11/include/ruby/io.h:351`). */
338
+ const FMODE_TEXTMODE = 0x00001000;
339
+ /** `FMODE_SETENC_BY_BOM` (`vendor/ruby/v3.3.11/include/ruby/io.h:368`). */
340
+ const FMODE_SETENC_BY_BOM = 0x00100000;
341
+ /** `bom_prefix` (`vendor/ruby/v3.3.11/io.c:6431`). */
342
+ const bomPrefix = "bom|";
343
+ /** `utf_prefix` (`vendor/ruby/v3.3.11/io.c:6432`). */
344
+ const utfPrefix = "utf-";
345
+ /** `bom_prefix_len` (`vendor/ruby/v3.3.11/io.c:6433`). */
346
+ const bomPrefixLen = bomPrefix.length;
347
+ /** `utf_prefix_len` (`vendor/ruby/v3.3.11/io.c:6434`). */
348
+ const utfPrefixLen = utfPrefix.length;
349
+ /** `io_encname_bom_p` (`vendor/ruby/v3.3.11/io.c:6437`). */
350
+ function ioEncnameBomP(name, len) {
351
+ return len > bomPrefixLen && name.slice(0, bomPrefixLen).toLowerCase() === bomPrefix;
352
+ }
353
+ /**
354
+ * `rb_enc_warn` (`vendor/ruby/v3.3.11/error.c:443`), which writes nothing at all while
355
+ * `$VERBOSE` is `nil` and terminates the message with a newline.
356
+ */
357
+ function rbEncWarn(message) {
358
+ if (verbose() == null)
359
+ return;
360
+ stderr.write(`${message}\n`);
361
+ }
362
+ /**
363
+ * `rb_io_modestr_fmode` (`vendor/ruby/v3.3.11/io.c:6443`) — the `FMODE_*` flags a mode
364
+ * string names, which `rb_io_extract_modeenc` (`io.c:6881`) records on the
365
+ * stream as `fptr->mode`.
366
+ */
367
+ function rbIoModestrFmode(modestr) {
368
+ let fmode = 0;
369
+ let m = 0;
370
+ switch (modestr[m++]) {
371
+ case "r":
372
+ fmode |= FMODE_READABLE;
373
+ break;
374
+ case "w":
375
+ fmode |= FMODE_WRITABLE | FMODE_TRUNC | FMODE_CREATE;
376
+ break;
377
+ case "a":
378
+ fmode |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE;
379
+ break;
380
+ default:
381
+ throw new ArgumentError(`invalid access mode ${modestr}`);
382
+ }
383
+ while (m < modestr.length) {
384
+ const c = modestr[m++];
385
+ switch (c) {
386
+ case "b":
387
+ fmode |= FMODE_BINMODE;
388
+ break;
389
+ case "t":
390
+ fmode |= FMODE_TEXTMODE;
391
+ break;
392
+ case "+":
393
+ fmode |= FMODE_READWRITE;
394
+ break;
395
+ case "x":
396
+ if (modestr[0] !== "w")
397
+ throw new ArgumentError(`invalid access mode ${modestr}`);
398
+ fmode |= FMODE_EXCL;
399
+ break;
400
+ default:
401
+ throw new ArgumentError(`invalid access mode ${modestr}`);
402
+ case ":": {
403
+ const p = modestr.indexOf(":", m);
404
+ if (ioEncnameBomP(modestr.slice(m), (p === -1 ? modestr.length : p) - m)) {
405
+ fmode |= FMODE_SETENC_BY_BOM;
406
+ }
407
+ m = modestr.length;
408
+ break;
409
+ }
410
+ }
411
+ }
412
+ if (fmode & FMODE_BINMODE && fmode & FMODE_TEXTMODE) {
413
+ throw new ArgumentError(`invalid access mode ${modestr}`);
414
+ }
415
+ return fmode;
416
+ }
417
+ /**
418
+ * `rb_io_ext_int_to_encs` (`vendor/ruby/v3.3.11/io.c:6604`) — the pair of encodings a
419
+ * stream records, given an external and an internal one. `enc` is the INTERNAL
420
+ * of a transcoding pair and `enc2` the external, which is why
421
+ * {@link IO#externalEncoding} answers `enc2` first.
422
+ *
423
+ * Ruby distinguishes `NULL` (no encoding given, so fall back to a default) from
424
+ * `Qnil` (one was given and it means "no transcoding"); `undefined` is the
425
+ * former here and `null` the latter.
426
+ */
427
+ function rbIoExtIntToEncs(ext, intern, fmode = 0) {
428
+ let defaultExt = false;
429
+ if (ext == null) {
430
+ ext = Encoding.defaultExternal;
431
+ defaultExt = true;
432
+ }
433
+ if (ext === Encoding.ASCII_8BIT) {
434
+ intern = undefined;
435
+ }
436
+ else if (intern === undefined) {
437
+ intern = Encoding.defaultInternal;
438
+ }
439
+ if (intern == null || (!(fmode & FMODE_SETENC_BY_BOM) && intern === ext)) {
440
+ return { enc: defaultExt && intern !== ext ? null : ext, enc2: null };
441
+ }
442
+ return { enc: intern, enc2: ext };
443
+ }
444
+ /**
445
+ * `parse_mode_enc` (`vendor/ruby/v3.3.11/io.c:6657`), which reads one string as `"enc"`,
446
+ * `"enc2:enc"` or `"enc:-"` — the form both a mode string's encoding half and
447
+ * `IO#set_encoding`'s one-argument String take — and strips the `"bom|"` prefix
448
+ * `rb_io_modestr_fmode` already flagged, keeping `FMODE_SETENC_BY_BOM` only for
449
+ * a UTF encoding (`io.c:6671-6681`).
450
+ *
451
+ * MRI's `fmode_p` is an in/out pointer, `NULL` where the caller has no mode to
452
+ * thread (`io_encoding_set`, `io.c:11706`); here it is the `fmode` argument and
453
+ * the `fmode` the result carries back.
454
+ */
455
+ function parseModeEnc(estr, fmodeIn = 0) {
456
+ let fmode = fmodeIn;
457
+ const p = estr.lastIndexOf(":");
458
+ let start = 0;
459
+ let len = p === -1 ? estr.length : p;
460
+ if (fmode & FMODE_SETENC_BY_BOM || ioEncnameBomP(estr, len)) {
461
+ start += bomPrefixLen;
462
+ len -= bomPrefixLen;
463
+ if (estr.slice(start, start + utfPrefixLen).toLowerCase() === utfPrefix) {
464
+ fmode |= FMODE_SETENC_BY_BOM;
465
+ }
466
+ else {
467
+ rbEncWarn(`BOM with non-UTF encoding ${estr.slice(start)} is nonsense`);
468
+ fmode &= ~FMODE_SETENC_BY_BOM;
469
+ }
470
+ }
471
+ const ext = len === 0 ? undefined : Encoding.find(estr.slice(start, start + len));
472
+ let intern;
473
+ if (p !== -1) {
474
+ const name = estr.slice(p + 1);
475
+ if (name === "-") {
476
+ intern = null;
477
+ }
478
+ else {
479
+ const idx2 = Encoding.find(name);
480
+ intern = !(fmode & FMODE_SETENC_BY_BOM) && idx2 === ext ? null : idx2;
481
+ }
482
+ }
483
+ return { ...rbIoExtIntToEncs(ext, intern, fmode), fmode };
484
+ }
485
+ /**
486
+ * The heap `os_obj_of` (`vendor/ruby/v3.3.11/gc.c:4162`) walks, for the one
487
+ * hierarchy ruby-compat constructs itself.
488
+ *
489
+ * @noRailsEquivalent PERMANENT
490
+ */
491
+ export const ioObjects = new Set();
492
+ const ioObjectsSweep = new FinalizationRegistry((ref) => ioObjects.delete(ref));
493
+ /**
494
+ * `IO::EAGAINWaitReadable` (`vendor/ruby/v3.3.11/io.c:15389`), the
495
+ * `Errno::EAGAIN` `read_nonblock` raises when a read would block.
496
+ *
497
+ * @noRailsEquivalent PERMANENT — Ruby core `IO::EAGAINWaitReadable`.
498
+ */
499
+ class EAGAINWaitReadable extends Errno.EAGAIN {
500
+ constructor(mesg) {
501
+ super(mesg);
502
+ this.name = "IO::EAGAINWaitReadable";
503
+ }
504
+ }
505
+ /**
506
+ * `IO::WaitWritable` (`vendor/ruby/v3.3.11/io.c:15387`), the module
507
+ * `IO::EAGAINWaitWritable` includes (`io.c:15393`), so `rescue
508
+ * IO::WaitWritable` catches it.
509
+ *
510
+ * @noRailsEquivalent PERMANENT — Ruby core `IO::WaitWritable`.
511
+ */
512
+ const WaitWritable = {
513
+ [Symbol.hasInstance](error) {
514
+ return error instanceof EAGAINWaitWritable;
515
+ },
516
+ };
517
+ /**
518
+ * `IO::EAGAINWaitWritable` (`vendor/ruby/v3.3.11/io.c:15392`), the
519
+ * `Errno::EAGAIN` `write_nonblock` raises when a write would block.
520
+ *
521
+ * @noRailsEquivalent PERMANENT — Ruby core `IO::EAGAINWaitWritable`.
522
+ */
523
+ class EAGAINWaitWritable extends Errno.EAGAIN {
524
+ constructor(mesg) {
525
+ super(mesg);
526
+ this.name = "IO::EAGAINWaitWritable";
527
+ }
528
+ }
529
+ /**
530
+ * `IO` (`vendor/ruby/v3.3.11/io.c:15371` `rb_cIO`), the sliver of it trails calls.
531
+ *
532
+ * Rails writes a credentials file through this class —
533
+ * `IO.binwrite "#{content_path}.tmp", encrypt(contents)`
534
+ * (`vendor/rails/v8.0.5.2/activesupport/lib/active_support/encrypted_file.rb:79`) — so
535
+ * trails writes it through a class of the same name. The backend is the
536
+ * `FsAdapter` contract in `./fs-adapter.js`, the same one `File` writes through.
537
+ *
538
+ * @noRailsEquivalent PERMANENT — Ruby core `IO` (`vendor/ruby/v3.3.11/io.c:15371`),
539
+ * which Rails calls without defining, so no Rails or gem file declares the
540
+ * class this file's export lives in.
541
+ */
542
+ export class IO {
543
+ /** @noRailsEquivalent PERMANENT — Ruby core `IO::SEEK_SET` (`vendor/ruby/v3.3.11/io.c:15506`). */
544
+ static SEEK_SET = 0;
545
+ /** @noRailsEquivalent PERMANENT — Ruby core `IO::SEEK_CUR` (`vendor/ruby/v3.3.11/io.c:15508`). */
546
+ static SEEK_CUR = 1;
547
+ /** @noRailsEquivalent PERMANENT — Ruby core `IO::SEEK_END` (`vendor/ruby/v3.3.11/io.c:15510`). */
548
+ static SEEK_END = 2;
549
+ /** @noRailsEquivalent PERMANENT */
550
+ static EAGAINWaitReadable = EAGAINWaitReadable;
551
+ /** @noRailsEquivalent PERMANENT */
552
+ static WaitWritable = WaitWritable;
553
+ /** @noRailsEquivalent PERMANENT */
554
+ static EAGAINWaitWritable = EAGAINWaitWritable;
555
+ /**
556
+ * `IO::EWOULDBLOCKWaitWritable` (`vendor/ruby/v3.3.11/io.c:15400`), the
557
+ * same class as {@link IO.EAGAINWaitWritable} where `EAGAIN == EWOULDBLOCK`,
558
+ * as on every platform Node runs on.
559
+ *
560
+ * @noRailsEquivalent PERMANENT
561
+ */
562
+ static EWOULDBLOCKWaitWritable = EAGAINWaitWritable;
563
+ /**
564
+ * `vendor/ruby/v3.3.11/file.c:7848` — `File::Constants::NULL`, which `IO`
565
+ * includes (`file.c:7773`), so it is `IO::NULL` and `File::NULL`:
566
+ * `ruby_null_device` (`file.c:6540`), `"NUL"` on a DOSISH build and
567
+ * `"/dev/null"` everywhere else. The platform answer comes from the
568
+ * registered path backend's separator, as `File::ALT_SEPARATOR` does.
569
+ *
570
+ * @noRailsEquivalent PERMANENT — Ruby core `IO::NULL`.
571
+ */
572
+ static get NULL() {
573
+ return getPath().sep === "\\" ? "NUL" : "/dev/null";
574
+ }
575
+ /**
576
+ * `IO.default_console_size` (`vendor/ruby/v3.3.11/ext/io/console/lib/console/size.rb:3-8`).
577
+ *
578
+ * @noRailsEquivalent PERMANENT
579
+ */
580
+ static defaultConsoleSize() {
581
+ return [Number(rbStrToI(env.LINES ?? "")) || 25, Number(rbStrToI(env.COLUMNS ?? "")) || 80];
582
+ }
583
+ /**
584
+ * `IO.console_size` (`vendor/ruby/v3.3.11/ext/io/console/lib/console/size.rb:17-21`).
585
+ * Node exposes no `/dev/tty` handle (`console_dev`,
586
+ * `vendor/ruby/v3.3.11/ext/io/console/console.c`), so `console.winsize` is read
587
+ * off whichever of stdout and stderr is a TTY; with neither it is the
588
+ * `NoMethodError` arm.
589
+ *
590
+ * @noRailsEquivalent PERMANENT
591
+ */
592
+ static consoleSize() {
593
+ for (const console of [stdout, stderr]) {
594
+ if (console.isTTY && console.columns != null && console.rows != null) {
595
+ return [console.rows, console.columns];
596
+ }
597
+ }
598
+ return IO.defaultConsoleSize();
599
+ }
600
+ /**
601
+ * The descriptor `rb_io_s_open` (`vendor/ruby/v3.3.11/io.c:8148`) opened the stream
602
+ * on, and the offset `rb_io_seek_m` (`io.c:2495`) moves — Ruby's `rb_io_t`
603
+ * holds both.
604
+ */
605
+ fd;
606
+ /** `fptr->pathv` (`vendor/ruby/v3.3.11/io.c:2943` reads it back as `IO#path`). */
607
+ pathv;
608
+ /** `fptr->mode`, the `FMODE_*` flags (`vendor/ruby/v3.3.11/io.c:6881`). */
609
+ mode;
610
+ enc = null;
611
+ /** `fptr->encs.enc2` (`vendor/ruby/v3.3.11/io.c:11718`). */
612
+ enc2 = null;
613
+ /**
614
+ * `fptr->stdio_file` (`vendor/ruby/v3.3.11/io.c:9328`), the C stream `prep_stdio`
615
+ * attaches to a standard descriptor. In trails the process adapter owns the
616
+ * standard streams, so a write reaches them through it rather than the fs.
617
+ */
618
+ stdioFile = null;
619
+ /** @internal */
620
+ _pos = 0;
621
+ /**
622
+ * `rb_io_initialize` (`vendor/ruby/v3.3.11/io.c:9207`), reached as `IO.new(fd)`. It
623
+ * is protected because `File.open` (`io.c:8148`) is the only way trails
624
+ * opens a stream, and a public TS constructor is measured surface.
625
+ */
626
+ constructor(fd, pathv = null, vmode = "r") {
627
+ this.fd = fd;
628
+ this.pathv = pathv;
629
+ this.mode = rbIoModestrFmode(vmode);
630
+ const ref = new WeakRef(this);
631
+ ioObjects.add(ref);
632
+ ioObjectsSweep.register(this, ref);
633
+ }
634
+ /**
635
+ * `vendor/ruby/v3.3.11/io.c:2703` `rb_io_sync`: whether the stream is in sync
636
+ * mode. {@link write} never buffers, so every stream behaves as a synced one.
637
+ *
638
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#sync`
639
+ * (`vendor/ruby/v3.3.11/io.c:2703`).
640
+ */
641
+ get sync() {
642
+ return (this.mode & FMODE_SYNC) !== 0;
643
+ }
644
+ /**
645
+ * `vendor/ruby/v3.3.11/io.c:2740` `rb_io_set_sync`.
646
+ *
647
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#sync=`
648
+ * (`vendor/ruby/v3.3.11/io.c:2740`).
649
+ */
650
+ set sync(sync) {
651
+ if (rtest(sync)) {
652
+ this.mode |= FMODE_SYNC;
653
+ }
654
+ else {
655
+ this.mode &= ~FMODE_SYNC;
656
+ }
657
+ }
658
+ /**
659
+ * `vendor/ruby/v3.3.11/io.c:6379` `rb_io_binmode_m`, which puts the stream in binary
660
+ * mode and answers the stream. A String written to a binary stream goes out
661
+ * as its own bytes rather than being transcoded, so after this {@link write}
662
+ * takes an ASCII-8BIT String — one character per byte, the encoding
663
+ * {@link IO#read} already answers in.
664
+ *
665
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#binmode`
666
+ * (`vendor/ruby/v3.3.11/io.c:6379`).
667
+ */
668
+ binmode() {
669
+ this.mode |= FMODE_BINMODE;
670
+ this.mode &= ~FMODE_TEXTMODE;
671
+ this.enc = Encoding.ASCII_8BIT;
672
+ return this;
673
+ }
674
+ /**
675
+ * `vendor/ruby/v3.3.11/io.c:13474` `rb_io_set_encoding` — the external encoding the
676
+ * stream reads and writes through, which {@link binmode} also sets but which
677
+ * carries no `FMODE_BINMODE` of its own, and, in the two-argument form, the
678
+ * internal one it transcodes to. It answers the stream.
679
+ *
680
+ * `io_encoding_set` (`vendor/ruby/v3.3.11/io.c:11659`) records whatever
681
+ * `find_encoding` answered, so a name that resolves to
682
+ * `UNSPECIFIED_ENCODING` — the `internal` alias while
683
+ * `Encoding.default_internal` is unset (`ruby -e 'p
684
+ * STDOUT.set_encoding("internal").external_encoding'` answers `nil`) —
685
+ * leaves the stream with no external encoding.
686
+ *
687
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#set_encoding`
688
+ * (`vendor/ruby/v3.3.11/io.c:13474`).
689
+ */
690
+ setEncoding(extEnc, intEnc) {
691
+ let enc;
692
+ let enc2;
693
+ if (intEnc != null) {
694
+ enc2 = Encoding.find(extEnc);
695
+ if (intEnc === "-") {
696
+ enc = enc2;
697
+ enc2 = null;
698
+ }
699
+ else {
700
+ enc = Encoding.find(intEnc);
701
+ if (enc === enc2)
702
+ enc2 = null;
703
+ }
704
+ if (enc2 === Encoding.ASCII_8BIT) {
705
+ enc = enc2;
706
+ enc2 = null;
707
+ }
708
+ }
709
+ else if (typeof extEnc === "string") {
710
+ ({ enc, enc2 } = parseModeEnc(extEnc));
711
+ }
712
+ else {
713
+ ({ enc, enc2 } = rbIoExtIntToEncs(Encoding.find(extEnc), undefined));
714
+ }
715
+ this.enc = enc;
716
+ this.enc2 = enc2;
717
+ return this;
718
+ }
719
+ /**
720
+ * `rb_io_external_encoding` (`vendor/ruby/v3.3.11/io.c:13407`) — the transcoding
721
+ * pair's source encoding, the recorded one on a writable stream, and
722
+ * `io_read_encoding` (`io.c:1010`) on a readable one.
723
+ *
724
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#external_encoding`
725
+ * (`vendor/ruby/v3.3.11/io.c:13407`).
726
+ */
727
+ externalEncoding() {
728
+ if (this.enc2) {
729
+ return this.enc2;
730
+ }
731
+ if (this.mode & FMODE_WRITABLE) {
732
+ if (this.enc)
733
+ return this.enc;
734
+ return null;
735
+ }
736
+ return this.ioReadEncoding();
737
+ }
738
+ /**
739
+ * `rb_io_internal_encoding` (`vendor/ruby/v3.3.11/io.c:13440`) — the transcoding
740
+ * pair's destination encoding, and `nil` where no conversion is specified.
741
+ *
742
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#internal_encoding`
743
+ * (`vendor/ruby/v3.3.11/io.c:13440`).
744
+ */
745
+ internalEncoding() {
746
+ if (!this.enc2)
747
+ return null;
748
+ return this.ioReadEncoding();
749
+ }
750
+ /**
751
+ * `vendor/ruby/v3.3.11/io.c:6400` `rb_io_binmode_p`, which answers whether
752
+ * `FMODE_BINMODE` is set on the stream.
753
+ *
754
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#binmode?`
755
+ * (`vendor/ruby/v3.3.11/io.c:6400`).
756
+ */
757
+ isBinmode() {
758
+ return (this.mode & FMODE_BINMODE) !== 0;
759
+ }
760
+ /**
761
+ * `vendor/ruby/v3.3.11/io.c:2943` `rb_io_path`, registered as both `IO#path` and
762
+ * `IO#to_path` (`io.c:15544-15545`) — the path the stream was opened on.
763
+ *
764
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#path`
765
+ * (`vendor/ruby/v3.3.11/io.c:2943`).
766
+ */
767
+ path() {
768
+ return this.pathv;
769
+ }
770
+ /**
771
+ * `vendor/ruby/v3.3.11/io.c:2943` `rb_io_path`, registered as `IO#to_path`
772
+ * (`io.c:15545`).
773
+ *
774
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#to_path`
775
+ * (`vendor/ruby/v3.3.11/io.c:15545`).
776
+ */
777
+ toPath() {
778
+ return this.pathv;
779
+ }
780
+ /**
781
+ * `vendor/ruby/v3.3.11/io.c:5093` `rb_io_to_io`, which answers the stream itself.
782
+ *
783
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#to_io`
784
+ * (`vendor/ruby/v3.3.11/io.c:5093`).
785
+ */
786
+ toIo() {
787
+ return this;
788
+ }
789
+ /**
790
+ * `vendor/ruby/v3.3.11/io.c:12121` `rb_io_s_readlines`, in its whole-file form:
791
+ * every line of the file, each keeping its trailing separator.
792
+ *
793
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.readlines`
794
+ * (`vendor/ruby/v3.3.11/io.c:12121`).
795
+ */
796
+ static readlines(name) {
797
+ const lines = getFs()
798
+ .readFileSync(name, "utf-8")
799
+ .split(/(?<=\n)/);
800
+ if (lines[lines.length - 1] === "")
801
+ lines.pop();
802
+ return lines;
803
+ }
804
+ /**
805
+ * {@link IO.readlines} over the backend's async `readFile`.
806
+ *
807
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.readlines`
808
+ * (`vendor/ruby/v3.3.11/io.c:12121`).
809
+ */
810
+ static async readlinesAsync(name) {
811
+ const lines = (await getFs().readFile(name, "utf-8")).split(/(?<=\n)/);
812
+ if (lines[lines.length - 1] === "")
813
+ lines.pop();
814
+ return lines;
815
+ }
816
+ /**
817
+ * `vendor/ruby/v3.3.11/io.c:12242` `rb_io_s_binread`, which opens the stream
818
+ * `FMODE_BINMODE` under `rb_ascii8bit_encoding()` (`io.c:12257`) and so
819
+ * answers the file's BYTES, an ASCII-8BIT `Uint8Array`, never a decoded
820
+ * String. `IO.read` (`io.c:12200`) is the member that decodes.
821
+ *
822
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.binread`
823
+ * (`vendor/ruby/v3.3.11/io.c:12242`).
824
+ */
825
+ static binread(name) {
826
+ return Uint8Array.from(getFs().readFileSync(name));
827
+ }
828
+ static async binreadAsync(name, length = null, offset = null) {
829
+ const bytes = Uint8Array.from(await getFs().readFile(name));
830
+ const start = offset ?? 0;
831
+ if (length == null)
832
+ return bytes.subarray(start);
833
+ if (length > 0 && start >= bytes.length)
834
+ return null;
835
+ return bytes.subarray(start, start + length);
836
+ }
837
+ /**
838
+ * {@link IO.copyStream} into a destination named by path, which
839
+ * `rb_io_s_copy_stream` opens for writing (`io.c:13232-13236`, `O_WRONLY |
840
+ * O_CREAT | O_TRUNC`), written through the backend's async `writeFile`, so
841
+ * that source is read to EOF first; an IO or any other `write` receiver gets
842
+ * each chunk as it is read (`copy_stream_body`). Answers the byte total
843
+ * (`io.c:13392`).
844
+ *
845
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.copy_stream`
846
+ * (`vendor/ruby/v3.3.11/io.c:13365`).
847
+ */
848
+ static async copyStreamAsync(src, dst) {
849
+ const chunks = [];
850
+ let total = 0;
851
+ let data;
852
+ while ((data = await (src instanceof IO ? src.readAsync(16384) : src.read(16384))) != null &&
853
+ data.length > 0) {
854
+ const chunk = typeof data === "string" ? new TextEncoder().encode(data) : data;
855
+ if (typeof dst === "string")
856
+ chunks.push(chunk);
857
+ else if (dst instanceof IO)
858
+ await dst.writeAsync(chunk);
859
+ else
860
+ await dst.write(chunk);
861
+ total += chunk.length;
862
+ }
863
+ if (typeof dst !== "string")
864
+ return total;
865
+ const bytes = new Uint8Array(total);
866
+ let offset = 0;
867
+ for (const chunk of chunks) {
868
+ bytes.set(chunk, offset);
869
+ offset += chunk.length;
870
+ }
871
+ const fs = getFs();
872
+ if (fs.writeFile)
873
+ await fs.writeFile(dst, bytes);
874
+ else
875
+ fs.writeFileSync(dst, bytes);
876
+ return total;
877
+ }
878
+ /**
879
+ * `vendor/ruby/v3.3.11/io.c:12396` `rb_io_s_binwrite`, which is `IO.write`
880
+ * (`io.c:12377`) with the stream opened in binary mode: `string` is an
881
+ * ASCII-8BIT String and its characters go to the file as bytes, so
882
+ * {@link IO.binread} answers it back unchanged. The byte count is the return
883
+ * value either way (`io_s_write`, `io.c:12285`).
884
+ *
885
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.binwrite`
886
+ * (`vendor/ruby/v3.3.11/io.c:12396`).
887
+ */
888
+ static binwrite(name, string) {
889
+ const buffer = typeof string === "string" ? binaryBytes(string) : string;
890
+ getFs().writeFileSync(name, buffer);
891
+ return buffer.length;
892
+ }
893
+ static async popen(pname, ...rest) {
894
+ const mode = typeof rest[0] === "string" ? rest.shift() : "r";
895
+ let opt = (rest[0] ?? {});
896
+ let block = rest[1];
897
+ if (typeof opt === "function") {
898
+ block = opt;
899
+ opt = {};
900
+ }
901
+ const execarg = rbExecargNew(typeof pname === "string" ? [pname] : pname);
902
+ const env = execarg[1];
903
+ let [command, , args] = execarg;
904
+ if (typeof pname === "string" && args === null) {
905
+ [command, args] = ["/bin/sh", ["-c", pname]];
906
+ }
907
+ const { getChildProcess } = await import("./child-process-adapter.js");
908
+ const adapter = getChildProcess();
909
+ if (adapter.popen === undefined) {
910
+ throw new NotImplementedError("fork() function is unimplemented on this machine");
911
+ }
912
+ const err = opt.err === "out" ? "out" : (opt.err?.fileno() ?? null);
913
+ let input;
914
+ let value;
915
+ if (mode.includes("w")) {
916
+ input = new StringIO(new Uint8Array(0));
917
+ if (block !== undefined)
918
+ value = await block(input);
919
+ }
920
+ const [out, status] = await adapter.popen(command, args ?? [], env, err, input === undefined ? undefined : input.string());
921
+ if (status.error !== undefined) {
922
+ rbLastStatusSet(new Process.Status({ pid: status.pid, status: 127, signal: null }));
923
+ throw status.error;
924
+ }
925
+ if (input !== undefined && block !== undefined) {
926
+ rbLastStatusSet(new Process.Status(status));
927
+ return value;
928
+ }
929
+ const port = new StringIO(out);
930
+ if (block === undefined) {
931
+ rbLastStatusSet(new Process.Status(status));
932
+ return port;
933
+ }
934
+ try {
935
+ return await block(port);
936
+ }
937
+ finally {
938
+ port.close();
939
+ rbLastStatusSet(new Process.Status(status));
940
+ }
941
+ }
942
+ /**
943
+ * `IO.pipe` (`vendor/ruby/v3.3.11/io.c:11828` `rb_io_s_pipe`): a reader and a
944
+ * writer over one in-process byte buffer standing in for the kernel's pipe,
945
+ * whose capacity (Linux's default 64KiB) bounds what `write_nonblock` takes
946
+ * before `IO::EAGAINWaitWritable`.
947
+ *
948
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.pipe`
949
+ * (`vendor/ruby/v3.3.11/io.c:11828`).
950
+ */
951
+ static pipe() {
952
+ const pipe = {
953
+ chunks: [],
954
+ length: 0,
955
+ readerClosed: false,
956
+ writerClosed: false,
957
+ writers: 1,
958
+ waiting: [],
959
+ };
960
+ return [new PipeIO(pipe, "r"), new PipeIO(pipe, "w")];
961
+ }
962
+ /**
963
+ * `vendor/ruby/v3.3.11/io.c:13365` `rb_io_s_copy_stream`, in the IO-to-IO form
964
+ * `Entry_#copy_file` calls (`vendor/ruby/v3.3.11/lib/fileutils.rb:2280`). With no
965
+ * `src_length` and no `src_offset`, `nogvl_copy_stream_read_write`
966
+ * (`io.c:12997-13050`) reads the source 16 KiB at a time until EOF and writes
967
+ * each chunk to the destination, so the bytes pass through unchanged
968
+ * whatever either stream's encoding. It answers the byte total
969
+ * (`io.c:13392`).
970
+ *
971
+ * A source that answers `to_path` (a `File`, a `Tempfile`) is read
972
+ * through its `to_io` (`rb_io_check_io`, `io.c:13186-13189`); any other
973
+ * (a `StringIO`) goes through `copy_stream_fallback_body` (`io.c:13088`),
974
+ * which `readpartial`s 16 KiB at a time until `EOFError` (`io.c:13096`).
975
+ *
976
+ * @noRailsEquivalent PERMANENT — Ruby core `IO.copy_stream`
977
+ * (`vendor/ruby/v3.3.11/io.c:13365`).
978
+ */
979
+ static copyStream(src, dst) {
980
+ let total = 0;
981
+ const source = src;
982
+ if (typeof source.toPath === "function" && typeof source.toIo === "function") {
983
+ src = source.toIo();
984
+ }
985
+ else if (!(src instanceof IO)) {
986
+ try {
987
+ for (;;) {
988
+ const chunk = src.readpartial(1024 * 16);
989
+ dst.write(chunk);
990
+ total += chunk.length;
991
+ }
992
+ }
993
+ catch (error) {
994
+ if (error instanceof EOFError)
995
+ return total;
996
+ throw error;
997
+ }
998
+ }
999
+ const buf = new Uint8Array(1024 * 16);
1000
+ for (;;) {
1001
+ const ss = getFs().readSync(src.fd, buf, 0, buf.length, src._pos);
1002
+ if (ss <= 0)
1003
+ return total;
1004
+ src._pos += ss;
1005
+ dst.write(buf.subarray(0, ss));
1006
+ total += ss;
1007
+ }
1008
+ }
1009
+ /**
1010
+ * `vendor/ruby/v3.3.11/io.c:2858` `rb_io_fileno` — the integer descriptor the
1011
+ * stream was opened on.
1012
+ *
1013
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#fileno`
1014
+ * (`vendor/ruby/v3.3.11/io.c:2858`).
1015
+ */
1016
+ fileno() {
1017
+ return this.fd;
1018
+ }
1019
+ /**
1020
+ * `vendor/ruby/v3.3.11/io.c:2495` `rb_io_seek_m`: `whence` defaults to
1021
+ * `IO::SEEK_SET`, the absolute offset the next read starts at; `SEEK_CUR` is
1022
+ * relative to the current position and `SEEK_END` to the stream's size.
1023
+ * It answers `0`.
1024
+ *
1025
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#seek`
1026
+ * (`vendor/ruby/v3.3.11/io.c:2495`).
1027
+ */
1028
+ seek(amount, whence = IO.SEEK_SET) {
1029
+ if (whence === IO.SEEK_CUR)
1030
+ amount += this._pos;
1031
+ else if (whence === IO.SEEK_END)
1032
+ amount += this.stat().size;
1033
+ this._pos = amount;
1034
+ return 0;
1035
+ }
1036
+ /**
1037
+ * `vendor/ruby/v3.3.11/io.c:2039` `rb_io_tell` — the offset the next read or write
1038
+ * starts at, which is what `Rack::Test::UploadedFile#append_to` leaves at `0`
1039
+ * (`vendor/rack-test/v2.2.0/lib/rack/test/uploaded_file.rb:66`).
1040
+ *
1041
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#pos`
1042
+ * (`vendor/ruby/v3.3.11/io.c:2039`).
1043
+ */
1044
+ get pos() {
1045
+ return this._pos;
1046
+ }
1047
+ /**
1048
+ * `vendor/ruby/v3.3.11/io.c:2565` `rb_io_rewind` — the offset goes back to the start
1049
+ * of the stream, and it answers `0`.
1050
+ *
1051
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#rewind`
1052
+ * (`vendor/ruby/v3.3.11/io.c:2565`).
1053
+ */
1054
+ rewind() {
1055
+ return this.seek(0);
1056
+ }
1057
+ /**
1058
+ * `vendor/ruby/v3.3.11/io.c:5842` `rb_io_closed_p`, which is `fptr->fd < 0` — the
1059
+ * same test `rb_io_close_m` (`io.c:5779`) short-circuits on.
1060
+ *
1061
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#closed?`
1062
+ * (`vendor/ruby/v3.3.11/io.c:5842`).
1063
+ */
1064
+ isClosed() {
1065
+ return this.fd < 0;
1066
+ }
1067
+ /**
1068
+ * `IO#tty?` (`vendor/ruby/v3.3.11/io.c:5270` `rb_io_isatty`): whether the
1069
+ * descriptor is a terminal. Only a standard stream's adapter can tell.
1070
+ *
1071
+ * @noRailsEquivalent PERMANENT
1072
+ */
1073
+ isTty() {
1074
+ return this.stdioFile?.isTTY ?? false;
1075
+ }
1076
+ /**
1077
+ * `vendor/ruby/v3.3.11/io.c:2075` `rb_io_stat` — `fstat(2)` of the descriptor, where
1078
+ * `File.stat` names a path. It raises on a closed stream, and on an adapter
1079
+ * with no `fstat` there is no descriptor identity to answer with.
1080
+ *
1081
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#stat`
1082
+ * (`vendor/ruby/v3.3.11/io.c:2075`).
1083
+ */
1084
+ stat() {
1085
+ const fstatSync = getFs().fstatSync;
1086
+ if (this.fd < 0)
1087
+ throw new IOError("closed stream");
1088
+ if (!fstatSync)
1089
+ throw new IOError("fstat is unavailable in this runtime");
1090
+ return fstatSync(this.fd);
1091
+ }
1092
+ read(length, str) {
1093
+ if (length == null) {
1094
+ const all = this.readAll();
1095
+ if (str)
1096
+ str.set(b(all).subarray(0, str.length));
1097
+ return all;
1098
+ }
1099
+ const buffer = new Uint8Array(length);
1100
+ let n = 0;
1101
+ while (n < length) {
1102
+ const read = getFs().readSync(this.fd, buffer, n, length - n, this._pos + n);
1103
+ if (read === 0)
1104
+ break;
1105
+ n += read;
1106
+ }
1107
+ if (n === 0) {
1108
+ if (str)
1109
+ str.fill(0);
1110
+ return length === 0 ? new Uint8Array(0) : null;
1111
+ }
1112
+ this._pos += n;
1113
+ if (str)
1114
+ str.set(buffer.subarray(0, Math.min(n, str.length)));
1115
+ return buffer.slice(0, n);
1116
+ }
1117
+ async readAsync(length) {
1118
+ if (length == null) {
1119
+ const chunk = new Uint8Array(READ_CHUNK);
1120
+ const chunks = [];
1121
+ let total = 0;
1122
+ for (;;) {
1123
+ const read = await getFs().readAsync(this.fd, chunk, 0, chunk.length, this._pos);
1124
+ if (read === 0)
1125
+ break;
1126
+ this._pos += read;
1127
+ chunks.push(chunk.slice(0, read));
1128
+ total += read;
1129
+ }
1130
+ const bytes = new Uint8Array(total);
1131
+ let at = 0;
1132
+ for (const c of chunks) {
1133
+ bytes.set(c, at);
1134
+ at += c.length;
1135
+ }
1136
+ if (this.enc2 === null)
1137
+ return ioEncStr(bytes, total, this.ioReadEncoding());
1138
+ return ioEncStr(bytes, total, this.enc2, this.ioReadEncoding());
1139
+ }
1140
+ const buffer = new Uint8Array(length);
1141
+ let n = 0;
1142
+ while (n < length) {
1143
+ const read = await getFs().readAsync(this.fd, buffer, n, length - n, this._pos + n);
1144
+ if (read === 0)
1145
+ break;
1146
+ n += read;
1147
+ }
1148
+ if (n === 0)
1149
+ return length === 0 ? new Uint8Array(0) : null;
1150
+ this._pos += n;
1151
+ return buffer.slice(0, n);
1152
+ }
1153
+ /**
1154
+ * `rb_io_pread` (`vendor/ruby/v3.3.11/io.c:6202`): `maxlen` bytes read at
1155
+ * `offset` without moving the stream's position, raising `EOFError` when
1156
+ * nothing is there to read.
1157
+ *
1158
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#pread`
1159
+ * (`vendor/ruby/v3.3.11/io.c:6202`).
1160
+ */
1161
+ pread(maxlen, offset) {
1162
+ const str = new Uint8Array(maxlen);
1163
+ if (maxlen === 0)
1164
+ return str;
1165
+ if (this.fd < 0)
1166
+ throw new IOError("closed stream");
1167
+ const n = getFs().readSync(this.fd, str, 0, maxlen, offset);
1168
+ if (n === 0)
1169
+ throw new EOFError("end of file reached");
1170
+ return str.slice(0, n);
1171
+ }
1172
+ eachLine(block) {
1173
+ const lines = function* (io) {
1174
+ const all = io.readAll();
1175
+ if (typeof all === "string") {
1176
+ yield* all.match(/[^\n]*\n|[^\n]+$/g) ?? [];
1177
+ return;
1178
+ }
1179
+ let start = 0;
1180
+ for (let i = 0; i < all.length; i++) {
1181
+ if (all[i] !== 0x0a)
1182
+ continue;
1183
+ yield all.slice(start, i + 1);
1184
+ start = i + 1;
1185
+ }
1186
+ if (start < all.length)
1187
+ yield all.slice(start);
1188
+ };
1189
+ if (!block)
1190
+ return lines(this);
1191
+ for (const line of lines(this))
1192
+ block(line);
1193
+ return this;
1194
+ }
1195
+ each(block) {
1196
+ return block ? this.eachLine(block) : this.eachLine();
1197
+ }
1198
+ /**
1199
+ * {@link each} over the backend's async read: each line of the rest of the
1200
+ * stream, its separator retained, read in chunks and never whole. Lines are
1201
+ * split as bytes, so a character straddling two chunks survives.
1202
+ *
1203
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#each`
1204
+ * (`vendor/ruby/v3.3.11/io.c:15462`).
1205
+ */
1206
+ async *eachAsync() {
1207
+ const buffer = new Uint8Array(READ_CHUNK);
1208
+ const enc = (str) => this.enc2 === null
1209
+ ? ioEncStr(str, str.length, this.ioReadEncoding())
1210
+ : ioEncStr(str, str.length, this.enc2, this.ioReadEncoding());
1211
+ let rest = new Uint8Array(0);
1212
+ for (;;) {
1213
+ const read = await getFs().readAsync(this.fd, buffer, 0, buffer.length, this._pos);
1214
+ if (read === 0)
1215
+ break;
1216
+ this._pos += read;
1217
+ const bytes = new Uint8Array(rest.length + read);
1218
+ bytes.set(rest);
1219
+ bytes.set(buffer.subarray(0, read), rest.length);
1220
+ let start = 0;
1221
+ for (let i = rest.length; i < bytes.length; i++) {
1222
+ if (bytes[i] !== 0x0a)
1223
+ continue;
1224
+ yield enc(bytes.slice(start, i + 1));
1225
+ start = i + 1;
1226
+ }
1227
+ rest = bytes.slice(start);
1228
+ }
1229
+ if (rest.length > 0)
1230
+ yield enc(rest);
1231
+ }
1232
+ /**
1233
+ * `rb_io_gets_m` (`vendor/ruby/v3.3.11/io.c:4363`): the bytes up to and
1234
+ * including the next `sep` (`$/`, `"\n"`, by default), or the rest of the stream,
1235
+ * in the external encoding as {@link readAll} answers it; `nil` at EOF.
1236
+ * `limit` caps the bytes read (`""` for 0), and `chomp: true` drops the
1237
+ * trailing `sep`, with a `\r` before the default `"\n"`
1238
+ * (`rb_io_getline_0`, `vendor/ruby/v3.3.11/io.c:4128`).
1239
+ *
1240
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#gets`
1241
+ * (`vendor/ruby/v3.3.11/io.c:4363`).
1242
+ */
1243
+ gets(sep = "\n", limit = null, opts = {}) {
1244
+ if (typeof sep === "object") {
1245
+ opts = sep;
1246
+ sep = "\n";
1247
+ }
1248
+ else if (typeof limit === "object" && limit !== null) {
1249
+ opts = limit;
1250
+ limit = null;
1251
+ }
1252
+ if (typeof sep === "number") {
1253
+ limit = sep;
1254
+ sep = "\n";
1255
+ }
1256
+ const chomp = opts.chomp != null && opts.chomp !== false;
1257
+ const rsptr = new TextEncoder().encode(sep);
1258
+ const bytes = [];
1259
+ let b;
1260
+ if (limit === 0)
1261
+ return "";
1262
+ while ((b = this.getbyte()) !== null) {
1263
+ bytes.push(b);
1264
+ if ((typeof limit === "number" && limit >= 0 && bytes.length >= limit) ||
1265
+ (bytes.length >= rsptr.length &&
1266
+ rsptr.every((c, i) => bytes[bytes.length - rsptr.length + i] === c)))
1267
+ break;
1268
+ }
1269
+ if (bytes.length === 0)
1270
+ return null;
1271
+ if (chomp &&
1272
+ bytes.length >= rsptr.length &&
1273
+ rsptr.every((c, i) => bytes[bytes.length - rsptr.length + i] === c)) {
1274
+ bytes.length -= rsptr.length;
1275
+ if (sep === "\n" && bytes[bytes.length - 1] === 0x0d)
1276
+ bytes.length -= 1;
1277
+ }
1278
+ const str = Uint8Array.from(bytes);
1279
+ if (this.enc2 === null)
1280
+ return ioEncStr(str, str.length, this.ioReadEncoding());
1281
+ return ioEncStr(str, str.length, this.enc2, this.ioReadEncoding());
1282
+ }
1283
+ /**
1284
+ * `rb_io_readlines` (`vendor/ruby/v3.3.11/io.c:4518`) through `io_readlines`
1285
+ * (`io.c:4527`): every remaining line, read as {@link gets} reads one.
1286
+ *
1287
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#readlines`
1288
+ * (`vendor/ruby/v3.3.11/io.c:4518`).
1289
+ */
1290
+ readlines(sep = "\n", limit = null, opts = {}) {
1291
+ if (limit === 0 || sep === 0)
1292
+ throw new ArgumentError("invalid limit: 0 for readlines");
1293
+ const ary = [];
1294
+ let line;
1295
+ while ((line = this.gets(sep, limit, opts)) !== null) {
1296
+ ary.push(line);
1297
+ }
1298
+ return ary;
1299
+ }
1300
+ /**
1301
+ * `IO#readline` (`vendor/ruby/v3.3.11/io.rb:133`):
1302
+ * `io_readline` (`vendor/ruby/v3.3.11/io.c:4414`) is {@link gets} that raises
1303
+ * `EOFError` through `rb_eof_error` where `gets` answers `nil`.
1304
+ *
1305
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#readline`
1306
+ * (`vendor/ruby/v3.3.11/io.rb:133`).
1307
+ */
1308
+ readline(sep = "\n") {
1309
+ const line = this.gets(sep);
1310
+ if (line === null)
1311
+ throw new EOFError("end of file reached");
1312
+ return line;
1313
+ }
1314
+ /**
1315
+ * `vendor/ruby/v3.3.11/io.c:3317` `read_all`, which `io_read` (`io.c:3774`) takes
1316
+ * when `length` is `nil`: the rest of the stream, and `""` rather than `nil`
1317
+ * at EOF. Ruby sizes the read from `remain_size(fptr)`, an `fstat` the
1318
+ * `FsAdapter` contract has no member for, so the bytes come in chunks.
1319
+ *
1320
+ * This is the arm that answers the external encoding — `io_enc_str`
1321
+ * (`io.c:3123`) over `io_read_encoding` (`io.c:1010`) — where the `length`
1322
+ * arm answers ASCII-8BIT whatever the mode. A binary
1323
+ * stream keeps the bytes. The chunks are joined before decoding because a
1324
+ * multi-byte character can straddle two of them.
1325
+ */
1326
+ readAll() {
1327
+ const buffer = new Uint8Array(READ_CHUNK);
1328
+ const chunks = [];
1329
+ let total = 0;
1330
+ for (;;) {
1331
+ const read = getFs().readSync(this.fd, buffer, 0, buffer.length, this._pos);
1332
+ if (read === 0)
1333
+ break;
1334
+ this._pos += read;
1335
+ chunks.push(buffer.slice(0, read));
1336
+ total += read;
1337
+ }
1338
+ const bytes = new Uint8Array(total);
1339
+ let at = 0;
1340
+ for (const chunk of chunks) {
1341
+ bytes.set(chunk, at);
1342
+ at += chunk.length;
1343
+ }
1344
+ if (this.enc2 === null)
1345
+ return ioEncStr(bytes, total, this.ioReadEncoding());
1346
+ return ioEncStr(bytes, total, this.enc2, this.ioReadEncoding());
1347
+ }
1348
+ /**
1349
+ * `rb_io_getbyte` (`vendor/ruby/v3.3.11/io.c:5056`) — the next byte, or `nil` at EOF.
1350
+ */
1351
+ getbyte() {
1352
+ const buffer = new Uint8Array(1);
1353
+ if (getFs().readSync(this.fd, buffer, 0, 1, this._pos) === 0)
1354
+ return null;
1355
+ this._pos += 1;
1356
+ return buffer[0];
1357
+ }
1358
+ /**
1359
+ * `rb_io_ungetbyte` (`vendor/ruby/v3.3.11/io.c:5150`). There is no read buffer behind
1360
+ * an `FsAdapter` to push `b` into, so the offset steps back over it instead,
1361
+ * which is the same stream for the byte {@link getbyte} just answered — the
1362
+ * only byte `io_strip_bom` ever ungets.
1363
+ */
1364
+ ungetbyte(b) {
1365
+ if (b === null)
1366
+ return;
1367
+ this._pos -= 1;
1368
+ }
1369
+ /** `io_strip_bom` (`vendor/ruby/v3.3.11/io.c:7085-7145`). */
1370
+ ioStripBom() {
1371
+ let b2, b3, b4;
1372
+ if (!(this.mode & FMODE_READABLE))
1373
+ return null;
1374
+ const b1 = this.getbyte();
1375
+ if (b1 === null)
1376
+ return null;
1377
+ switch (b1) {
1378
+ case 0xef:
1379
+ if ((b2 = this.getbyte()) === null)
1380
+ break;
1381
+ if (b2 === 0xbb && (b3 = this.getbyte()) !== null) {
1382
+ if (b3 === 0xbf) {
1383
+ return Encoding.UTF_8;
1384
+ }
1385
+ this.ungetbyte(b3);
1386
+ }
1387
+ this.ungetbyte(b2);
1388
+ break;
1389
+ case 0xfe:
1390
+ if ((b2 = this.getbyte()) === null)
1391
+ break;
1392
+ if (b2 === 0xff) {
1393
+ return Encoding.find("UTF-16BE");
1394
+ }
1395
+ this.ungetbyte(b2);
1396
+ break;
1397
+ case 0xff:
1398
+ if ((b2 = this.getbyte()) === null)
1399
+ break;
1400
+ if (b2 === 0xfe) {
1401
+ b3 = this.getbyte();
1402
+ if (b3 === 0 && (b4 = this.getbyte()) !== null) {
1403
+ if (b4 === 0) {
1404
+ return Encoding.find("UTF-32LE");
1405
+ }
1406
+ this.ungetbyte(b4);
1407
+ }
1408
+ this.ungetbyte(b3);
1409
+ return Encoding.find("UTF-16LE");
1410
+ }
1411
+ this.ungetbyte(b2);
1412
+ break;
1413
+ case 0:
1414
+ if ((b2 = this.getbyte()) === null)
1415
+ break;
1416
+ if (b2 === 0 && (b3 = this.getbyte()) !== null) {
1417
+ if (b3 === 0xfe && (b4 = this.getbyte()) !== null) {
1418
+ if (b4 === 0xff) {
1419
+ return Encoding.find("UTF-32BE");
1420
+ }
1421
+ this.ungetbyte(b4);
1422
+ }
1423
+ this.ungetbyte(b3);
1424
+ }
1425
+ this.ungetbyte(b2);
1426
+ break;
1427
+ }
1428
+ this.ungetbyte(b1);
1429
+ return null;
1430
+ }
1431
+ /**
1432
+ * `io_set_encoding_by_bom` (`vendor/ruby/v3.3.11/io.c:7148-7163`), which
1433
+ * `rb_file_open_generic` runs under `FMODE_SETENC_BY_BOM` (`io.c:7196`).
1434
+ */
1435
+ ioSetEncodingByBom() {
1436
+ const extenc = this.ioStripBom();
1437
+ if (extenc) {
1438
+ this.setEncoding(extenc, this.internalEncoding() ?? undefined);
1439
+ }
1440
+ else {
1441
+ this.enc2 = null;
1442
+ }
1443
+ return extenc;
1444
+ }
1445
+ /**
1446
+ * `io_read_encoding` (`vendor/ruby/v3.3.11/io.c:1010`) — the encoding a read tags
1447
+ * its String with: the stream's own external encoding, or
1448
+ * `Encoding.default_external` where none was recorded.
1449
+ */
1450
+ ioReadEncoding() {
1451
+ if (this.enc) {
1452
+ return this.enc;
1453
+ }
1454
+ return Encoding.defaultExternal;
1455
+ }
1456
+ /**
1457
+ * `vendor/ruby/v3.3.11/io.c:3590` `io_readpartial`, which is `io_getpartial` with a
1458
+ * `rb_eof_error()` (`io.c:756`) where that answers `nil` — so it reads at
1459
+ * most `maxlen` bytes and raises `EOFError` rather than returning `nil` at
1460
+ * the end of the stream. `outbuf` is the buffer `io_getpartial` fills, the
1461
+ * same `str` {@link read} takes.
1462
+ *
1463
+ * A blocking descriptor read already returns what is available, so
1464
+ * `io_getpartial`'s short read IS {@link read}'s length arm here.
1465
+ *
1466
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#readpartial`
1467
+ * (`vendor/ruby/v3.3.11/io.c:3590`).
1468
+ */
1469
+ readpartial(maxlen, outbuf) {
1470
+ const ret = this.read(maxlen, outbuf);
1471
+ if (ret === null)
1472
+ throw new EOFError("end of file reached");
1473
+ return ret;
1474
+ }
1475
+ /**
1476
+ * `vendor/ruby/v3.3.11/io.c:2668` `rb_io_eof` — true when `io_fillbuf` cannot get a
1477
+ * byte at the current offset. There is no read buffer behind an `FsAdapter`,
1478
+ * so the two `READ_*_PENDING` short-circuits (`io.c:2674-2675`) have nothing
1479
+ * to answer for and the fill is a one-byte read that leaves the offset alone.
1480
+ *
1481
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#eof?`
1482
+ * (`vendor/ruby/v3.3.11/io.c:2668`).
1483
+ */
1484
+ isEof() {
1485
+ if (this.fd < 0)
1486
+ throw new IOError("closed stream");
1487
+ return getFs().readSync(this.fd, new Uint8Array(1), 0, 1, this._pos) === 0;
1488
+ }
1489
+ /**
1490
+ * `IO#<<` (`vendor/ruby/v3.3.11/io.c:15501` `rb_io_addstr`, `io.c:2323-2327`).
1491
+ *
1492
+ * @noRailsEquivalent PERMANENT
1493
+ */
1494
+ append(str) {
1495
+ this.write(str);
1496
+ return this;
1497
+ }
1498
+ /**
1499
+ * `vendor/ruby/v3.3.11/io.c:2263` `io_write_m` in its one-argument form, which
1500
+ * answers the number of bytes written. On a binary stream — {@link binmode},
1501
+ * or a mode carrying `b` (`rb_io_binmode`, `io.c:6311`) — `string` goes out
1502
+ * as its own bytes, its UTF-8; otherwise `do_writeconv` (`io.c:1904`)
1503
+ * transcodes it to the external encoding. A `Uint8Array` is a String's bytes
1504
+ * already and goes out unchanged, which is how an ASCII-8BIT producer hands
1505
+ * over its bytes.
1506
+ *
1507
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#write`
1508
+ * (`vendor/ruby/v3.3.11/io.c:2263`).
1509
+ */
1510
+ write(string) {
1511
+ const buffer = typeof string === "string" ? doWriteconv(string, this.enc) : string;
1512
+ if (this.stdioFile != null) {
1513
+ this.stdioFile.write(new TextDecoder().decode(buffer));
1514
+ return buffer.length;
1515
+ }
1516
+ let n = 0;
1517
+ while (n < buffer.length) {
1518
+ n += getFs().writeSync(this.fd, buffer, n, buffer.length - n, this._pos + n);
1519
+ }
1520
+ this._pos += n;
1521
+ return n;
1522
+ }
1523
+ /**
1524
+ * {@link write} over the backend's async write.
1525
+ *
1526
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#write`
1527
+ * (`vendor/ruby/v3.3.11/io.c:2263`).
1528
+ */
1529
+ async writeAsync(string) {
1530
+ const buffer = typeof string === "string" ? doWriteconv(string, this.enc) : string;
1531
+ if (this.stdioFile != null) {
1532
+ this.stdioFile.write(new TextDecoder().decode(buffer));
1533
+ return buffer.length;
1534
+ }
1535
+ let n = 0;
1536
+ while (n < buffer.length) {
1537
+ n += await getFs().writeAsync(this.fd, buffer, n, buffer.length - n, this._pos + n);
1538
+ }
1539
+ this._pos += n;
1540
+ return n;
1541
+ }
1542
+ /**
1543
+ * `vendor/ruby/v3.3.11/io.c:2379` `rb_io_flush`, which answers the stream.
1544
+ * {@link write} holds no buffer.
1545
+ *
1546
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#flush`
1547
+ * (`vendor/ruby/v3.3.11/io.c:2379`).
1548
+ */
1549
+ flush() {
1550
+ return this;
1551
+ }
1552
+ /**
1553
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#puts`
1554
+ * (`vendor/ruby/v3.3.11/io.c:15459`).
1555
+ */
1556
+ puts = puts;
1557
+ /**
1558
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#print`
1559
+ * (`vendor/ruby/v3.3.11/io.c:15457`).
1560
+ */
1561
+ print = print;
1562
+ /**
1563
+ * `vendor/ruby/v3.3.11/io.c:5777` `rb_io_close_m`, which answers `nil` — and answers
1564
+ * it without closing anything when `fptr->fd < 0` (`io.c:5779-5781`), so a
1565
+ * second close is a no-op rather than an error — which `atomic_write` leans
1566
+ * on, closing the temp file at `core_ext/file/atomic.rb:30` inside a
1567
+ * `Tempfile.open` whose `ensure` closes it again (`tempfile.rb:372`).
1568
+ *
1569
+ * @noRailsEquivalent PERMANENT — Ruby core `IO#close`
1570
+ * (`vendor/ruby/v3.3.11/io.c:5777`).
1571
+ */
1572
+ close() {
1573
+ if (this.fd < 0)
1574
+ return null;
1575
+ if (this.fd > 2)
1576
+ getFs().closeSync(this.fd);
1577
+ this.fd = -1;
1578
+ return null;
1579
+ }
1580
+ /**
1581
+ * `IO#reopen(other_io)` (`vendor/ruby/v3.3.11/io.c:8316` `io_reopen`). JS has
1582
+ * no `dup2(2)`, so the stream takes `other_io`'s descriptor rather than a copy
1583
+ * of it, and `other_io` has to stay open for as long as this stream writes to
1584
+ * it. A descriptor's kernel offset is shared but `pos` is per IO and writes
1585
+ * are positional, so the two IOs do not advance each other. A child
1586
+ * spawned with inherited stdio gets {@link STDOUT} and {@link STDERR} by
1587
+ * {@link fileno}, so it follows the reopen as it follows the `dup2` in Ruby.
1588
+ *
1589
+ * @noRailsEquivalent PERMANENT
1590
+ */
1591
+ reopen(nfile) {
1592
+ const orig = nfile.toIo();
1593
+ if (this.isClosed() || orig.isClosed())
1594
+ throw new IOError("closed stream");
1595
+ if (orig === this)
1596
+ return this;
1597
+ if ((this === STDIN && !(orig.mode & FMODE_READABLE)) ||
1598
+ ((this === STDOUT || this === STDERR) && !(orig.mode & FMODE_WRITABLE))) {
1599
+ throw new ArgumentError(`${this.pathv} can't change access mode from "${rbIoFmodeModestr(this.mode)}" to "${rbIoFmodeModestr(orig.mode)}"`);
1600
+ }
1601
+ if (this.mode & FMODE_WRITABLE)
1602
+ this.flush();
1603
+ if (orig.mode & FMODE_WRITABLE)
1604
+ orig.flush();
1605
+ this.mode = orig.mode;
1606
+ if (orig.pathv != null)
1607
+ this.pathv = orig.pathv;
1608
+ this.fd = orig.fd;
1609
+ this.stdioFile = orig.stdioFile;
1610
+ this._pos = orig._pos;
1611
+ return this;
1612
+ }
1613
+ }
1614
+ /**
1615
+ * `rb_io_fmode_modestr` (`vendor/ruby/v3.3.11/io.c:6408`), without its binary
1616
+ * and text spellings.
1617
+ *
1618
+ * @noRailsEquivalent PERMANENT
1619
+ */
1620
+ export function rbIoFmodeModestr(fmode) {
1621
+ if (fmode & FMODE_APPEND) {
1622
+ if ((fmode & FMODE_READWRITE) === FMODE_READWRITE)
1623
+ return "a+";
1624
+ return "a";
1625
+ }
1626
+ switch (fmode & FMODE_READWRITE) {
1627
+ case FMODE_READABLE:
1628
+ return "r";
1629
+ case FMODE_WRITABLE:
1630
+ return "w";
1631
+ case FMODE_READWRITE:
1632
+ if (fmode & FMODE_CREATE)
1633
+ return "w+";
1634
+ return "r+";
1635
+ default:
1636
+ throw new ArgumentError(`invalid access fmode 0x${fmode.toString(16)}`);
1637
+ }
1638
+ }
1639
+ /**
1640
+ * `prep_stdio` (`vendor/ruby/v3.3.11/io.c:9313`): an `IO` over a standard descriptor,
1641
+ * `rb_io_open_descriptor` (`io.c:9290`) standing in for trails' protected
1642
+ * constructor.
1643
+ */
1644
+ function prepStdio(f, fd, fmode, klass, path) {
1645
+ const io = new klass(fd, path, fmode);
1646
+ io.stdioFile = f;
1647
+ return io;
1648
+ }
1649
+ /**
1650
+ * `STDIN` / `$stdin`, `rb_io_prep_stdin` (`vendor/ruby/v3.3.11/io.c:9332`): an
1651
+ * `IO` over descriptor 0, which has no write-side adapter stream.
1652
+ *
1653
+ * @noRailsEquivalent PERMANENT
1654
+ */
1655
+ export const STDIN = prepStdio(null, 0, "r", IO, "<STDIN>");
1656
+ /**
1657
+ * `STDOUT` / `$stdout`, `rb_io_prep_stdout` (`vendor/ruby/v3.3.11/io.c:9338`), defined
1658
+ * at `io.c:15586`: an `IO` answering `write` / `puts` / `print` over the process
1659
+ * adapter's stdout.
1660
+ *
1661
+ * @noRailsEquivalent PERMANENT — Ruby core `STDOUT` (`vendor/ruby/v3.3.11/io.c:15586`).
1662
+ */
1663
+ export const STDOUT = prepStdio(stdout, 1, "w", IO, "<STDOUT>");
1664
+ /**
1665
+ * `STDERR` / `$stderr`, `rb_io_prep_stderr` (`vendor/ruby/v3.3.11/io.c:9344`), defined
1666
+ * at `io.c:15588`: an `IO` answering `write` / `puts` / `print` over the process
1667
+ * adapter's stderr.
1668
+ *
1669
+ * @noRailsEquivalent PERMANENT — Ruby core `STDERR` (`vendor/ruby/v3.3.11/io.c:15588`).
1670
+ */
1671
+ export const STDERR = prepStdio(stderr, 2, "w", IO, "<STDERR>");
1672
+ const PIPE_CAPACITY = 64 * 1024;
1673
+ /**
1674
+ * The copy of a pipe's writer a forked child holds (`rb_fork_ruby`,
1675
+ * `vendor/ruby/v3.3.11/process.c:4249`, duplicates every descriptor): the
1676
+ * reader sees end of file only once this copy is closed too. `write` is what
1677
+ * the child wrote to it.
1678
+ *
1679
+ * @noRailsEquivalent PERMANENT
1680
+ */
1681
+ export function pipeWriterDup(writer) {
1682
+ const pipe = writer._pipe;
1683
+ pipe.writers++;
1684
+ let closed = false;
1685
+ return {
1686
+ write(bytes) {
1687
+ if (closed || pipe.readerClosed || bytes.length === 0)
1688
+ return;
1689
+ pipe.chunks.push(bytes);
1690
+ pipe.length += bytes.length;
1691
+ for (const wake of pipe.waiting.splice(0))
1692
+ wake();
1693
+ },
1694
+ close() {
1695
+ if (closed)
1696
+ return;
1697
+ closed = true;
1698
+ if (--pipe.writers === 0)
1699
+ pipe.writerClosed = true;
1700
+ for (const wake of pipe.waiting.splice(0))
1701
+ wake();
1702
+ },
1703
+ };
1704
+ }
1705
+ /**
1706
+ * One end of an {@link IO.pipe}: the reader opened `"r"`, the writer `"w"`,
1707
+ * as `rb_io_s_pipe` opens them (`vendor/ruby/v3.3.11/io.c:11845-11858`).
1708
+ *
1709
+ * @noRailsEquivalent PERMANENT — Ruby core `IO` over a `pipe(2)` descriptor.
1710
+ */
1711
+ export class PipeIO extends IO {
1712
+ _pipe;
1713
+ _closed = false;
1714
+ /** @noRailsEquivalent PERMANENT */
1715
+ constructor(pipe, vmode) {
1716
+ super(-1, null, vmode);
1717
+ this.binmode();
1718
+ this._pipe = pipe;
1719
+ }
1720
+ read(length, str) {
1721
+ this._checkReadable();
1722
+ if (!this._pipe.writerClosed && (length == null || this._pipe.length < length)) {
1723
+ throw new IO.EAGAINWaitReadable("read would block");
1724
+ }
1725
+ if (length == null)
1726
+ length = this._pipe.length;
1727
+ else if (this._pipe.length === 0 && length > 0) {
1728
+ if (str)
1729
+ str.fill(0);
1730
+ return null;
1731
+ }
1732
+ const out = this._shift(length);
1733
+ if (str)
1734
+ str.set(out.subarray(0, str.length));
1735
+ return out;
1736
+ }
1737
+ /**
1738
+ * `IO#read_nonblock` (`vendor/ruby/v3.3.11/io.rb:62`, `io.c:3611`
1739
+ * `io_read_nonblock`): at most `len` of the bytes written so far. A
1740
+ * non-boolean `exception` raises `ArgumentError`. With none buffered it
1741
+ * raises `IO::EAGAINWaitReadable` ("read would block", `io.c:3648`), or
1742
+ * answers `:wait_readable` (`io.c:3647`); once the writer is closed it
1743
+ * raises `EOFError`, or answers `nil` (`io.c:3656-3659`). `buf` is filled
1744
+ * up to its own length and zeroed at end of file, as `BasicSocket`'s
1745
+ * is: a `Uint8Array` cannot be resized to the bytes read.
1746
+ *
1747
+ * @noRailsEquivalent PERMANENT
1748
+ */
1749
+ readNonblock(len, buf = null, { exception = true } = {}) {
1750
+ if (len < 0)
1751
+ throw new ArgumentError(`negative length ${len} given`);
1752
+ if (exception !== true && exception !== false) {
1753
+ throw new ArgumentError(`expected true or false as exception: ${rbInspect(exception)}`);
1754
+ }
1755
+ this._checkReadable();
1756
+ if (len === 0)
1757
+ return new Uint8Array(0);
1758
+ if (this._pipe.length === 0) {
1759
+ if (!this._pipe.writerClosed) {
1760
+ if (!exception)
1761
+ return "wait_readable";
1762
+ throw new IO.EAGAINWaitReadable("read would block");
1763
+ }
1764
+ if (buf)
1765
+ buf.fill(0);
1766
+ if (!exception)
1767
+ return null;
1768
+ throw new EOFError("end of file reached");
1769
+ }
1770
+ const out = this._shift(len);
1771
+ if (buf)
1772
+ buf.set(out.subarray(0, buf.length));
1773
+ return out;
1774
+ }
1775
+ /**
1776
+ * `IO#wait_readable` (`vendor/ruby/v3.3.11/io.c:9742` `io_wait_readable`):
1777
+ * resolves with the reader once a byte or end of file can be read, or with
1778
+ * `nil` once `timeout` seconds pass first (`io.c:9710-9716`). A reader
1779
+ * closed during the wait raises `IOError` (`io.c:1451-1458`).
1780
+ *
1781
+ * @noRailsEquivalent PERMANENT
1782
+ */
1783
+ async waitReadable(timeout = null) {
1784
+ this._checkReadable();
1785
+ if (timeout !== null && timeout < 0)
1786
+ throw new ArgumentError("time interval must not be negative");
1787
+ if (this._pipe.length > 0 || this._pipe.writerClosed)
1788
+ return this;
1789
+ const ready = await new Promise((resolve) => {
1790
+ const wake = () => {
1791
+ if (timer !== null)
1792
+ clearTimeout(timer);
1793
+ resolve(true);
1794
+ };
1795
+ const timer = timeout === null
1796
+ ? null
1797
+ : setTimeout(() => {
1798
+ this._pipe.waiting.splice(this._pipe.waiting.indexOf(wake), 1);
1799
+ resolve(false);
1800
+ }, timeout * 1000);
1801
+ this._pipe.waiting.push(wake);
1802
+ });
1803
+ if (this._closed)
1804
+ throw new IOError("closed stream");
1805
+ return ready ? this : null;
1806
+ }
1807
+ /**
1808
+ * {@link gets} awaited where `rb_io_gets_m` (`vendor/ruby/v3.3.11/io.c:4363`)
1809
+ * blocks: the bytes up to and including the next `sep`, or the rest once the
1810
+ * writer is closed, as a String; `nil` at end of file.
1811
+ *
1812
+ * @noRailsEquivalent PERMANENT
1813
+ */
1814
+ async getsAsync(sep = "\n") {
1815
+ const rsptr = new TextEncoder().encode(sep);
1816
+ for (;;) {
1817
+ this._checkReadable();
1818
+ const buffered = this._peek();
1819
+ let take = -1;
1820
+ for (let i = 0; i + rsptr.length <= buffered.length; i++) {
1821
+ if (rsptr.every((c, j) => buffered[i + j] === c)) {
1822
+ take = i + rsptr.length;
1823
+ break;
1824
+ }
1825
+ }
1826
+ if (take === -1 && this._pipe.writerClosed)
1827
+ take = buffered.length;
1828
+ if (take === 0)
1829
+ return null;
1830
+ if (take > 0)
1831
+ return new TextDecoder().decode(this._shift(take));
1832
+ await new Promise((resolve) => this._pipe.waiting.push(resolve));
1833
+ }
1834
+ }
1835
+ async readAsync(length) {
1836
+ this._checkReadable();
1837
+ while (!this._pipe.writerClosed && (length == null || this._pipe.length < length)) {
1838
+ await new Promise((resolve) => this._pipe.waiting.push(resolve));
1839
+ this._checkReadable();
1840
+ }
1841
+ return this.read(length ?? null);
1842
+ }
1843
+ /**
1844
+ * `IO#write` (`vendor/ruby/v3.3.11/io.c:2263` `io_write_m`); a pipe whose
1845
+ * reader is closed raises `Errno::EPIPE`, as `write(2)` does.
1846
+ *
1847
+ * @noRailsEquivalent PERMANENT
1848
+ */
1849
+ write(string) {
1850
+ this._checkWritable();
1851
+ const bytes = typeof string === "string" ? new TextEncoder().encode(string) : string;
1852
+ this._push(bytes);
1853
+ return bytes.length;
1854
+ }
1855
+ /**
1856
+ * `IO#write_nonblock` (`vendor/ruby/v3.3.11/io.rb:120`, `io.c:3666`
1857
+ * `io_write_nonblock`): `buf` is sent `to_s` (`io.c:3671-3672`), a
1858
+ * non-boolean `exception` raises `ArgumentError` (`io.c:3673`), and as many
1859
+ * bytes as the pipe has room for are written. With no room it raises
1860
+ * `IO::EAGAINWaitWritable` ("write would block", `io.c:3693`), or answers
1861
+ * `:wait_writable` (`io.c:3690`).
1862
+ *
1863
+ * @noRailsEquivalent PERMANENT
1864
+ */
1865
+ writeNonblock(buf, { exception = true } = {}) {
1866
+ const str = rbObjAsString(buf);
1867
+ if (exception !== true && exception !== false) {
1868
+ throw new ArgumentError(`expected true or false as exception: ${rbInspect(exception)}`);
1869
+ }
1870
+ this._checkWritable();
1871
+ const bytes = typeof str === "string" ? new TextEncoder().encode(str) : str;
1872
+ if (bytes.length === 0)
1873
+ return 0;
1874
+ const room = PIPE_CAPACITY - this._pipe.length;
1875
+ if (room <= 0) {
1876
+ if (!exception)
1877
+ return "wait_writable";
1878
+ throw new IO.EAGAINWaitWritable("write would block");
1879
+ }
1880
+ const written = Math.min(room, bytes.length);
1881
+ this._push(bytes.slice(0, written));
1882
+ return written;
1883
+ }
1884
+ /** @noRailsEquivalent PERMANENT */
1885
+ isClosed() {
1886
+ return this._closed;
1887
+ }
1888
+ /**
1889
+ * `IO#close` (`vendor/ruby/v3.3.11/io.c:5777`): closing the writer is end of
1890
+ * file to the reader; closing the reader drops what it had not read.
1891
+ *
1892
+ * @noRailsEquivalent PERMANENT
1893
+ */
1894
+ close() {
1895
+ if (this._closed)
1896
+ return null;
1897
+ this._closed = true;
1898
+ if (this.mode & FMODE_WRITABLE) {
1899
+ if (--this._pipe.writers === 0)
1900
+ this._pipe.writerClosed = true;
1901
+ }
1902
+ else {
1903
+ this._pipe.readerClosed = true;
1904
+ this._pipe.chunks = [];
1905
+ this._pipe.length = 0;
1906
+ }
1907
+ for (const wake of this._pipe.waiting.splice(0))
1908
+ wake();
1909
+ return null;
1910
+ }
1911
+ _checkReadable() {
1912
+ if (this._closed)
1913
+ throw new IOError("closed stream");
1914
+ if (!(this.mode & FMODE_READABLE))
1915
+ throw new IOError("not opened for reading");
1916
+ }
1917
+ _checkWritable() {
1918
+ if (this._closed)
1919
+ throw new IOError("closed stream");
1920
+ if (!(this.mode & FMODE_WRITABLE))
1921
+ throw new IOError("not opened for writing");
1922
+ if (this._pipe.readerClosed)
1923
+ throw new Errno.EPIPE();
1924
+ }
1925
+ _push(bytes) {
1926
+ if (bytes.length === 0)
1927
+ return;
1928
+ this._pipe.chunks.push(bytes);
1929
+ this._pipe.length += bytes.length;
1930
+ for (const wake of this._pipe.waiting.splice(0))
1931
+ wake();
1932
+ }
1933
+ _peek() {
1934
+ const out = new Uint8Array(this._pipe.length);
1935
+ let n = 0;
1936
+ for (const chunk of this._pipe.chunks) {
1937
+ out.set(chunk, n);
1938
+ n += chunk.length;
1939
+ }
1940
+ return out;
1941
+ }
1942
+ _shift(length) {
1943
+ const pipe = this._pipe;
1944
+ const out = new Uint8Array(Math.min(length, pipe.length));
1945
+ let n = 0;
1946
+ while (n < out.length) {
1947
+ const chunk = pipe.chunks[0];
1948
+ const take = Math.min(chunk.length, out.length - n);
1949
+ out.set(chunk.subarray(0, take), n);
1950
+ n += take;
1951
+ if (take === chunk.length)
1952
+ pipe.chunks.shift();
1953
+ else
1954
+ pipe.chunks[0] = chunk.subarray(take);
1955
+ }
1956
+ pipe.length -= n;
1957
+ return out;
1958
+ }
1959
+ }
1960
+ //# sourceMappingURL=io.js.map