@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.
- package/LICENSE +21 -0
- package/NOTICE +6 -0
- package/README.md +440 -2
- package/dist/argument-error.d.ts +15 -0
- package/dist/argument-error.js +15 -0
- package/dist/argument-error.js.map +1 -0
- package/dist/array.d.ts +415 -0
- package/dist/array.js +1330 -0
- package/dist/array.js.map +1 -0
- package/dist/async-context-adapter.d.ts +19 -0
- package/dist/async-context-adapter.js +139 -0
- package/dist/async-context-adapter.js.map +1 -0
- package/dist/backtrace-location.d.ts +77 -0
- package/dist/backtrace-location.js +155 -0
- package/dist/backtrace-location.js.map +1 -0
- package/dist/base64.d.ts +73 -0
- package/dist/base64.js +164 -0
- package/dist/base64.js.map +1 -0
- package/dist/benchmark.d.ts +19 -0
- package/dist/benchmark.js +16 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/big-decimal.d.ts +110 -0
- package/dist/big-decimal.js +582 -0
- package/dist/big-decimal.js.map +1 -0
- package/dist/bundler.d.ts +44 -0
- package/dist/bundler.js +101 -0
- package/dist/bundler.js.map +1 -0
- package/dist/cgi.d.ts +89 -0
- package/dist/cgi.js +168 -0
- package/dist/cgi.js.map +1 -0
- package/dist/child-process-adapter.d.ts +110 -0
- package/dist/child-process-adapter.js +272 -0
- package/dist/child-process-adapter.js.map +1 -0
- package/dist/class-module.d.ts +10 -0
- package/dist/class-module.js +10 -0
- package/dist/class-module.js.map +1 -0
- package/dist/classpath.d.ts +90 -0
- package/dist/classpath.js +207 -0
- package/dist/classpath.js.map +1 -0
- package/dist/closed-queue-error.d.ts +10 -0
- package/dist/closed-queue-error.js +10 -0
- package/dist/closed-queue-error.js.map +1 -0
- package/dist/comparable.d.ts +127 -0
- package/dist/comparable.js +376 -0
- package/dist/comparable.js.map +1 -0
- package/dist/complex.d.ts +48 -0
- package/dist/complex.js +162 -0
- package/dist/complex.js.map +1 -0
- package/dist/concurrent/atomic-boolean.d.ts +24 -0
- package/dist/concurrent/atomic-boolean.js +43 -0
- package/dist/concurrent/atomic-boolean.js.map +1 -0
- package/dist/concurrent/atomic-fixnum.d.ts +21 -0
- package/dist/concurrent/atomic-fixnum.js +35 -0
- package/dist/concurrent/atomic-fixnum.js.map +1 -0
- package/dist/concurrent/count-down-latch.d.ts +20 -0
- package/dist/concurrent/count-down-latch.js +50 -0
- package/dist/concurrent/count-down-latch.js.map +1 -0
- package/dist/concurrent/cyclic-barrier.d.ts +18 -0
- package/dist/concurrent/cyclic-barrier.js +50 -0
- package/dist/concurrent/cyclic-barrier.js.map +1 -0
- package/dist/concurrent/event.d.ts +19 -0
- package/dist/concurrent/event.js +31 -0
- package/dist/concurrent/event.js.map +1 -0
- package/dist/concurrent/map.d.ts +149 -0
- package/dist/concurrent/map.js +202 -0
- package/dist/concurrent/map.js.map +1 -0
- package/dist/concurrent/read-write-lock.d.ts +25 -0
- package/dist/concurrent/read-write-lock.js +70 -0
- package/dist/concurrent/read-write-lock.js.map +1 -0
- package/dist/concurrent/semaphore.d.ts +24 -0
- package/dist/concurrent/semaphore.js +74 -0
- package/dist/concurrent/semaphore.js.map +1 -0
- package/dist/concurrent/timer-task.d.ts +52 -0
- package/dist/concurrent/timer-task.js +112 -0
- package/dist/concurrent/timer-task.js.map +1 -0
- package/dist/constants.generated.d.ts +2 -0
- package/dist/constants.generated.js +64 -0
- package/dist/constants.generated.js.map +1 -0
- package/dist/converter-not-found-error.d.ts +14 -0
- package/dist/converter-not-found-error.js +14 -0
- package/dist/converter-not-found-error.js.map +1 -0
- package/dist/crypto-adapter.d.ts +64 -0
- package/dist/crypto-adapter.js +365 -0
- package/dist/crypto-adapter.js.map +1 -0
- package/dist/delegate.d.ts +156 -0
- package/dist/delegate.js +306 -0
- package/dist/delegate.js.map +1 -0
- package/dist/digest.d.ts +99 -0
- package/dist/digest.js +131 -0
- package/dist/digest.js.map +1 -0
- package/dist/dir.d.ts +218 -0
- package/dist/dir.js +599 -0
- package/dist/dir.js.map +1 -0
- package/dist/encoding-error.d.ts +14 -0
- package/dist/encoding-error.js +17 -0
- package/dist/encoding-error.js.map +1 -0
- package/dist/encoding.d.ts +121 -0
- package/dist/encoding.js +306 -0
- package/dist/encoding.js.map +1 -0
- package/dist/ensure.d.ts +15 -0
- package/dist/ensure.js +35 -0
- package/dist/ensure.js.map +1 -0
- package/dist/enumerable.d.ts +375 -0
- package/dist/enumerable.js +1100 -0
- package/dist/enumerable.js.map +1 -0
- package/dist/enumerator.d.ts +321 -0
- package/dist/enumerator.js +642 -0
- package/dist/enumerator.js.map +1 -0
- package/dist/eof-error.d.ts +14 -0
- package/dist/eof-error.js +14 -0
- package/dist/eof-error.js.map +1 -0
- package/dist/errno.d.ts +327 -0
- package/dist/errno.js +452 -0
- package/dist/errno.js.map +1 -0
- package/dist/exc-detailed-message.d.ts +15 -0
- package/dist/exc-detailed-message.js +106 -0
- package/dist/exc-detailed-message.js.map +1 -0
- package/dist/exc-to-s.d.ts +10 -0
- package/dist/exc-to-s.js +21 -0
- package/dist/exc-to-s.js.map +1 -0
- package/dist/exception.d.ts +34 -0
- package/dist/exception.js +99 -0
- package/dist/exception.js.map +1 -0
- package/dist/fiber-error.d.ts +12 -0
- package/dist/fiber-error.js +12 -0
- package/dist/fiber-error.js.map +1 -0
- package/dist/fiber.d.ts +51 -0
- package/dist/fiber.js +178 -0
- package/dist/fiber.js.map +1 -0
- package/dist/file-utils.d.ts +480 -0
- package/dist/file-utils.js +1823 -0
- package/dist/file-utils.js.map +1 -0
- package/dist/file.d.ts +635 -0
- package/dist/file.js +1312 -0
- package/dist/file.js.map +1 -0
- package/dist/float-domain-error.d.ts +17 -0
- package/dist/float-domain-error.js +17 -0
- package/dist/float-domain-error.js.map +1 -0
- package/dist/fork-children.d.ts +23 -0
- package/dist/fork-children.js +32 -0
- package/dist/fork-children.js.map +1 -0
- package/dist/frozen-error.d.ts +33 -0
- package/dist/frozen-error.js +42 -0
- package/dist/frozen-error.js.map +1 -0
- package/dist/fs-adapter.d.ts +158 -0
- package/dist/fs-adapter.js +253 -0
- package/dist/fs-adapter.js.map +1 -0
- package/dist/gem/deprecate.d.ts +10 -0
- package/dist/gem/deprecate.js +8 -0
- package/dist/gem/deprecate.js.map +1 -0
- package/dist/gem/requirement.d.ts +64 -0
- package/dist/gem/requirement.js +91 -0
- package/dist/gem/requirement.js.map +1 -0
- package/dist/gem/version.d.ts +50 -0
- package/dist/gem/version.js +148 -0
- package/dist/gem/version.js.map +1 -0
- package/dist/gem.d.ts +59 -0
- package/dist/gem.js +82 -0
- package/dist/gem.js.map +1 -0
- package/dist/hash.d.ts +967 -0
- package/dist/hash.js +1572 -0
- package/dist/hash.js.map +1 -0
- package/dist/http-adapter.d.ts +123 -0
- package/dist/http-adapter.js +220 -0
- package/dist/http-adapter.js.map +1 -0
- package/dist/immediate-executor.d.ts +20 -0
- package/dist/immediate-executor.js +39 -0
- package/dist/immediate-executor.js.map +1 -0
- package/dist/include.d.ts +778 -0
- package/dist/include.js +2195 -0
- package/dist/include.js.map +1 -0
- package/dist/index-error.d.ts +13 -0
- package/dist/index-error.js +13 -0
- package/dist/index-error.js.map +1 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/invalid-byte-sequence-error.d.ts +62 -0
- package/dist/invalid-byte-sequence-error.js +75 -0
- package/dist/invalid-byte-sequence-error.js.map +1 -0
- package/dist/io-error.d.ts +14 -0
- package/dist/io-error.js +17 -0
- package/dist/io-error.js.map +1 -0
- package/dist/io.d.ts +867 -0
- package/dist/io.js +1960 -0
- package/dist/io.js.map +1 -0
- package/dist/ipaddr.d.ts +79 -0
- package/dist/ipaddr.js +405 -0
- package/dist/ipaddr.js.map +1 -0
- package/dist/json.d.ts +67 -0
- package/dist/json.js +185 -0
- package/dist/json.js.map +1 -0
- package/dist/kernel-catch.d.ts +59 -0
- package/dist/kernel-catch.js +184 -0
- package/dist/kernel-catch.js.map +1 -0
- package/dist/kernel-float.d.ts +19 -0
- package/dist/kernel-float.js +54 -0
- package/dist/kernel-float.js.map +1 -0
- package/dist/kernel-fork.d.ts +30 -0
- package/dist/kernel-fork.js +72 -0
- package/dist/kernel-fork.js.map +1 -0
- package/dist/kernel-format.d.ts +27 -0
- package/dist/kernel-format.js +901 -0
- package/dist/kernel-format.js.map +1 -0
- package/dist/kernel-hash.d.ts +7 -0
- package/dist/kernel-hash.js +33 -0
- package/dist/kernel-hash.js.map +1 -0
- package/dist/kernel-integer.d.ts +49 -0
- package/dist/kernel-integer.js +170 -0
- package/dist/kernel-integer.js.map +1 -0
- package/dist/kernel-rand.d.ts +16 -0
- package/dist/kernel-rand.js +237 -0
- package/dist/kernel-rand.js.map +1 -0
- package/dist/kernel-system.d.ts +40 -0
- package/dist/kernel-system.js +97 -0
- package/dist/kernel-system.js.map +1 -0
- package/dist/kernel-warn.d.ts +35 -0
- package/dist/kernel-warn.js +73 -0
- package/dist/kernel-warn.js.map +1 -0
- package/dist/key-error.d.ts +44 -0
- package/dist/key-error.js +59 -0
- package/dist/key-error.js.map +1 -0
- package/dist/keyword-splat.d.ts +41 -0
- package/dist/keyword-splat.js +65 -0
- package/dist/keyword-splat.js.map +1 -0
- package/dist/load-error.d.ts +19 -0
- package/dist/load-error.js +19 -0
- package/dist/load-error.js.map +1 -0
- package/dist/load.d.ts +121 -0
- package/dist/load.js +263 -0
- package/dist/load.js.map +1 -0
- package/dist/loaded-features.d.ts +13 -0
- package/dist/loaded-features.js +15 -0
- package/dist/loaded-features.js.map +1 -0
- package/dist/local-jump-error.d.ts +12 -0
- package/dist/local-jump-error.js +12 -0
- package/dist/local-jump-error.js.map +1 -0
- package/dist/logger/formatter.d.ts +21 -0
- package/dist/logger/formatter.js +43 -0
- package/dist/logger/formatter.js.map +1 -0
- package/dist/logger/log-device.d.ts +52 -0
- package/dist/logger/log-device.js +104 -0
- package/dist/logger/log-device.js.map +1 -0
- package/dist/logger/severity.d.ts +23 -0
- package/dist/logger/severity.js +42 -0
- package/dist/logger/severity.js.map +1 -0
- package/dist/logger.d.ts +127 -0
- package/dist/logger.js +215 -0
- package/dist/logger.js.map +1 -0
- package/dist/marshal.d.ts +83 -0
- package/dist/marshal.js +1487 -0
- package/dist/marshal.js.map +1 -0
- package/dist/match-data.d.ts +161 -0
- package/dist/match-data.js +284 -0
- package/dist/match-data.js.map +1 -0
- package/dist/method-cache.d.ts +17 -0
- package/dist/method-cache.js +19 -0
- package/dist/method-cache.js.map +1 -0
- package/dist/method-missing-proxy.d.ts +53 -0
- package/dist/method-missing-proxy.js +154 -0
- package/dist/method-missing-proxy.js.map +1 -0
- package/dist/method.d.ts +132 -0
- package/dist/method.js +320 -0
- package/dist/method.js.map +1 -0
- package/dist/monitor.d.ts +114 -0
- package/dist/monitor.js +270 -0
- package/dist/monitor.js.map +1 -0
- package/dist/mutex.d.ts +51 -0
- package/dist/mutex.js +150 -0
- package/dist/mutex.js.map +1 -0
- package/dist/name-error.d.ts +45 -0
- package/dist/name-error.js +54 -0
- package/dist/name-error.js.map +1 -0
- package/dist/net/http/exceptions.d.ts +31 -0
- package/dist/net/http/exceptions.js +46 -0
- package/dist/net/http/exceptions.js.map +1 -0
- package/dist/net/http/request.d.ts +137 -0
- package/dist/net/http/request.js +559 -0
- package/dist/net/http/request.js.map +1 -0
- package/dist/net/http/requests.d.ts +197 -0
- package/dist/net/http/requests.js +197 -0
- package/dist/net/http/requests.js.map +1 -0
- package/dist/net/http/response.d.ts +141 -0
- package/dist/net/http/response.js +416 -0
- package/dist/net/http/response.js.map +1 -0
- package/dist/net/http/responses.d.ts +345 -0
- package/dist/net/http/responses.js +486 -0
- package/dist/net/http/responses.js.map +1 -0
- package/dist/net/http.d.ts +278 -0
- package/dist/net/http.js +760 -0
- package/dist/net/http.js.map +1 -0
- package/dist/net/protocol.d.ts +227 -0
- package/dist/net/protocol.js +392 -0
- package/dist/net/protocol.js.map +1 -0
- package/dist/nil-class.d.ts +10 -0
- package/dist/nil-class.js +27 -0
- package/dist/nil-class.js.map +1 -0
- package/dist/no-method-error.d.ts +38 -0
- package/dist/no-method-error.js +45 -0
- package/dist/no-method-error.js.map +1 -0
- package/dist/not-implemented-error.d.ts +13 -0
- package/dist/not-implemented-error.js +14 -0
- package/dist/not-implemented-error.js.map +1 -0
- package/dist/numeric.d.ts +211 -0
- package/dist/numeric.js +802 -0
- package/dist/numeric.js.map +1 -0
- package/dist/object-space.d.ts +34 -0
- package/dist/object-space.js +152 -0
- package/dist/object-space.js.map +1 -0
- package/dist/object.d.ts +908 -0
- package/dist/object.js +2238 -0
- package/dist/object.js.map +1 -0
- package/dist/open-uri.d.ts +180 -0
- package/dist/open-uri.js +402 -0
- package/dist/open-uri.js.map +1 -0
- package/dist/open3.d.ts +69 -0
- package/dist/open3.js +134 -0
- package/dist/open3.js.map +1 -0
- package/dist/openssl.d.ts +479 -0
- package/dist/openssl.js +1052 -0
- package/dist/openssl.js.map +1 -0
- package/dist/optparse.d.ts +130 -0
- package/dist/optparse.js +457 -0
- package/dist/optparse.js.map +1 -0
- package/dist/os-adapter.d.ts +20 -0
- package/dist/os-adapter.js +95 -0
- package/dist/os-adapter.js.map +1 -0
- package/dist/pathname.d.ts +71 -0
- package/dist/pathname.js +394 -0
- package/dist/pathname.js.map +1 -0
- package/dist/pp.d.ts +60 -0
- package/dist/pp.js +195 -0
- package/dist/pp.js.map +1 -0
- package/dist/pretty-print.d.ts +89 -0
- package/dist/pretty-print.js +232 -0
- package/dist/pretty-print.js.map +1 -0
- package/dist/process-adapter.d.ts +224 -0
- package/dist/process-adapter.js +878 -0
- package/dist/process-adapter.js.map +1 -0
- package/dist/process.d.ts +192 -0
- package/dist/process.js +403 -0
- package/dist/process.js.map +1 -0
- package/dist/psych/class-loader.d.ts +92 -0
- package/dist/psych/class-loader.js +139 -0
- package/dist/psych/class-loader.js.map +1 -0
- package/dist/psych/coder.d.ts +144 -0
- package/dist/psych/coder.js +176 -0
- package/dist/psych/coder.js.map +1 -0
- package/dist/psych/core-ext.d.ts +8 -0
- package/dist/psych/core-ext.js +10 -0
- package/dist/psych/core-ext.js.map +1 -0
- package/dist/psych/emitter.d.ts +116 -0
- package/dist/psych/emitter.js +1130 -0
- package/dist/psych/emitter.js.map +1 -0
- package/dist/psych/exception.d.ts +43 -0
- package/dist/psych/exception.js +54 -0
- package/dist/psych/exception.js.map +1 -0
- package/dist/psych/handler.d.ts +59 -0
- package/dist/psych/handler.js +95 -0
- package/dist/psych/handler.js.map +1 -0
- package/dist/psych/handlers/document-stream.d.ts +17 -0
- package/dist/psych/handlers/document-stream.js +26 -0
- package/dist/psych/handlers/document-stream.js.map +1 -0
- package/dist/psych/nodes/alias.d.ts +15 -0
- package/dist/psych/nodes/alias.js +22 -0
- package/dist/psych/nodes/alias.js.map +1 -0
- package/dist/psych/nodes/document.d.ts +23 -0
- package/dist/psych/nodes/document.js +35 -0
- package/dist/psych/nodes/document.js.map +1 -0
- package/dist/psych/nodes/mapping.d.ts +25 -0
- package/dist/psych/nodes/mapping.js +35 -0
- package/dist/psych/nodes/mapping.js.map +1 -0
- package/dist/psych/nodes/node.d.ts +59 -0
- package/dist/psych/nodes/node.js +79 -0
- package/dist/psych/nodes/node.js.map +1 -0
- package/dist/psych/nodes/scalar.d.ts +35 -0
- package/dist/psych/nodes/scalar.js +47 -0
- package/dist/psych/nodes/scalar.js.map +1 -0
- package/dist/psych/nodes/sequence.d.ts +25 -0
- package/dist/psych/nodes/sequence.js +35 -0
- package/dist/psych/nodes/sequence.js.map +1 -0
- package/dist/psych/nodes/stream.d.ts +23 -0
- package/dist/psych/nodes/stream.js +31 -0
- package/dist/psych/nodes/stream.js.map +1 -0
- package/dist/psych/omap.d.ts +9 -0
- package/dist/psych/omap.js +9 -0
- package/dist/psych/omap.js.map +1 -0
- package/dist/psych/parser.d.ts +41 -0
- package/dist/psych/parser.js +139 -0
- package/dist/psych/parser.js.map +1 -0
- package/dist/psych/scalar-scanner.d.ts +35 -0
- package/dist/psych/scalar-scanner.js +173 -0
- package/dist/psych/scalar-scanner.js.map +1 -0
- package/dist/psych/syntax-error.d.ts +23 -0
- package/dist/psych/syntax-error.js +35 -0
- package/dist/psych/syntax-error.js.map +1 -0
- package/dist/psych/tree-builder.d.ts +51 -0
- package/dist/psych/tree-builder.js +118 -0
- package/dist/psych/tree-builder.js.map +1 -0
- package/dist/psych/visitors/depth-first.d.ts +27 -0
- package/dist/psych/visitors/depth-first.js +37 -0
- package/dist/psych/visitors/depth-first.js.map +1 -0
- package/dist/psych/visitors/emitter.d.ts +32 -0
- package/dist/psych/visitors/emitter.js +63 -0
- package/dist/psych/visitors/emitter.js.map +1 -0
- package/dist/psych/visitors/to-ruby.d.ts +110 -0
- package/dist/psych/visitors/to-ruby.js +396 -0
- package/dist/psych/visitors/to-ruby.js.map +1 -0
- package/dist/psych/visitors/visitor.d.ts +11 -0
- package/dist/psych/visitors/visitor.js +17 -0
- package/dist/psych/visitors/visitor.js.map +1 -0
- package/dist/psych/visitors/yaml-tree.d.ts +182 -0
- package/dist/psych/visitors/yaml-tree.js +593 -0
- package/dist/psych/visitors/yaml-tree.js.map +1 -0
- package/dist/psych-adapter.d.ts +65 -0
- package/dist/psych-adapter.js +121 -0
- package/dist/psych-adapter.js.map +1 -0
- package/dist/psych-yaml.d.ts +2 -0
- package/dist/psych-yaml.js +5 -0
- package/dist/psych-yaml.js.map +1 -0
- package/dist/psych.d.ts +257 -0
- package/dist/psych.js +332 -0
- package/dist/psych.js.map +1 -0
- package/dist/queue.d.ts +129 -0
- package/dist/queue.js +215 -0
- package/dist/queue.js.map +1 -0
- package/dist/racc/parser.d.ts +70 -0
- package/dist/racc/parser.js +206 -0
- package/dist/racc/parser.js.map +1 -0
- package/dist/range-error.d.ts +15 -0
- package/dist/range-error.js +15 -0
- package/dist/range-error.js.map +1 -0
- package/dist/range.d.ts +166 -0
- package/dist/range.js +421 -0
- package/dist/range.js.map +1 -0
- package/dist/rational.d.ts +167 -0
- package/dist/rational.js +379 -0
- package/dist/rational.js.map +1 -0
- package/dist/rb-config.d.ts +33 -0
- package/dist/rb-config.js +53 -0
- package/dist/rb-config.js.map +1 -0
- package/dist/rb-equal.d.ts +66 -0
- package/dist/rb-equal.js +261 -0
- package/dist/rb-equal.js.map +1 -0
- package/dist/rb-hash.d.ts +26 -0
- package/dist/rb-hash.js +108 -0
- package/dist/rb-hash.js.map +1 -0
- package/dist/regexp.d.ts +82 -0
- package/dist/regexp.js +191 -0
- package/dist/regexp.js.map +1 -0
- package/dist/repl-adapter.d.ts +188 -0
- package/dist/repl-adapter.js +388 -0
- package/dist/repl-adapter.js.map +1 -0
- package/dist/resolv.d.ts +30 -0
- package/dist/resolv.js +48 -0
- package/dist/resolv.js.map +1 -0
- package/dist/ruby-empty.d.ts +28 -0
- package/dist/ruby-empty.js +40 -0
- package/dist/ruby-empty.js.map +1 -0
- package/dist/ruby-platform.d.ts +39 -0
- package/dist/ruby-platform.js +49 -0
- package/dist/ruby-platform.js.map +1 -0
- package/dist/runtime-error.d.ts +15 -0
- package/dist/runtime-error.js +16 -0
- package/dist/runtime-error.js.map +1 -0
- package/dist/scheduled-task.d.ts +73 -0
- package/dist/scheduled-task.js +150 -0
- package/dist/scheduled-task.js.map +1 -0
- package/dist/secure-random.d.ts +33 -0
- package/dist/secure-random.js +78 -0
- package/dist/secure-random.js.map +1 -0
- package/dist/set.d.ts +158 -0
- package/dist/set.js +352 -0
- package/dist/set.js.map +1 -0
- package/dist/shellwords.d.ts +27 -0
- package/dist/shellwords.js +53 -0
- package/dist/shellwords.js.map +1 -0
- package/dist/signal-exception.d.ts +21 -0
- package/dist/signal-exception.js +21 -0
- package/dist/signal-exception.js.map +1 -0
- package/dist/socket.d.ts +230 -0
- package/dist/socket.js +484 -0
- package/dist/socket.js.map +1 -0
- package/dist/standard-error.d.ts +18 -0
- package/dist/standard-error.js +23 -0
- package/dist/standard-error.js.map +1 -0
- package/dist/stop-iteration.d.ts +10 -0
- package/dist/stop-iteration.js +10 -0
- package/dist/stop-iteration.js.map +1 -0
- package/dist/string/b.d.ts +19 -0
- package/dist/string/b.js +28 -0
- package/dist/string/b.js.map +1 -0
- package/dist/string/byte-methods.d.ts +57 -0
- package/dist/string/byte-methods.js +266 -0
- package/dist/string/byte-methods.js.map +1 -0
- package/dist/string/bytes.d.ts +35 -0
- package/dist/string/bytes.js +123 -0
- package/dist/string/bytes.js.map +1 -0
- package/dist/string/case-mapping.d.ts +57 -0
- package/dist/string/case-mapping.js +192 -0
- package/dist/string/case-mapping.js.map +1 -0
- package/dist/string/chomp.d.ts +15 -0
- package/dist/string/chomp.js +32 -0
- package/dist/string/chomp.js.map +1 -0
- package/dist/string/convert.d.ts +55 -0
- package/dist/string/convert.js +316 -0
- package/dist/string/convert.js.map +1 -0
- package/dist/string/delete.d.ts +14 -0
- package/dist/string/delete.js +17 -0
- package/dist/string/delete.js.map +1 -0
- package/dist/string/each.d.ts +108 -0
- package/dist/string/each.js +305 -0
- package/dist/string/each.js.map +1 -0
- package/dist/string/encode.d.ts +37 -0
- package/dist/string/encode.js +268 -0
- package/dist/string/encode.js.map +1 -0
- package/dist/string/force-encoding.d.ts +72 -0
- package/dist/string/force-encoding.js +147 -0
- package/dist/string/force-encoding.js.map +1 -0
- package/dist/string/inspect.d.ts +17 -0
- package/dist/string/inspect.js +81 -0
- package/dist/string/inspect.js.map +1 -0
- package/dist/string/method-table.d.ts +174 -0
- package/dist/string/method-table.js +805 -0
- package/dist/string/method-table.js.map +1 -0
- package/dist/string/scrub.d.ts +12 -0
- package/dist/string/scrub.js +33 -0
- package/dist/string/scrub.js.map +1 -0
- package/dist/string/slice.d.ts +26 -0
- package/dist/string/slice.js +73 -0
- package/dist/string/slice.js.map +1 -0
- package/dist/string/split.d.ts +11 -0
- package/dist/string/split.js +44 -0
- package/dist/string/split.js.map +1 -0
- package/dist/string/sub.d.ts +114 -0
- package/dist/string/sub.js +371 -0
- package/dist/string/sub.js.map +1 -0
- package/dist/string/succ.d.ts +14 -0
- package/dist/string/succ.js +118 -0
- package/dist/string/succ.js.map +1 -0
- package/dist/string/support.d.ts +135 -0
- package/dist/string/support.js +283 -0
- package/dist/string/support.js.map +1 -0
- package/dist/string/tr.d.ts +46 -0
- package/dist/string/tr.js +156 -0
- package/dist/string/tr.js.map +1 -0
- package/dist/string-io.d.ts +166 -0
- package/dist/string-io.js +248 -0
- package/dist/string-io.js.map +1 -0
- package/dist/string-scanner.d.ts +133 -0
- package/dist/string-scanner.js +248 -0
- package/dist/string-scanner.js.map +1 -0
- package/dist/struct.d.ts +54 -0
- package/dist/struct.js +222 -0
- package/dist/struct.js.map +1 -0
- package/dist/symbol.d.ts +48 -0
- package/dist/symbol.js +107 -0
- package/dist/symbol.js.map +1 -0
- package/dist/tempfile.d.ts +173 -0
- package/dist/tempfile.js +290 -0
- package/dist/tempfile.js.map +1 -0
- package/dist/temporal-tag.d.ts +23 -0
- package/dist/temporal-tag.js +29 -0
- package/dist/temporal-tag.js.map +1 -0
- package/dist/thread-error.d.ts +13 -0
- package/dist/thread-error.js +13 -0
- package/dist/thread-error.js.map +1 -0
- package/dist/thread-pool-executor.d.ts +119 -0
- package/dist/thread-pool-executor.js +250 -0
- package/dist/thread-pool-executor.js.map +1 -0
- package/dist/thread.d.ts +211 -0
- package/dist/thread.js +495 -0
- package/dist/thread.js.map +1 -0
- package/dist/timeout.d.ts +29 -0
- package/dist/timeout.js +41 -0
- package/dist/timeout.js.map +1 -0
- package/dist/tse.d.ts +40 -0
- package/dist/tse.js +62 -0
- package/dist/tse.js.map +1 -0
- package/dist/type-error.d.ts +14 -0
- package/dist/type-error.js +15 -0
- package/dist/type-error.js.map +1 -0
- package/dist/undefined-conversion-error.d.ts +10 -0
- package/dist/undefined-conversion-error.js +10 -0
- package/dist/undefined-conversion-error.js.map +1 -0
- package/dist/uri/common.d.ts +209 -0
- package/dist/uri/common.js +369 -0
- package/dist/uri/common.js.map +1 -0
- package/dist/uri/generic.d.ts +283 -0
- package/dist/uri/generic.js +810 -0
- package/dist/uri/generic.js.map +1 -0
- package/dist/uri/http.d.ts +23 -0
- package/dist/uri/http.js +30 -0
- package/dist/uri/http.js.map +1 -0
- package/dist/uri/https.d.ts +13 -0
- package/dist/uri/https.js +15 -0
- package/dist/uri/https.js.map +1 -0
- package/dist/uri/rfc2396-parser.d.ts +70 -0
- package/dist/uri/rfc2396-parser.js +264 -0
- package/dist/uri/rfc2396-parser.js.map +1 -0
- package/dist/uri/rfc3986-parser.d.ts +46 -0
- package/dist/uri/rfc3986-parser.js +171 -0
- package/dist/uri/rfc3986-parser.js.map +1 -0
- package/dist/uri.d.ts +13 -0
- package/dist/uri.js +13 -0
- package/dist/uri.js.map +1 -0
- package/dist/variable.d.ts +183 -0
- package/dist/variable.js +463 -0
- package/dist/variable.js.map +1 -0
- package/dist/verbose.d.ts +21 -0
- package/dist/verbose.js +26 -0
- package/dist/verbose.js.map +1 -0
- package/dist/yaml.d.ts +9 -0
- package/dist/yaml.js +9 -0
- package/dist/yaml.js.map +1 -0
- package/dist/zlib-adapter.d.ts +117 -0
- package/dist/zlib-adapter.js +250 -0
- package/dist/zlib-adapter.js.map +1 -0
- package/dist/zlib.d.ts +248 -0
- package/dist/zlib.js +362 -0
- package/dist/zlib.js.map +1 -0
- package/package.json +82 -3
package/dist/file.js
ADDED
|
@@ -0,0 +1,1312 @@
|
|
|
1
|
+
import { constSet } from "./include.js";
|
|
2
|
+
import { TopLevel } from "./object.js";
|
|
3
|
+
import { getProcessAdapter } from "./process-adapter.js";
|
|
4
|
+
import { ArgumentError } from "./argument-error.js";
|
|
5
|
+
import { getFs, getPath } from "./fs-adapter.js";
|
|
6
|
+
import { IO } from "./io.js";
|
|
7
|
+
import { NotImplementedError } from "./not-implemented-error.js";
|
|
8
|
+
import { stringValue } from "./string/support.js";
|
|
9
|
+
/** `FMODE_SETENC_BY_BOM` (`vendor/ruby/v3.3.11/include/ruby/io.h:368`). */
|
|
10
|
+
const FMODE_SETENC_BY_BOM = 0x00100000;
|
|
11
|
+
/**
|
|
12
|
+
* `rb_get_path` (`vendor/ruby/v3.3.11/file.c:246`), the `FilePathValue` conversion:
|
|
13
|
+
* a String is the path, anything else is asked for `to_path`, and the answer (the
|
|
14
|
+
* object itself where it has no `to_path`) goes through `StringValue`
|
|
15
|
+
* (`rb_get_path_check_to_string`, `file.c:212-224`).
|
|
16
|
+
*
|
|
17
|
+
* @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/file.c:246`
|
|
18
|
+
*/
|
|
19
|
+
export function rbGetPath(obj) {
|
|
20
|
+
if (typeof obj === "string")
|
|
21
|
+
return obj;
|
|
22
|
+
const toPath = obj?.toPath;
|
|
23
|
+
const tmp = typeof toPath === "function" ? toPath.call(obj) : obj;
|
|
24
|
+
return stringValue(tmp);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `rb_stat` (`vendor/ruby/v3.3.11/file.c:1296`), which `fstat`s an open stream and
|
|
28
|
+
* `stat`s a name, answering `< 0` — `null` here — where the call fails.
|
|
29
|
+
*/
|
|
30
|
+
function rbStat(file) {
|
|
31
|
+
try {
|
|
32
|
+
return typeof file === "string" ? getFs().statSync(file) : file.stat();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function rbStatAsync(file) {
|
|
39
|
+
try {
|
|
40
|
+
if (typeof file !== "string")
|
|
41
|
+
return file.stat();
|
|
42
|
+
const fs = getFs();
|
|
43
|
+
return fs.stat ? await fs.stat(file) : fs.statSync(file);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `isdirsep` (`vendor/ruby/v3.3.11/file.c:3306,3311`) — `'/'` on every platform, and
|
|
51
|
+
* `FILE_ALT_SEPARATOR` as well where the build defines one (`file.c:3303`).
|
|
52
|
+
*/
|
|
53
|
+
function isdirsep(c) {
|
|
54
|
+
return c === File.SEPARATOR || c === File.ALT_SEPARATOR;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* `chompdirsep` (`vendor/ruby/v3.3.11/file.c:3484`), which answers the path without
|
|
58
|
+
* the run of separators that terminates it, and the whole path where none
|
|
59
|
+
* does.
|
|
60
|
+
*/
|
|
61
|
+
function chompdirsep(path) {
|
|
62
|
+
let end = path.length;
|
|
63
|
+
while (end > 0 && isdirsep(path[end - 1]))
|
|
64
|
+
end--;
|
|
65
|
+
return path.slice(0, end);
|
|
66
|
+
}
|
|
67
|
+
const joining = new Set();
|
|
68
|
+
/**
|
|
69
|
+
* `file_inspect_join` (`vendor/ruby/v3.3.11/file.c:5006`), the `rb_exec_recursive`
|
|
70
|
+
* callback that joins a nested Array component.
|
|
71
|
+
*/
|
|
72
|
+
function fileInspectJoin(ary, arg) {
|
|
73
|
+
if (joining.has(arg) || ary === arg)
|
|
74
|
+
throw new ArgumentError("recursive array");
|
|
75
|
+
joining.add(arg);
|
|
76
|
+
try {
|
|
77
|
+
return rbFileJoin(arg);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
joining.delete(arg);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** `rb_file_join` (`vendor/ruby/v3.3.11/file.c:5013`). */
|
|
84
|
+
function rbFileJoin(ary) {
|
|
85
|
+
if (ary.length === 0)
|
|
86
|
+
return "";
|
|
87
|
+
let result = "";
|
|
88
|
+
for (let i = 0; i < ary.length; i++) {
|
|
89
|
+
let tmp = ary[i];
|
|
90
|
+
if (typeof tmp !== "string") {
|
|
91
|
+
if (ary === tmp)
|
|
92
|
+
throw new ArgumentError("recursive array");
|
|
93
|
+
tmp = Array.isArray(tmp)
|
|
94
|
+
? fileInspectJoin(ary, tmp)
|
|
95
|
+
: rbGetPath(tmp);
|
|
96
|
+
}
|
|
97
|
+
if (i !== 0) {
|
|
98
|
+
const tail = chompdirsep(result);
|
|
99
|
+
if (isdirsep(tmp.charAt(0)))
|
|
100
|
+
result = tail;
|
|
101
|
+
else if (tail.length === result.length)
|
|
102
|
+
result = `${result}${File.SEPARATOR}`;
|
|
103
|
+
}
|
|
104
|
+
result = `${result}${tmp}`;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `to_uid` (`vendor/ruby/v3.3.11/file.c:2661`), which maps a `nil` owner onto `-1` —
|
|
110
|
+
* the id `chown(2)` reads as "leave this one unchanged".
|
|
111
|
+
*/
|
|
112
|
+
function toUid(u) {
|
|
113
|
+
if (u == null)
|
|
114
|
+
return -1;
|
|
115
|
+
return u;
|
|
116
|
+
}
|
|
117
|
+
/** `to_gid` (`vendor/ruby/v3.3.11/file.c:2670`), `to_uid`'s group half. */
|
|
118
|
+
function toGid(g) {
|
|
119
|
+
if (g == null)
|
|
120
|
+
return -1;
|
|
121
|
+
return g;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* `File` (`vendor/ruby/v3.3.11/file.c:7354` `rb_cFile`), the sliver of it trails calls.
|
|
125
|
+
*
|
|
126
|
+
* Rails reaches the filesystem through this class — `File.exist?(key)` in
|
|
127
|
+
* `vendor/rails/v8.0.5.2/activesupport/lib/active_support/cache/file_store.rb:125`,
|
|
128
|
+
* `File.join(cache_path, ...)` at `file_store.rb:185`,
|
|
129
|
+
* `File.realpath(dir)` at `file_store.rb:196` — so trails reaches it through a
|
|
130
|
+
* class of the same name rather than through members named after node's `fs`.
|
|
131
|
+
* The backend a member lands on is the `FsAdapter` contract in
|
|
132
|
+
* `./fs-adapter.js`; a platform registers one, and nothing here names a
|
|
133
|
+
* runtime.
|
|
134
|
+
*
|
|
135
|
+
* Only the members ported bodies call are here. `File::SEPARATOR` is `"/"` on
|
|
136
|
+
* every platform (`vendor/ruby/v3.3.11/file.c:7427`); the backslash is
|
|
137
|
+
* `File::ALT_SEPARATOR`, which is `nil` off DOSISH (`file.c:7435`).
|
|
138
|
+
*
|
|
139
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File` (`vendor/ruby/v3.3.11/file.c:7354`),
|
|
140
|
+
* which Rails calls without defining, so no Rails or gem file declares the
|
|
141
|
+
* class this file's single export lives in.
|
|
142
|
+
*/
|
|
143
|
+
export class File extends IO {
|
|
144
|
+
/**
|
|
145
|
+
* `rb_file_initialize` (`vendor/ruby/v3.3.11/io.c:9616`) over `rb_open_file`
|
|
146
|
+
* (`io.c:8102`): `File.new(filename, mode = "r", opt)` opens the named file.
|
|
147
|
+
* Ruby's mode string carries the binary flag node's `flags` has no letter
|
|
148
|
+
* for, so `b` is dropped from the flags and recorded on the stream instead
|
|
149
|
+
* (`rb_io_binmode`, `io.c:6311`), and everything after the first `:` is
|
|
150
|
+
* `parse_mode_enc`'s encoding (`io.c:6667,6883-6886`).
|
|
151
|
+
*
|
|
152
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.new`
|
|
153
|
+
* (`vendor/ruby/v3.3.11/io.c:9616`).
|
|
154
|
+
*
|
|
155
|
+
* An Integer `fileName` is `rb_file_initialize`'s fd arm, `rb_io_initialize`
|
|
156
|
+
* over a descriptor already open, which has no path.
|
|
157
|
+
*/
|
|
158
|
+
constructor(fileName, mode = "r", opt) {
|
|
159
|
+
if (typeof mode === "object") {
|
|
160
|
+
opt = mode;
|
|
161
|
+
mode = opt.mode ?? "r";
|
|
162
|
+
if (opt.binmode === true)
|
|
163
|
+
mode = mode.replace(/^[^:]*/, (m) => (m.includes("b") ? m : `${m}b`));
|
|
164
|
+
}
|
|
165
|
+
const colon = mode.indexOf(":");
|
|
166
|
+
const estr = colon === -1 ? null : mode.slice(colon + 1);
|
|
167
|
+
const vmode = colon === -1 ? mode : mode.slice(0, colon);
|
|
168
|
+
if (typeof fileName === "number")
|
|
169
|
+
super(fileName, null, mode);
|
|
170
|
+
else
|
|
171
|
+
super(getFs().openSync(fileName, vmode.replace(/b/g, ""), opt?.perm), fileName, mode);
|
|
172
|
+
if (vmode.includes("b"))
|
|
173
|
+
this.binmode();
|
|
174
|
+
if (estr !== null)
|
|
175
|
+
this.setEncoding(estr);
|
|
176
|
+
else if (opt?.externalEncoding != null)
|
|
177
|
+
this.setEncoding(opt.externalEncoding);
|
|
178
|
+
if (this.mode & FMODE_SETENC_BY_BOM)
|
|
179
|
+
this.ioSetEncodingByBom();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* `vendor/ruby/v3.3.11/file.c:7427` — `File::SEPARATOR`, `"/"` on every platform.
|
|
183
|
+
*
|
|
184
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::SEPARATOR`.
|
|
185
|
+
*/
|
|
186
|
+
static SEPARATOR = "/";
|
|
187
|
+
/**
|
|
188
|
+
* `vendor/ruby/v3.3.11/file.c:7433` — `File::ALT_SEPARATOR`, the `'\\'` of
|
|
189
|
+
* `FILE_ALT_SEPARATOR` (`file.c:3303`) where the build is DOSISH, and `nil`
|
|
190
|
+
* everywhere else (`file.c:7435`). The platform answer comes from the
|
|
191
|
+
* registered path backend's separator rather than from a runtime global.
|
|
192
|
+
*
|
|
193
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::ALT_SEPARATOR`.
|
|
194
|
+
*/
|
|
195
|
+
static get ALT_SEPARATOR() {
|
|
196
|
+
return getPath().sep === "\\" ? "\\" : null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* `vendor/ruby/v3.3.11/file.c:7440` — `File::PATH_SEPARATOR`, the `';'` of a DOSISH
|
|
200
|
+
* build and `':'` everywhere else. The platform answer comes from the
|
|
201
|
+
* registered path backend's separator, as `ALT_SEPARATOR` above does.
|
|
202
|
+
*
|
|
203
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::PATH_SEPARATOR`.
|
|
204
|
+
*/
|
|
205
|
+
static get PATH_SEPARATOR() {
|
|
206
|
+
return getPath().sep === "\\" ? ";" : ":";
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* `vendor/ruby/v3.3.11/file.c:7841` — `File::LOCK_EX`, the exclusive-lock operation
|
|
210
|
+
* `File#flock` takes (`file.c:5198`).
|
|
211
|
+
*
|
|
212
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::LOCK_EX`.
|
|
213
|
+
*/
|
|
214
|
+
static LOCK_EX = 2;
|
|
215
|
+
/**
|
|
216
|
+
* `vendor/ruby/v3.3.11/file.c:7843` — `File::LOCK_UN`, the release operation
|
|
217
|
+
* `File#flock` takes (`file.c:5204`).
|
|
218
|
+
*
|
|
219
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::LOCK_UN`.
|
|
220
|
+
*/
|
|
221
|
+
static LOCK_UN = 8;
|
|
222
|
+
/**
|
|
223
|
+
* `vendor/ruby/v3.3.11/file.c:7845` — `File::LOCK_NB`, which makes `File#flock`
|
|
224
|
+
* answer `false` rather than wait (`file.c:5201`).
|
|
225
|
+
*
|
|
226
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::LOCK_NB`.
|
|
227
|
+
*/
|
|
228
|
+
static LOCK_NB = 4;
|
|
229
|
+
/**
|
|
230
|
+
* `vendor/ruby/v3.3.11/dir.c:3678` — a backslash is an ordinary character, not an escape.
|
|
231
|
+
*
|
|
232
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::FNM_NOESCAPE`.
|
|
233
|
+
*/
|
|
234
|
+
static FNM_NOESCAPE = 0x01;
|
|
235
|
+
/**
|
|
236
|
+
* `vendor/ruby/v3.3.11/dir.c:3682` — `*`, `?` and a bracket stop at `/`, and `**` + `/` walks elements.
|
|
237
|
+
*
|
|
238
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::FNM_PATHNAME`.
|
|
239
|
+
*/
|
|
240
|
+
static FNM_PATHNAME = 0x02;
|
|
241
|
+
/**
|
|
242
|
+
* `vendor/ruby/v3.3.11/dir.c:3686` — a wildcard may match a leading period.
|
|
243
|
+
*
|
|
244
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::FNM_DOTMATCH`.
|
|
245
|
+
*/
|
|
246
|
+
static FNM_DOTMATCH = 0x04;
|
|
247
|
+
/**
|
|
248
|
+
* `vendor/ruby/v3.3.11/dir.c:3674` — case-insensitive matching.
|
|
249
|
+
*
|
|
250
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::FNM_CASEFOLD`.
|
|
251
|
+
*/
|
|
252
|
+
static FNM_CASEFOLD = 0x08;
|
|
253
|
+
/**
|
|
254
|
+
* `vendor/ruby/v3.3.11/dir.c:222-226` — `FNM_CASEFOLD` on a case-folding filesystem
|
|
255
|
+
* and `0` otherwise, which is the arm `Entry_#descendant_directory?` selects
|
|
256
|
+
* on (`vendor/ruby/v3.3.11/lib/fileutils.rb:2453`).
|
|
257
|
+
*
|
|
258
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::FNM_SYSCASE`.
|
|
259
|
+
*/
|
|
260
|
+
static FNM_SYSCASE = 0;
|
|
261
|
+
/**
|
|
262
|
+
* `vendor/ruby/v3.3.11/dir.c:3690` — `{a,b}` alternation, expanded by `ruby_brace_expand` (`dir.c:3471-3478`).
|
|
263
|
+
*
|
|
264
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File::FNM_EXTGLOB`.
|
|
265
|
+
*/
|
|
266
|
+
static FNM_EXTGLOB = 0x10;
|
|
267
|
+
/**
|
|
268
|
+
* `vendor/ruby/v3.3.11/file.c:1806` `rb_file_exist_p`, which is `rb_stat(fname)`
|
|
269
|
+
* against a FOLLOWED symlink — so a broken symlink is `false` even though
|
|
270
|
+
* `File.symlink?` is `true`.
|
|
271
|
+
*
|
|
272
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.exist?`
|
|
273
|
+
* (`vendor/ruby/v3.3.11/file.c:1806`).
|
|
274
|
+
*/
|
|
275
|
+
static isExist(fileName) {
|
|
276
|
+
return getFs().existsSync(rbGetPath(fileName));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* {@link File.isExist} over the backend's async `exists`.
|
|
280
|
+
*
|
|
281
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.exist?`
|
|
282
|
+
* (`vendor/ruby/v3.3.11/file.c:1806`).
|
|
283
|
+
*/
|
|
284
|
+
static async isExistAsync(fileName) {
|
|
285
|
+
return getFs().exists(fileName);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* `vendor/ruby/v3.3.11/file.c:2196` `rb_file_identical_p` — `false` unless both
|
|
289
|
+
* names stat successfully and report the same `st_dev` and `st_ino`
|
|
290
|
+
* (`file.c:2201-2205`). Either argument may be an open stream, which
|
|
291
|
+
* `rb_stat` (`file.c:1296`) `fstat`s instead. An adapter that reports no
|
|
292
|
+
* device identity cannot answer, so it answers `false`.
|
|
293
|
+
*
|
|
294
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.identical?`
|
|
295
|
+
* (`vendor/ruby/v3.3.11/file.c:2196`).
|
|
296
|
+
*/
|
|
297
|
+
static isIdentical(fileName1, fileName2) {
|
|
298
|
+
const st1 = rbStat(fileName1);
|
|
299
|
+
const st2 = rbStat(fileName2);
|
|
300
|
+
if (!st1 || !st2)
|
|
301
|
+
return false;
|
|
302
|
+
if (st1.dev == null || st1.ino == null)
|
|
303
|
+
return false;
|
|
304
|
+
if (st1.dev !== st2.dev)
|
|
305
|
+
return false;
|
|
306
|
+
if (st1.ino !== st2.ino)
|
|
307
|
+
return false;
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* {@link File.isDirectory} over the backend's async `stat`: any failed stat
|
|
312
|
+
* answers `false`, as `rb_file_directory_p` does (`file.c:1622`).
|
|
313
|
+
*
|
|
314
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.directory?`
|
|
315
|
+
* (`vendor/ruby/v3.3.11/file.c:1615`).
|
|
316
|
+
*/
|
|
317
|
+
static async isDirectoryAsync(fileName) {
|
|
318
|
+
try {
|
|
319
|
+
return (await getFs().stat(fileName)).isDirectory();
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* `vendor/ruby/v3.3.11/file.c:1615` `rb_file_directory_p`, which answers `false`
|
|
327
|
+
* rather than raising when the stat fails (`file.c:1622`).
|
|
328
|
+
*
|
|
329
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.directory?`
|
|
330
|
+
* (`vendor/ruby/v3.3.11/file.c:1615`).
|
|
331
|
+
*/
|
|
332
|
+
static isDirectory(fileName) {
|
|
333
|
+
try {
|
|
334
|
+
return getFs().statSync(fileName).isDirectory();
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* `vendor/ruby/v3.3.11/file.c:1966` `rb_file_executable_p`, which is
|
|
342
|
+
* `rb_eaccess(fname, X_OK) >= 0`: the backend's `File::Stat#executable?`
|
|
343
|
+
* (`file.c:2244`), and `false` where the stat fails.
|
|
344
|
+
*
|
|
345
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.executable?`
|
|
346
|
+
* (`vendor/ruby/v3.3.11/file.c:1966`).
|
|
347
|
+
*/
|
|
348
|
+
static isExecutable(fileName) {
|
|
349
|
+
try {
|
|
350
|
+
return getFs().statSync(fileName).isExecutable();
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* `vendor/ruby/v3.3.11/file.c:1723` `rb_file_symlink_p`, which `lstat`s the name and
|
|
358
|
+
* answers `false` rather than raising when the `lstat` fails
|
|
359
|
+
* (`file.c:1730`), the way its {@link File.isDirectory} neighbour does.
|
|
360
|
+
*
|
|
361
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.symlink?`
|
|
362
|
+
* (`vendor/ruby/v3.3.11/file.c:1723`).
|
|
363
|
+
*/
|
|
364
|
+
static isSymlink(fileName) {
|
|
365
|
+
try {
|
|
366
|
+
return getFs().lstatSync(fileName).isSymbolicLink?.() === true;
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.file?`
|
|
374
|
+
* (`vendor/ruby/v3.3.11/file.c:2009`), over the backend's async `stat`.
|
|
375
|
+
*/
|
|
376
|
+
static async isFileAsync(fileName) {
|
|
377
|
+
const fs = getFs();
|
|
378
|
+
try {
|
|
379
|
+
return (await fs.stat(fileName)).isFile();
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* {@link File.isIdentical} over the backend's async `stat`, which is the
|
|
387
|
+
* form a caller on the async fs path awaits; a backend with no async `stat`
|
|
388
|
+
* is read through its sync one. A stream argument is still `fstat`ed, as
|
|
389
|
+
* `rb_stat` (`vendor/ruby/v3.3.11/file.c:1296`) does.
|
|
390
|
+
*
|
|
391
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.identical?`
|
|
392
|
+
* (`vendor/ruby/v3.3.11/file.c:2196`).
|
|
393
|
+
*/
|
|
394
|
+
static async isIdenticalAsync(fileName1, fileName2) {
|
|
395
|
+
const st1 = await rbStatAsync(fileName1);
|
|
396
|
+
const st2 = await rbStatAsync(fileName2);
|
|
397
|
+
if (!st1 || !st2)
|
|
398
|
+
return false;
|
|
399
|
+
if (st1.dev == null || st1.ino == null)
|
|
400
|
+
return false;
|
|
401
|
+
if (st1.dev !== st2.dev)
|
|
402
|
+
return false;
|
|
403
|
+
if (st1.ino !== st2.ino)
|
|
404
|
+
return false;
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* {@link File.isSymlink} over the backend's async `lstat`, `false` on a
|
|
409
|
+
* failed `lstat`; a backend with no async `lstat` is read through its sync
|
|
410
|
+
* one.
|
|
411
|
+
*
|
|
412
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.symlink?`
|
|
413
|
+
* (`vendor/ruby/v3.3.11/file.c:1670`).
|
|
414
|
+
*/
|
|
415
|
+
static async isSymlinkAsync(fileName) {
|
|
416
|
+
try {
|
|
417
|
+
const fs = getFs();
|
|
418
|
+
const st = fs.lstat ? await fs.lstat(fileName) : fs.lstatSync(fileName);
|
|
419
|
+
return st.isSymbolicLink?.() === true;
|
|
420
|
+
}
|
|
421
|
+
catch {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* `vendor/ruby/v3.3.11/file.c:2009` `rb_file_file_p`, `false` on a failed stat.
|
|
427
|
+
*
|
|
428
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.file?`
|
|
429
|
+
* (`vendor/ruby/v3.3.11/file.c:2009`).
|
|
430
|
+
*/
|
|
431
|
+
static isFile(fileName) {
|
|
432
|
+
try {
|
|
433
|
+
return getFs().statSync(fileName).isFile();
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* {@link File.isReadable} over the backend's async `access`, `rb_eaccess(fname, R_OK)`.
|
|
441
|
+
*
|
|
442
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.readable?`
|
|
443
|
+
* (`vendor/ruby/v3.3.11/file.c:1826`).
|
|
444
|
+
*/
|
|
445
|
+
static async isReadableAsync(fileName) {
|
|
446
|
+
try {
|
|
447
|
+
await getFs().accessAsync(fileName, 4);
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* {@link File.isExecutable} over the backend's async `access`, `rb_eaccess(fname, X_OK)`.
|
|
456
|
+
*
|
|
457
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.executable?`
|
|
458
|
+
* (`vendor/ruby/v3.3.11/file.c:1966`).
|
|
459
|
+
*/
|
|
460
|
+
static async isExecutableAsync(fileName) {
|
|
461
|
+
try {
|
|
462
|
+
await getFs().accessAsync(fileName, 1);
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* `vendor/ruby/v3.3.11/file.c:1826` `rb_file_readable_p`, which is
|
|
471
|
+
* `rb_eaccess(fname, R_OK) >= 0` and so is `false` both for a file that is
|
|
472
|
+
* not there and for one the effective user cannot read. `R_OK` is POSIX's
|
|
473
|
+
* `4` rather than a Ruby constant. A backend with no access check has no
|
|
474
|
+
* `accessSync`, and there existence is all that can be answered.
|
|
475
|
+
*
|
|
476
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.readable?`
|
|
477
|
+
* (`vendor/ruby/v3.3.11/file.c:1826`).
|
|
478
|
+
*/
|
|
479
|
+
static isReadable(fileName) {
|
|
480
|
+
const fs = getFs();
|
|
481
|
+
if (!fs.accessSync)
|
|
482
|
+
return fs.existsSync(fileName);
|
|
483
|
+
try {
|
|
484
|
+
fs.accessSync(fileName, 4);
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
catch {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* `vendor/ruby/v3.3.11/file.c:1329` `rb_file_s_stat`, which RAISES `Errno::ENOENT`
|
|
493
|
+
* rather than answering `nil` when the path is not there — the predicates
|
|
494
|
+
* above are the arms that swallow it.
|
|
495
|
+
*
|
|
496
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.stat`
|
|
497
|
+
* (`vendor/ruby/v3.3.11/file.c:1329`).
|
|
498
|
+
*/
|
|
499
|
+
static stat(fileName) {
|
|
500
|
+
return getFs().statSync(fileName);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* `vendor/ruby/v3.3.11/file.c:1305` `rb_file_s_size` — the byte size of the named
|
|
504
|
+
* file, which is `File.stat(file_name).size`.
|
|
505
|
+
*
|
|
506
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.size`
|
|
507
|
+
* (`vendor/ruby/v3.3.11/file.c:1305`).
|
|
508
|
+
*/
|
|
509
|
+
static size(fileName) {
|
|
510
|
+
return File.stat(fileName).size;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* `vendor/ruby/v3.3.11/file.c:2047` `rb_file_size_p` — `File.size?`, `nil` both when
|
|
514
|
+
* the file is missing AND when it is empty, which is what makes it a
|
|
515
|
+
* three-state answer rather than a size.
|
|
516
|
+
*
|
|
517
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.size?`
|
|
518
|
+
* (`vendor/ruby/v3.3.11/file.c:2047`).
|
|
519
|
+
*/
|
|
520
|
+
static isSize(fileName) {
|
|
521
|
+
let size;
|
|
522
|
+
try {
|
|
523
|
+
size = File.stat(fileName).size;
|
|
524
|
+
}
|
|
525
|
+
catch {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
return size === 0 ? null : size;
|
|
529
|
+
}
|
|
530
|
+
static open(fileName, mode = "r", blockOrOpt, optBlock) {
|
|
531
|
+
const block = typeof blockOrOpt === "function" ? blockOrOpt : optBlock;
|
|
532
|
+
const opt = typeof blockOrOpt === "function" ? undefined : blockOrOpt;
|
|
533
|
+
const file = new File(fileName, mode, opt);
|
|
534
|
+
if (!block)
|
|
535
|
+
return file;
|
|
536
|
+
let result;
|
|
537
|
+
try {
|
|
538
|
+
result = block(file);
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
file.close();
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
if (result instanceof Promise) {
|
|
545
|
+
return result.finally(() => file.close());
|
|
546
|
+
}
|
|
547
|
+
file.close();
|
|
548
|
+
return result;
|
|
549
|
+
}
|
|
550
|
+
static async openAsync(fileName, mode = "r", blockOrOpt, optBlock) {
|
|
551
|
+
const block = typeof blockOrOpt === "function" ? blockOrOpt : optBlock;
|
|
552
|
+
const opt = typeof blockOrOpt === "function" ? undefined : blockOrOpt;
|
|
553
|
+
const perm = typeof mode === "object" ? mode.perm : opt?.perm;
|
|
554
|
+
const vmode = (typeof mode === "object" ? (mode.mode ?? "r") : mode).split(":")[0];
|
|
555
|
+
const fd = await getFs().openAsync(fileName, vmode.replace(/b/g, ""), perm);
|
|
556
|
+
let file;
|
|
557
|
+
try {
|
|
558
|
+
file = new this(fd, mode, opt);
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
getFs().closeSync(fd);
|
|
562
|
+
throw error;
|
|
563
|
+
}
|
|
564
|
+
file.pathv = fileName;
|
|
565
|
+
if (!block)
|
|
566
|
+
return file;
|
|
567
|
+
try {
|
|
568
|
+
return await block(file);
|
|
569
|
+
}
|
|
570
|
+
finally {
|
|
571
|
+
file.close();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
/** @noRailsEquivalent PERMANENT — Ruby core `File.read` (`vendor/ruby/v3.3.11/io.c:12200`). */
|
|
575
|
+
static read(name, opt) {
|
|
576
|
+
const file = File.open(name, "r", { externalEncoding: opt?.encoding });
|
|
577
|
+
try {
|
|
578
|
+
return file.read();
|
|
579
|
+
}
|
|
580
|
+
finally {
|
|
581
|
+
file.close();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* {@link File.read} over the backend's async `readFile`, as UTF-8 text.
|
|
586
|
+
*
|
|
587
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.read` (`IO.read`,
|
|
588
|
+
* `vendor/ruby/v3.3.11/io.c:12200`).
|
|
589
|
+
*/
|
|
590
|
+
static async readAsync(name) {
|
|
591
|
+
return await getFs().readFile(name, "utf8");
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* `vendor/ruby/v3.3.11/io.c:12063` `rb_io_s_foreach` in its block form: the stream
|
|
595
|
+
* opens through `open_key_args` (`io.c:12163`), `rb_io_each_line`
|
|
596
|
+
* (`io.c:4159`) yields each line with its separator retained, and
|
|
597
|
+
* `rb_ensure` (`io.c:12180`) closes it. The file is read in chunks, never
|
|
598
|
+
* whole; the decoder streams so a character straddling two chunks survives.
|
|
599
|
+
*
|
|
600
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.foreach` (`IO.foreach`,
|
|
601
|
+
* `vendor/ruby/v3.3.11/io.c:12063`).
|
|
602
|
+
*/
|
|
603
|
+
static foreach(name, block) {
|
|
604
|
+
const fs = getFs();
|
|
605
|
+
const fd = fs.openSync(name, "r");
|
|
606
|
+
try {
|
|
607
|
+
const decoder = new TextDecoder();
|
|
608
|
+
const buffer = new Uint8Array(8192);
|
|
609
|
+
let pos = 0;
|
|
610
|
+
let rest = "";
|
|
611
|
+
for (;;) {
|
|
612
|
+
const read = fs.readSync(fd, buffer, 0, buffer.length, pos);
|
|
613
|
+
rest +=
|
|
614
|
+
read === 0
|
|
615
|
+
? decoder.decode()
|
|
616
|
+
: decoder.decode(buffer.subarray(0, read), { stream: true });
|
|
617
|
+
let at;
|
|
618
|
+
while ((at = rest.indexOf("\n")) !== -1) {
|
|
619
|
+
block(rest.slice(0, at + 1));
|
|
620
|
+
rest = rest.slice(at + 1);
|
|
621
|
+
}
|
|
622
|
+
if (read === 0)
|
|
623
|
+
break;
|
|
624
|
+
pos += read;
|
|
625
|
+
}
|
|
626
|
+
if (rest !== "")
|
|
627
|
+
block(rest);
|
|
628
|
+
}
|
|
629
|
+
finally {
|
|
630
|
+
fs.closeSync(fd);
|
|
631
|
+
}
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* `vendor/ruby/v3.3.11/io.c:12377` `rb_io_s_write`, which answers the number of
|
|
636
|
+
* BYTES written rather than the string itself.
|
|
637
|
+
*
|
|
638
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.write` (`IO.write`,
|
|
639
|
+
* `vendor/ruby/v3.3.11/io.c:12377`).
|
|
640
|
+
*/
|
|
641
|
+
static write(name, string) {
|
|
642
|
+
getFs().writeFileSync(name, string);
|
|
643
|
+
return new TextEncoder().encode(string).length;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* `vendor/ruby/v3.3.11/file.c:3202` `rb_file_s_unlink`, which answers the number of
|
|
647
|
+
* files deleted and raises on the first failure.
|
|
648
|
+
*
|
|
649
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.delete`
|
|
650
|
+
* (`vendor/ruby/v3.3.11/file.c:3202`).
|
|
651
|
+
*/
|
|
652
|
+
static delete(...files) {
|
|
653
|
+
for (const file of files)
|
|
654
|
+
getFs().unlinkSync(file);
|
|
655
|
+
return files.length;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* {@link File.write} over the backend's async `writeFile`, falling back to its
|
|
659
|
+
* `writeFileSync`. `perm` is `IO.write`'s `perm:` option
|
|
660
|
+
* (`vendor/ruby/v3.3.11/io.c:6953`), the mode a created file is opened with,
|
|
661
|
+
* and `mode` its `mode:` open-mode string (`"wx"` is
|
|
662
|
+
* `CREAT | EXCL | WRONLY`, raising `Errno::EEXIST` on an existing file).
|
|
663
|
+
*
|
|
664
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.write` (`IO.write`,
|
|
665
|
+
* `vendor/ruby/v3.3.11/io.c:12377`).
|
|
666
|
+
*/
|
|
667
|
+
static async writeAsync(name, string, { perm, mode } = {}) {
|
|
668
|
+
const fs = getFs();
|
|
669
|
+
if (fs.writeFile)
|
|
670
|
+
await fs.writeFile(name, string, { mode: perm, flag: mode });
|
|
671
|
+
else
|
|
672
|
+
fs.writeFileSync(name, string, { mode: perm, flag: mode });
|
|
673
|
+
return typeof string === "string" ? new TextEncoder().encode(string).length : string.length;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* {@link File.delete} over the backend's async `unlink`, falling back to its
|
|
677
|
+
* `unlinkSync`.
|
|
678
|
+
*
|
|
679
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.delete`
|
|
680
|
+
* (`vendor/ruby/v3.3.11/file.c:3202`).
|
|
681
|
+
*/
|
|
682
|
+
static async deleteAsync(...files) {
|
|
683
|
+
const fs = getFs();
|
|
684
|
+
for (const file of files) {
|
|
685
|
+
if (fs.unlink)
|
|
686
|
+
await fs.unlink(file);
|
|
687
|
+
else
|
|
688
|
+
fs.unlinkSync(file);
|
|
689
|
+
}
|
|
690
|
+
return files.length;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* `vendor/ruby/v3.3.11/file.c:3279` `rb_file_s_umask`, reading only. A backend
|
|
694
|
+
* with no permission bits answers 0, as `chmod` below is a no-op there.
|
|
695
|
+
*
|
|
696
|
+
* @noRailsEquivalent PERMANENT
|
|
697
|
+
*/
|
|
698
|
+
static umask() {
|
|
699
|
+
return getProcessAdapter().umask?.() ?? 0;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* `vendor/ruby/v3.3.11/file.c:2575` `rb_file_s_chmod`, which answers the number of
|
|
703
|
+
* files whose mode was set. A backend with no permission bits has no
|
|
704
|
+
* `chmodSync`, and there the call is a no-op.
|
|
705
|
+
*
|
|
706
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.chmod`
|
|
707
|
+
* (`vendor/ruby/v3.3.11/file.c:2575`).
|
|
708
|
+
*/
|
|
709
|
+
static chmod(mode, ...files) {
|
|
710
|
+
for (const file of files)
|
|
711
|
+
getFs().chmodSync?.(file, mode);
|
|
712
|
+
return files.length;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* {@link File.chmod} over the backend's async `chmod`, falling back to its
|
|
716
|
+
* `chmodSync`; a backend with no permission bits has neither, and there the
|
|
717
|
+
* call is a no-op too.
|
|
718
|
+
*
|
|
719
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.chmod`
|
|
720
|
+
* (`vendor/ruby/v3.3.11/file.c:2575`).
|
|
721
|
+
*/
|
|
722
|
+
static async chmodAsync(mode, ...files) {
|
|
723
|
+
const fs = getFs();
|
|
724
|
+
for (const file of files) {
|
|
725
|
+
if (fs.chmod)
|
|
726
|
+
await fs.chmod(file, mode);
|
|
727
|
+
else
|
|
728
|
+
fs.chmodSync?.(file, mode);
|
|
729
|
+
}
|
|
730
|
+
return files.length;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* `vendor/ruby/v3.3.11/file.c:3056` `rb_file_s_link`, which answers `0`
|
|
734
|
+
* (`file.c:3066`) and raises `NotImplementedError` on a platform with no
|
|
735
|
+
* `link(2)` — spelled here as a backend with no `link`.
|
|
736
|
+
*
|
|
737
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.link`
|
|
738
|
+
* (`vendor/ruby/v3.3.11/file.c:3056`).
|
|
739
|
+
*/
|
|
740
|
+
static async linkAsync(oldName, newName) {
|
|
741
|
+
const fs = getFs();
|
|
742
|
+
if (!fs.link)
|
|
743
|
+
throw new NotImplementedError("link() function is unimplemented on this machine");
|
|
744
|
+
await fs.link(oldName, newName);
|
|
745
|
+
return 0;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* `vendor/ruby/v3.3.11/file.c:3086` `rb_file_s_symlink`, which answers `0`
|
|
749
|
+
* (`file.c:3096`) and raises `NotImplementedError` on a platform with no
|
|
750
|
+
* `symlink(2)` — spelled here as a backend with no `symlink`.
|
|
751
|
+
*
|
|
752
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.symlink`
|
|
753
|
+
* (`vendor/ruby/v3.3.11/file.c:3086`).
|
|
754
|
+
*/
|
|
755
|
+
static async symlinkAsync(oldName, newName) {
|
|
756
|
+
const fs = getFs();
|
|
757
|
+
if (!fs.symlink)
|
|
758
|
+
throw new NotImplementedError("symlink() function is unimplemented on this machine");
|
|
759
|
+
await fs.symlink(oldName, newName);
|
|
760
|
+
return 0;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* `vendor/ruby/v3.3.11/file.c:3115` `rb_file_s_readlink`: the name of the file
|
|
764
|
+
* the link `path` refers to. `rb_f_notimplement` stands in on a platform with
|
|
765
|
+
* no `readlink(2)` (`file.c:3197`), spelled here as a backend with no
|
|
766
|
+
* `readlinkSync`.
|
|
767
|
+
*
|
|
768
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.readlink`
|
|
769
|
+
* (`vendor/ruby/v3.3.11/file.c:3115`).
|
|
770
|
+
*/
|
|
771
|
+
static readlink(path) {
|
|
772
|
+
const fs = getFs();
|
|
773
|
+
if (!fs.readlinkSync)
|
|
774
|
+
throw new NotImplementedError("readlink() function is unimplemented on this machine");
|
|
775
|
+
return fs.readlinkSync(path);
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.chown`
|
|
779
|
+
* (`vendor/ruby/v3.3.11/file.c:2706`), over the backend's async `chown`.
|
|
780
|
+
*/
|
|
781
|
+
static async chownAsync(owner, group, path) {
|
|
782
|
+
const fs = getFs();
|
|
783
|
+
if (fs.chown)
|
|
784
|
+
await fs.chown(path, toUid(owner), toGid(group));
|
|
785
|
+
else
|
|
786
|
+
fs.chownSync?.(path, toUid(owner), toGid(group));
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.utime`
|
|
790
|
+
* (`vendor/ruby/v3.3.11/file.c:2983`), over the backend's async `utimes`.
|
|
791
|
+
*/
|
|
792
|
+
static async utimeAsync(atime, mtime, path) {
|
|
793
|
+
const fs = getFs();
|
|
794
|
+
if (fs.utimes)
|
|
795
|
+
await fs.utimes(path, atime, mtime);
|
|
796
|
+
else if (fs.utimesSync)
|
|
797
|
+
fs.utimesSync(path, atime, mtime);
|
|
798
|
+
else
|
|
799
|
+
throw new NotImplementedError("utime() function is unimplemented on this machine");
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* `vendor/ruby/v3.3.11/file.c:2706` `rb_file_s_chown`, which answers the number of
|
|
803
|
+
* files whose owner was set. A `nil` owner or group is ignored
|
|
804
|
+
* (`file.c:2698`) — `File.chown(nil, 100, "testfile")` — which `to_uid` /
|
|
805
|
+
* `to_gid` (`file.c:2661,2670`) carry through as `-1`. A backend with no
|
|
806
|
+
* ownership has no `chownSync`, and there the call is a no-op.
|
|
807
|
+
*
|
|
808
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.chown`
|
|
809
|
+
* (`vendor/ruby/v3.3.11/file.c:2706`).
|
|
810
|
+
*/
|
|
811
|
+
static chown(owner, group, ...files) {
|
|
812
|
+
const uid = toUid(owner);
|
|
813
|
+
const gid = toGid(group);
|
|
814
|
+
for (const file of files)
|
|
815
|
+
getFs().chownSync?.(file, uid, gid);
|
|
816
|
+
return files.length;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* `vendor/ruby/v3.3.11/file.c:3231` `rb_file_s_rename`, which answers `0` and
|
|
820
|
+
* replaces `to` when it already exists.
|
|
821
|
+
*
|
|
822
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.rename`
|
|
823
|
+
* (`vendor/ruby/v3.3.11/file.c:3231`).
|
|
824
|
+
*/
|
|
825
|
+
static rename(from, to) {
|
|
826
|
+
getFs().renameSync(from, to);
|
|
827
|
+
return 0;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* `vendor/ruby/v3.3.11/file.c:2427` `rb_file_s_mtime`, the modification Time of a
|
|
831
|
+
* FOLLOWED symlink — it raises `ENOENT` rather than answering `nil` when the
|
|
832
|
+
* path does not exist.
|
|
833
|
+
*
|
|
834
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.mtime`
|
|
835
|
+
* (`vendor/ruby/v3.3.11/file.c:2427`).
|
|
836
|
+
*/
|
|
837
|
+
static mtime(fileName) {
|
|
838
|
+
return getFs().statSync(fileName).mtime;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* {@link File.mtime} over the backend's async `stat`.
|
|
842
|
+
*
|
|
843
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.mtime`
|
|
844
|
+
* (`vendor/ruby/v3.3.11/file.c:2427`).
|
|
845
|
+
*/
|
|
846
|
+
static async mtimeAsync(fileName) {
|
|
847
|
+
const fs = getFs();
|
|
848
|
+
return (fs.stat ? await fs.stat(fileName) : fs.statSync(fileName)).mtime;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* `vendor/ruby/v3.3.11/file.c:4559` `rb_file_s_realpath`, which resolves every
|
|
852
|
+
* symlink and raises `ENOENT` when the path does not exist. A backend with
|
|
853
|
+
* no symlink support has no `realpathSync`, and there the path resolves
|
|
854
|
+
* lexically.
|
|
855
|
+
*
|
|
856
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.realpath`
|
|
857
|
+
* (`vendor/ruby/v3.3.11/file.c:4559`).
|
|
858
|
+
*/
|
|
859
|
+
static realpath(pathname) {
|
|
860
|
+
const fs = getFs();
|
|
861
|
+
if (fs.realpathSync)
|
|
862
|
+
return fs.realpathSync(pathname);
|
|
863
|
+
return File.expandPath(pathname);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* {@link File.realpath} over the backend's async `realpath`, resolving
|
|
867
|
+
* lexically where the backend has none.
|
|
868
|
+
*
|
|
869
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.realpath`
|
|
870
|
+
* (`vendor/ruby/v3.3.11/file.c:4559`).
|
|
871
|
+
*/
|
|
872
|
+
static async realpathAsync(pathname) {
|
|
873
|
+
const fs = getFs();
|
|
874
|
+
if (fs.realpath)
|
|
875
|
+
return await fs.realpath(pathname);
|
|
876
|
+
return File.expandPath(pathname);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* `vendor/ruby/v3.3.11/file.c:4580` `rb_file_s_realdirpath`, {@link File.realpath}
|
|
880
|
+
* with the last component allowed to be missing, following a broken symlink
|
|
881
|
+
* to its target.
|
|
882
|
+
*
|
|
883
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.realdirpath`
|
|
884
|
+
* (`vendor/ruby/v3.3.11/file.c:4580`).
|
|
885
|
+
*/
|
|
886
|
+
static async realdirpathAsync(pathname) {
|
|
887
|
+
const fs = getFs();
|
|
888
|
+
try {
|
|
889
|
+
return await fs.realpath(pathname);
|
|
890
|
+
}
|
|
891
|
+
catch (error) {
|
|
892
|
+
if (error.code !== "ENOENT")
|
|
893
|
+
throw error;
|
|
894
|
+
}
|
|
895
|
+
const [dir, base] = File.split(File.expandPath(pathname));
|
|
896
|
+
const link = await fs.readlink(pathname).catch(() => null);
|
|
897
|
+
if (link != null)
|
|
898
|
+
return File.realdirpathAsync(File.expandPath(link, dir));
|
|
899
|
+
return File.join(await fs.realpath(dir), base);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* `vendor/ruby/v3.3.11/file.c:5013` `rb_file_join`, which is a STRING join and not
|
|
903
|
+
* a path normalization: `File.join("a", "..", "b")` is `"a/../b"`, where
|
|
904
|
+
* node's `path.join` answers `"b"`. A separator at the boundary is squeezed
|
|
905
|
+
* to one (`file.c:5061-5067`) — `File.join("a//", "/b")` is `"a/b"` — and an
|
|
906
|
+
* empty component keeps its separator, so `File.join("a", "")` is `"a/"`.
|
|
907
|
+
* Both boundary arms test with `isdirsep`, so a `File::ALT_SEPARATOR` at the
|
|
908
|
+
* boundary is a separator too: `File.join("a\\", "b")` is `"a\\b"` on
|
|
909
|
+
* Windows and `"a\\/b"` on POSIX. An Array component is joined first and
|
|
910
|
+
* spliced in (`file.c:5048-5054`), so an empty one contributes `""`:
|
|
911
|
+
* `File.join("a", [], "b")` is `"a/b"`.
|
|
912
|
+
*
|
|
913
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.join`
|
|
914
|
+
* (`vendor/ruby/v3.3.11/file.c:5013`).
|
|
915
|
+
*/
|
|
916
|
+
static join(...args) {
|
|
917
|
+
return rbFileJoin(args);
|
|
918
|
+
}
|
|
919
|
+
/** @noRailsEquivalent PERMANENT — Ruby core `File.split` (`rb_file_s_split`, `vendor/ruby/v3.3.11/file.c:4999-5004`). */
|
|
920
|
+
static split(path) {
|
|
921
|
+
return [File.dirname(path), File.basename(path)];
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* `vendor/ruby/v3.3.11/file.c:4770` `rb_file_s_dirname`.
|
|
925
|
+
*
|
|
926
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.dirname`
|
|
927
|
+
* (`vendor/ruby/v3.3.11/file.c:4770`).
|
|
928
|
+
*/
|
|
929
|
+
static dirname(fileName) {
|
|
930
|
+
return getPath().dirname(fileName);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* `vendor/ruby/v3.3.11/file.c:4705` `rb_file_s_basename`. The optional `suffix` is
|
|
934
|
+
* stripped, and the literal `".*"` strips whatever extension is there
|
|
935
|
+
* (`file.c:4664-4680`). A path of separators only answers `"/"`
|
|
936
|
+
* (`vendor/ruby/v3.3.11/file.c:4625` `ruby_enc_find_basename`).
|
|
937
|
+
*
|
|
938
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.basename`
|
|
939
|
+
* (`vendor/ruby/v3.3.11/file.c:4705`).
|
|
940
|
+
*/
|
|
941
|
+
static basename(fileName, suffix) {
|
|
942
|
+
const name = rbGetPath(fileName);
|
|
943
|
+
const base = /^\/+$/.test(name) ? "/" : getPath().basename(name);
|
|
944
|
+
if (suffix === undefined)
|
|
945
|
+
return base;
|
|
946
|
+
if (suffix === ".*") {
|
|
947
|
+
const extname = File.extname(base);
|
|
948
|
+
return extname === "" ? base : base.slice(0, base.length - extname.length);
|
|
949
|
+
}
|
|
950
|
+
return base.endsWith(suffix) && base !== suffix
|
|
951
|
+
? base.slice(0, base.length - suffix.length)
|
|
952
|
+
: base;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* `vendor/ruby/v3.3.11/file.c:4954` `rb_file_s_extname`: a leading dot is not an
|
|
956
|
+
* extension (`".bashrc"` is `""`) and a trailing dot is (`"b."` is `"."`).
|
|
957
|
+
*
|
|
958
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.extname`
|
|
959
|
+
* (`vendor/ruby/v3.3.11/file.c:4954`).
|
|
960
|
+
*/
|
|
961
|
+
static extname(fileName) {
|
|
962
|
+
return getPath().extname(fileName);
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* `vendor/ruby/v3.3.11/dir.c:3457` `file_s_fnmatch` — `true` when `path` matches the
|
|
966
|
+
* glob `pattern`. Under `FNM_EXTGLOB` the pattern is brace-expanded first and
|
|
967
|
+
* the first alternative that matches wins (`dir.c:3471-3478`).
|
|
968
|
+
*
|
|
969
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.fnmatch`
|
|
970
|
+
* (`vendor/ruby/v3.3.11/dir.c:3457`).
|
|
971
|
+
*/
|
|
972
|
+
static fnmatch(pattern, path, flags = 0) {
|
|
973
|
+
if (flags & File.FNM_EXTGLOB) {
|
|
974
|
+
return rubyBraceExpand(pattern, flags, (expanded) => fnmatch(expanded, path, flags));
|
|
975
|
+
}
|
|
976
|
+
return fnmatch(pattern, path, flags);
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* `vendor/ruby/v3.3.11/file.c:4126` `rb_file_s_expand_path`, which resolves
|
|
980
|
+
* `fileName` against `dirString` — the working directory when it is omitted.
|
|
981
|
+
*
|
|
982
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.expand_path`
|
|
983
|
+
* (`vendor/ruby/v3.3.11/file.c:4126`).
|
|
984
|
+
*/
|
|
985
|
+
static expandPath(fileName, dirString) {
|
|
986
|
+
return getPath().resolve(dirString == null ? getFs().cwd() : rbGetPath(dirString), rbGetPath(fileName));
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* `vendor/ruby/v3.3.11/file.c:4210` `rb_file_s_absolute_path_p`.
|
|
990
|
+
*
|
|
991
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File.absolute_path?`
|
|
992
|
+
* (`vendor/ruby/v3.3.11/file.c:4210`).
|
|
993
|
+
*/
|
|
994
|
+
static isAbsolutePath(fileName) {
|
|
995
|
+
const path = rbGetPath(fileName);
|
|
996
|
+
return getPath().isAbsolute?.(path) ?? path.startsWith(File.SEPARATOR);
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* `vendor/ruby/v3.3.11/file.c:5301` `rb_file_flock`, which answers `0` once the lock
|
|
1000
|
+
* is held. A backend with no advisory locking — node's `fs` exposes no
|
|
1001
|
+
* `flock(2)` — has no `flockSync`, and there the stream is left unlocked,
|
|
1002
|
+
* which is what an unlockable file already behaves like.
|
|
1003
|
+
*
|
|
1004
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File#flock`
|
|
1005
|
+
* (`vendor/ruby/v3.3.11/file.c:5301`).
|
|
1006
|
+
*/
|
|
1007
|
+
flock(operation) {
|
|
1008
|
+
const locked = getFs().flockSync?.(this.fd, operation === File.LOCK_UN ? "un" : operation & File.LOCK_NB ? "exnb" : "ex");
|
|
1009
|
+
if (locked === false)
|
|
1010
|
+
return false;
|
|
1011
|
+
return 0;
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* `vendor/ruby/v3.3.11/file.c:1330` `rb_file_size` — `fstat(2)` of the open
|
|
1015
|
+
* descriptor, which is why it answers the bytes already written rather than
|
|
1016
|
+
* what a stale `File.stat` of the path would say.
|
|
1017
|
+
*
|
|
1018
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File#size`
|
|
1019
|
+
* (`vendor/ruby/v3.3.11/file.c:1330`).
|
|
1020
|
+
*/
|
|
1021
|
+
size() {
|
|
1022
|
+
return this.stat().size;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* `vendor/ruby/v3.3.11/file.c:2599` `rb_file_chmod`, which answers `0`. MRI
|
|
1026
|
+
* calls `fchmod(2)` on the descriptor; the `FsAdapter` contract has no
|
|
1027
|
+
* `fchmodSync`, so the open file's path takes the mode instead.
|
|
1028
|
+
*
|
|
1029
|
+
* @noRailsEquivalent PERMANENT — Ruby core `File#chmod`
|
|
1030
|
+
* (`vendor/ruby/v3.3.11/file.c:2599`).
|
|
1031
|
+
*/
|
|
1032
|
+
chmod(mode) {
|
|
1033
|
+
getFs().chmodSync?.(this.path(), mode);
|
|
1034
|
+
return 0;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
constSet(TopLevel, "File", File);
|
|
1038
|
+
/**
|
|
1039
|
+
* `Inc(p, e, enc)` (`vendor/ruby/v3.3.11/dir.c:237`) — the cursor advance MRI spells
|
|
1040
|
+
* through `rb_enc_mbclen`, one whole character. A JS string is UTF-16, so an
|
|
1041
|
+
* astral character is the two code units of a surrogate pair.
|
|
1042
|
+
*/
|
|
1043
|
+
function inc(str, i) {
|
|
1044
|
+
const cp = str.codePointAt(i);
|
|
1045
|
+
return i + (cp !== undefined && cp > 0xffff ? 2 : 1);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* The one whole character at `i` — what MRI's `memcmp(t1, s, r)`
|
|
1049
|
+
* (`vendor/ruby/v3.3.11/dir.c:277`) and `rb_enc_codepoint` (`dir.c:281`) read, where a
|
|
1050
|
+
* JS index reads one code unit.
|
|
1051
|
+
*/
|
|
1052
|
+
function charAt(str, i) {
|
|
1053
|
+
const cp = str.codePointAt(i);
|
|
1054
|
+
return cp === undefined ? "" : String.fromCodePoint(cp);
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* `bracket` (`vendor/ruby/v3.3.11/dir.c:240`), which answers the pattern index just
|
|
1058
|
+
* past the closing `]` when `s` is in the class, and `null` when it is not or
|
|
1059
|
+
* the class never closes. Its `FNM_CASEFOLD` arm casefolds against `p`, the
|
|
1060
|
+
* character AFTER `t1` (`dir.c:296`) — mirrored, not corrected.
|
|
1061
|
+
*/
|
|
1062
|
+
function bracket(p, pattern, s, string, flags) {
|
|
1063
|
+
const nocase = flags & File.FNM_CASEFOLD;
|
|
1064
|
+
const escape = !(flags & File.FNM_NOESCAPE);
|
|
1065
|
+
let ok = false;
|
|
1066
|
+
let not = false;
|
|
1067
|
+
if (p >= pattern.length)
|
|
1068
|
+
return null;
|
|
1069
|
+
if (pattern[p] === "!" || pattern[p] === "^") {
|
|
1070
|
+
not = true;
|
|
1071
|
+
p++;
|
|
1072
|
+
}
|
|
1073
|
+
while (pattern[p] !== "]") {
|
|
1074
|
+
let t1 = p;
|
|
1075
|
+
if (escape && pattern[t1] === "\\")
|
|
1076
|
+
t1++;
|
|
1077
|
+
if (t1 >= pattern.length)
|
|
1078
|
+
return null;
|
|
1079
|
+
p = inc(pattern, t1);
|
|
1080
|
+
if (p >= pattern.length)
|
|
1081
|
+
return null;
|
|
1082
|
+
if (pattern[p] === "-" && pattern[p + 1] !== "]") {
|
|
1083
|
+
let t2 = p + 1;
|
|
1084
|
+
if (escape && pattern[t2] === "\\")
|
|
1085
|
+
t2++;
|
|
1086
|
+
if (t2 >= pattern.length)
|
|
1087
|
+
return null;
|
|
1088
|
+
p = inc(pattern, t2);
|
|
1089
|
+
if (ok)
|
|
1090
|
+
continue;
|
|
1091
|
+
if (charAt(pattern, t1) === charAt(string, s) || charAt(pattern, t2) === charAt(string, s)) {
|
|
1092
|
+
ok = true;
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
if (compareChar(charAt(string, s), charAt(pattern, t1), nocase) < 0)
|
|
1096
|
+
continue;
|
|
1097
|
+
if (compareChar(charAt(string, s), charAt(pattern, t2), nocase) > 0)
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
if (ok)
|
|
1102
|
+
continue;
|
|
1103
|
+
if (charAt(pattern, t1) === charAt(string, s)) {
|
|
1104
|
+
ok = true;
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
if (!nocase)
|
|
1108
|
+
continue;
|
|
1109
|
+
if (compareChar(charAt(string, s), charAt(pattern, p), nocase) !== 0)
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1112
|
+
ok = true;
|
|
1113
|
+
}
|
|
1114
|
+
return ok === not ? null : p + 1;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* The `rb_enc_toupper` comparison `bracket` and `fnmatch_helper` share
|
|
1118
|
+
* (`vendor/ruby/v3.3.11/dir.c:281-297,383-386`).
|
|
1119
|
+
*/
|
|
1120
|
+
function compareChar(a, b, nocase) {
|
|
1121
|
+
const x = nocase ? a.toUpperCase() : a;
|
|
1122
|
+
const y = nocase ? b.toUpperCase() : b;
|
|
1123
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* `fnmatch_helper` (`vendor/ruby/v3.3.11/dir.c:317`), which matches one path element
|
|
1127
|
+
* under `FNM_PATHNAME` and the whole string without it. The cursors it
|
|
1128
|
+
* advances through `*pcur` / `*scur` are the returned pair; `unescape` / `isEndP`
|
|
1129
|
+
* / `isEndS` / `ret` are its `UNESCAPE` / `ISEND` / `RETURN` macros
|
|
1130
|
+
* (`dir.c:311-314`) and `failed:` its `goto failed` (`dir.c:396`).
|
|
1131
|
+
*/
|
|
1132
|
+
function fnmatchHelper(pcur, pattern, scur, string, flags) {
|
|
1133
|
+
const period = !(flags & File.FNM_DOTMATCH);
|
|
1134
|
+
const pathname = flags & File.FNM_PATHNAME;
|
|
1135
|
+
const escape = !(flags & File.FNM_NOESCAPE);
|
|
1136
|
+
const nocase = flags & File.FNM_CASEFOLD;
|
|
1137
|
+
let ptmp = null;
|
|
1138
|
+
let stmp = null;
|
|
1139
|
+
let p = pcur;
|
|
1140
|
+
let s = scur;
|
|
1141
|
+
const unescape = (i) => (escape && pattern[i] === "\\" ? i + 1 : i);
|
|
1142
|
+
const isEndP = (i) => i >= pattern.length || (!!pathname && pattern[i] === "/");
|
|
1143
|
+
const isEndS = (i) => i >= string.length || (!!pathname && string[i] === "/");
|
|
1144
|
+
const ret = (matched) => ({ matched, p, s });
|
|
1145
|
+
if (period && string[s] === "." && pattern[unescape(p)] !== ".")
|
|
1146
|
+
return ret(false);
|
|
1147
|
+
for (;;) {
|
|
1148
|
+
failed: {
|
|
1149
|
+
switch (pattern[p]) {
|
|
1150
|
+
case "*":
|
|
1151
|
+
do {
|
|
1152
|
+
p++;
|
|
1153
|
+
} while (pattern[p] === "*");
|
|
1154
|
+
if (isEndP(unescape(p))) {
|
|
1155
|
+
p = unescape(p);
|
|
1156
|
+
return ret(true);
|
|
1157
|
+
}
|
|
1158
|
+
if (isEndS(s))
|
|
1159
|
+
return ret(false);
|
|
1160
|
+
ptmp = p;
|
|
1161
|
+
stmp = s;
|
|
1162
|
+
continue;
|
|
1163
|
+
case "?":
|
|
1164
|
+
if (isEndS(s))
|
|
1165
|
+
return ret(false);
|
|
1166
|
+
p++;
|
|
1167
|
+
s = inc(string, s);
|
|
1168
|
+
continue;
|
|
1169
|
+
case "[": {
|
|
1170
|
+
if (isEndS(s))
|
|
1171
|
+
return ret(false);
|
|
1172
|
+
const t = bracket(p + 1, pattern, s, string, flags);
|
|
1173
|
+
if (t !== null) {
|
|
1174
|
+
p = t;
|
|
1175
|
+
s = inc(string, s);
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
break failed;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
p = unescape(p);
|
|
1182
|
+
if (isEndS(s))
|
|
1183
|
+
return ret(isEndP(p));
|
|
1184
|
+
if (isEndP(p))
|
|
1185
|
+
break failed;
|
|
1186
|
+
if (charAt(pattern, p) === charAt(string, s)) {
|
|
1187
|
+
p = inc(pattern, p);
|
|
1188
|
+
s = inc(string, s);
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
if (!nocase)
|
|
1192
|
+
break failed;
|
|
1193
|
+
if (compareChar(charAt(pattern, p), charAt(string, s), nocase) !== 0)
|
|
1194
|
+
break failed;
|
|
1195
|
+
p = inc(pattern, p);
|
|
1196
|
+
s = inc(string, s);
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
if (ptmp !== null && stmp !== null) {
|
|
1200
|
+
p = ptmp;
|
|
1201
|
+
stmp = inc(string, stmp);
|
|
1202
|
+
s = stmp;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
return ret(false);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* `fnmatch` (`vendor/ruby/v3.3.11/dir.c:411`) — the `FNM_PATHNAME` element walk with
|
|
1210
|
+
* its `**` + `/` backtrack, falling through to a single `fnmatch_helper` without.
|
|
1211
|
+
*/
|
|
1212
|
+
function fnmatch(pattern, string, flags) {
|
|
1213
|
+
let p = 0;
|
|
1214
|
+
let s = 0;
|
|
1215
|
+
const period = !(flags & File.FNM_DOTMATCH);
|
|
1216
|
+
const pathname = flags & File.FNM_PATHNAME;
|
|
1217
|
+
let ptmp = null;
|
|
1218
|
+
let stmp = null;
|
|
1219
|
+
if (pathname) {
|
|
1220
|
+
for (;;) {
|
|
1221
|
+
if (pattern.startsWith("**/", p)) {
|
|
1222
|
+
do {
|
|
1223
|
+
p += 3;
|
|
1224
|
+
} while (pattern.startsWith("**/", p));
|
|
1225
|
+
ptmp = p;
|
|
1226
|
+
stmp = s;
|
|
1227
|
+
}
|
|
1228
|
+
const r = fnmatchHelper(p, pattern, s, string, flags);
|
|
1229
|
+
p = r.p;
|
|
1230
|
+
s = r.s;
|
|
1231
|
+
if (r.matched) {
|
|
1232
|
+
while (s < string.length && string[s] !== "/")
|
|
1233
|
+
s++;
|
|
1234
|
+
if (p < pattern.length && s < string.length) {
|
|
1235
|
+
p++;
|
|
1236
|
+
s++;
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
if (p >= pattern.length && s >= string.length)
|
|
1240
|
+
return true;
|
|
1241
|
+
}
|
|
1242
|
+
if (ptmp !== null && stmp !== null && !(period && string[stmp] === ".")) {
|
|
1243
|
+
while (stmp < string.length && string[stmp] !== "/")
|
|
1244
|
+
stmp++;
|
|
1245
|
+
if (stmp < string.length) {
|
|
1246
|
+
p = ptmp;
|
|
1247
|
+
stmp++;
|
|
1248
|
+
s = stmp;
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
else {
|
|
1256
|
+
return fnmatchHelper(p, pattern, s, string, flags).matched;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* `ruby_brace_expand` (`vendor/ruby/v3.3.11/dir.c:3019`), which calls back once per
|
|
1261
|
+
* `{a,b}` alternative and stops at the first non-zero status — for
|
|
1262
|
+
* `fnmatch_brace` (`dir.c:3430`), the first alternative that matches.
|
|
1263
|
+
*/
|
|
1264
|
+
function rubyBraceExpand(str, flags, func) {
|
|
1265
|
+
const escape = !(flags & File.FNM_NOESCAPE);
|
|
1266
|
+
let p = 0;
|
|
1267
|
+
let lbrace = -1;
|
|
1268
|
+
let rbrace = -1;
|
|
1269
|
+
let nest = 0;
|
|
1270
|
+
while (p < str.length) {
|
|
1271
|
+
if (str[p] === "{" && nest++ === 0)
|
|
1272
|
+
lbrace = p;
|
|
1273
|
+
if (str[p] === "}" && lbrace >= 0 && --nest === 0) {
|
|
1274
|
+
rbrace = p;
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
if (str[p] === "\\" && escape) {
|
|
1278
|
+
if (++p >= str.length)
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
p++;
|
|
1282
|
+
}
|
|
1283
|
+
if (lbrace >= 0 && rbrace >= 0) {
|
|
1284
|
+
const prefix = str.slice(0, lbrace);
|
|
1285
|
+
let status = false;
|
|
1286
|
+
p = lbrace;
|
|
1287
|
+
while (p < rbrace) {
|
|
1288
|
+
const t = ++p;
|
|
1289
|
+
nest = 0;
|
|
1290
|
+
while (p < rbrace && !(str[p] === "," && nest === 0)) {
|
|
1291
|
+
if (str[p] === "{")
|
|
1292
|
+
nest++;
|
|
1293
|
+
if (str[p] === "}")
|
|
1294
|
+
nest--;
|
|
1295
|
+
if (str[p] === "\\" && escape) {
|
|
1296
|
+
if (++p === rbrace)
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
p++;
|
|
1300
|
+
}
|
|
1301
|
+
status = rubyBraceExpand(prefix + str.slice(t, p) + str.slice(rbrace + 1), flags, func);
|
|
1302
|
+
if (status)
|
|
1303
|
+
break;
|
|
1304
|
+
}
|
|
1305
|
+
return status;
|
|
1306
|
+
}
|
|
1307
|
+
else if (lbrace < 0 && rbrace < 0) {
|
|
1308
|
+
return func(str);
|
|
1309
|
+
}
|
|
1310
|
+
return false;
|
|
1311
|
+
}
|
|
1312
|
+
//# sourceMappingURL=file.js.map
|