visaljs 0.0.7 → 0.0.8
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/README.md +63 -2
- package/THIRD_PARTY_LICENSES +1216 -0
- package/cli.js +4413 -324
- package/node/include/js_node.h +57 -1
- package/node/include/js_uv.h +8 -1
- package/node/prelude/_stream_duplex.js +4 -0
- package/node/prelude/_stream_passthrough.js +4 -0
- package/node/prelude/_stream_readable.js +4 -0
- package/node/prelude/_stream_transform.js +4 -0
- package/node/prelude/_stream_writable.js +4 -0
- package/node/prelude/assert.js +1334 -0
- package/node/prelude/assert_strict.js +12 -0
- package/node/prelude/async_hooks.js +1 -1
- package/node/prelude/buffer.js +43 -3
- package/node/prelude/child_process.js +1098 -0
- package/node/prelude/cluster.js +52 -0
- package/node/prelude/console.js +328 -0
- package/node/prelude/constants.js +10 -0
- package/node/prelude/crypto.js +1 -1
- package/node/prelude/diagnostics_channel.js +1 -1
- package/node/prelude/dns.js +1 -1
- package/node/prelude/domain.js +115 -0
- package/node/prelude/events.js +144 -16
- package/node/prelude/fs.js +1138 -151
- package/node/prelude/fs_promises.js +117 -11
- package/node/prelude/http.js +104 -27
- package/node/prelude/http2.js +1 -1
- package/node/prelude/https.js +148 -0
- package/node/prelude/inspector.js +27 -0
- package/node/prelude/inspector_promises.js +4 -0
- package/node/prelude/internal/async_context.js +1 -1
- package/node/prelude/internal/buffer_transcode.js +44 -0
- package/node/prelude/internal/comparisons.js +916 -0
- package/node/prelude/internal/compression_streams.js +153 -0
- package/node/prelude/internal/crypto/asym.js +27 -14
- package/node/prelude/internal/crypto/cipher.js +16 -5
- package/node/prelude/internal/crypto/diffiehellman.js +3 -2
- package/node/prelude/internal/crypto/hash.js +2 -1
- package/node/prelude/internal/crypto/kdf.js +14 -9
- package/node/prelude/internal/crypto/keys.js +63 -50
- package/node/prelude/internal/crypto/random.js +2 -1
- package/node/prelude/internal/crypto/util.js +4 -4
- package/node/prelude/internal/dotenv.js +98 -0
- package/node/prelude/internal/errors.js +21 -5
- package/node/prelude/internal/events_extras.js +116 -0
- package/node/prelude/internal/events_on.js +100 -0
- package/node/prelude/internal/features.js +55 -0
- package/node/prelude/internal/fetch.js +364 -0
- package/node/prelude/internal/form_data.js +376 -0
- package/node/prelude/internal/fs_bigint_stats.js +41 -0
- package/node/prelude/internal/fs_blob.js +19 -0
- package/node/prelude/internal/fs_cp.js +709 -0
- package/node/prelude/internal/fs_dir.js +166 -0
- package/node/prelude/internal/fs_filehandle.js +287 -0
- package/node/prelude/internal/fs_glob.js +296 -0
- package/node/prelude/internal/fs_statfs.js +42 -0
- package/node/prelude/internal/fs_stats.js +89 -0
- package/node/prelude/internal/fs_streams.js +541 -0
- package/node/prelude/internal/fs_utils.js +286 -0
- package/node/prelude/internal/fs_watch.js +580 -0
- package/node/prelude/internal/http_agent.js +26 -0
- package/node/prelude/internal/mime.js +249 -0
- package/node/prelude/internal/net.js +1 -0
- package/node/prelude/internal/parse_args.js +288 -0
- package/node/prelude/internal/perf_histogram.js +435 -0
- package/node/prelude/internal/perf_observe.js +119 -0
- package/node/prelude/internal/performance_global.js +19 -0
- package/node/prelude/internal/process_events.js +49 -1
- package/node/prelude/internal/process_memory.js +14 -0
- package/node/prelude/internal/process_more.js +414 -0
- package/node/prelude/internal/process_signals.js +2 -1
- package/node/prelude/internal/process_stdin.js +52 -0
- package/node/prelude/internal/process_stdio.js +36 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/readline.js +338 -0
- package/node/prelude/internal/socketaddress.js +8 -4
- package/node/prelude/internal/source_map.js +122 -0
- package/node/prelude/internal/stream_compose.js +74 -0
- package/node/prelude/internal/stream_from.js +6 -0
- package/node/prelude/internal/stream_operators.js +23 -0
- package/node/prelude/internal/stream_pipeline.js +7 -0
- package/node/prelude/internal/stream_transform.js +10 -0
- package/node/prelude/internal/stream_web_adapters.js +143 -0
- package/node/prelude/internal/streams/add_abort_signal.js +58 -0
- package/node/prelude/internal/streams/compose.js +244 -0
- package/node/prelude/internal/streams/destroy.js +358 -0
- package/node/prelude/internal/streams/duplex.js +199 -0
- package/node/prelude/internal/streams/duplexify.js +378 -0
- package/node/prelude/internal/streams/end_of_stream.js +387 -0
- package/node/prelude/internal/streams/errors.js +216 -0
- package/node/prelude/internal/streams/from.js +211 -0
- package/node/prelude/internal/streams/legacy.js +120 -0
- package/node/prelude/internal/streams/operators.js +375 -0
- package/node/prelude/internal/streams/passthrough.js +45 -0
- package/node/prelude/internal/streams/pipeline.js +468 -0
- package/node/prelude/internal/streams/readable.js +1835 -0
- package/node/prelude/internal/streams/state.js +48 -0
- package/node/prelude/internal/streams/transform.js +203 -0
- package/node/prelude/internal/streams/utils.js +355 -0
- package/node/prelude/internal/streams/validators.js +108 -0
- package/node/prelude/internal/streams/writable.js +1160 -0
- package/node/prelude/internal/structured_clone.js +238 -0
- package/node/prelude/internal/system_errors.js +37 -0
- package/node/prelude/internal/test_runner/mock.js +431 -0
- package/node/prelude/internal/test_runner/reporters.js +404 -0
- package/node/prelude/internal/test_runner/test.js +1571 -0
- package/node/prelude/internal/timers.js +38 -7
- package/node/prelude/internal/timers_global.js +1 -1
- package/node/prelude/internal/tls/common.js +8 -2
- package/node/prelude/internal/tls/wrap.js +3 -15
- package/node/prelude/internal/tls/x509.js +1 -1
- package/node/prelude/internal/tty_read_stream.js +39 -0
- package/node/prelude/internal/tty_streams.js +3 -0
- package/node/prelude/internal/util_debuglog.js +68 -0
- package/node/prelude/internal/util_diff.js +63 -0
- package/node/prelude/internal/util_more.js +111 -0
- package/node/prelude/internal/util_styles.js +76 -0
- package/node/prelude/internal/zlib_engines.js +1 -1
- package/node/prelude/module.js +194 -7
- package/node/prelude/net.js +2 -1
- package/node/prelude/os.js +88 -11
- package/node/prelude/path.js +11 -7
- package/node/prelude/path_posix.js +1 -1
- package/node/prelude/path_win32.js +1 -1
- package/node/prelude/perf_hooks.js +147 -0
- package/node/prelude/process.js +36 -1
- package/node/prelude/punycode.js +188 -0
- package/node/prelude/querystring.js +1 -1
- package/node/prelude/readline.js +8 -0
- package/node/prelude/readline_promises.js +88 -0
- package/node/prelude/repl.js +38 -0
- package/node/prelude/sea.js +23 -0
- package/node/prelude/stream.js +70 -1332
- package/node/prelude/stream_consumers.js +34 -0
- package/node/prelude/stream_promises.js +1 -1
- package/node/prelude/stream_web.js +15 -2
- package/node/prelude/string_decoder.js +1 -1
- package/node/prelude/sys.js +7 -0
- package/node/prelude/test.js +56 -0
- package/node/prelude/test_reporters.js +269 -0
- package/node/prelude/timers.js +7 -84
- package/node/prelude/timers_promises.js +1 -1
- package/node/prelude/tls.js +2 -1
- package/node/prelude/trace_events.js +52 -0
- package/node/prelude/tty.js +10 -4
- package/node/prelude/url.js +88 -27
- package/node/prelude/util.js +121 -5
- package/node/prelude/util_types.js +4 -3
- package/node/prelude/v8.js +814 -0
- package/node/prelude/vm.js +86 -0
- package/node/prelude/wasi.js +10 -0
- package/node/prelude/worker_threads.js +56 -0
- package/node/prelude/zlib.js +58 -25
- package/node/src/host_brotli.c +59 -11
- package/node/src/host_fs.c +342 -11
- package/node/src/host_fswatch.c +170 -0
- package/node/src/host_http.c +143 -20
- package/node/src/host_loop.c +25 -2
- package/node/src/host_net.c +55 -7
- package/node/src/host_os.c +55 -1
- package/node/src/host_proc.c +291 -0
- package/node/src/host_process.c +488 -0
- package/node/src/host_sys.c +64 -2
- package/node/src/host_zlib.c +27 -7
- package/node/src/host_zstd.c +41 -6
- package/node/third_party/hdrhistogram/LICENSE +42 -0
- package/node/third_party/hdrhistogram/README.md +5 -0
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/LICENSE-extra +36 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/node/third_party/nodejs/LICENSE +47 -0
- package/node/third_party/nodejs/README.md +5 -0
- package/node/third_party/parseargs/LICENSE +21 -0
- package/node/third_party/parseargs/README.md +5 -0
- package/node/third_party/punycode/LICENSE +20 -0
- package/node/third_party/punycode/README.md +5 -0
- package/node/third_party/zlib/LICENSE.chromium +27 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-arm64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-arm64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/darwin-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-x64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-x64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +1 -1
- package/runtime/include/js_bigint.h +1 -1
- package/runtime/include/js_buffer.h +4 -4
- package/runtime/include/js_builtins.h +41 -3
- package/runtime/include/js_console.h +9 -4
- package/runtime/include/js_convert.h +1 -1
- package/runtime/include/js_core.def +5 -4
- package/runtime/include/js_crypto.h +1 -1
- package/runtime/include/js_error.h +1 -1
- package/runtime/include/js_exception.h +21 -1
- package/runtime/include/js_function.h +33 -9
- package/runtime/include/js_gc.h +172 -30
- package/runtime/include/js_generator.h +2 -2
- package/runtime/include/js_host.h +19 -1
- package/runtime/include/js_jobs.h +5 -5
- package/runtime/include/js_module.h +1 -1
- package/runtime/include/js_object.h +142 -15
- package/runtime/include/js_ops.h +107 -5
- package/runtime/include/js_promise.h +3 -3
- package/runtime/include/js_regexp.h +1 -1
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +1 -1
- package/runtime/include/js_web.h +2 -1
- package/runtime/include/jscell.h +22 -15
- package/runtime/include/jscontext.h +74 -39
- package/runtime/include/jsnum.h +1 -1
- package/runtime/include/jsstring.h +19 -6
- package/runtime/include/jsvalue.h +7 -3
- package/runtime/src/arguments.c +2 -2
- package/runtime/src/array.c +4 -1
- package/runtime/src/arraybuffer.c +19 -7
- package/runtime/src/async_iter.c +4 -3
- package/runtime/src/atoms.c +1 -1
- package/runtime/src/base64.c +2 -2
- package/runtime/src/bigint.c +1 -1
- package/runtime/src/blob.c +22 -9
- package/runtime/src/boringssl_support.cc +1 -1
- package/runtime/src/buffer.c +299 -91
- package/runtime/src/builtin_table.c +1 -1
- package/runtime/src/builtins.c +30 -4
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +18 -3
- package/runtime/src/components.c +1 -1
- package/runtime/src/console.c +14 -7
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +1 -1
- package/runtime/src/crypto.c +1 -1
- package/runtime/src/crypto_asym.c +1 -1
- package/runtime/src/crypto_bn.c +1 -1
- package/runtime/src/crypto_cipher.c +10 -3
- package/runtime/src/crypto_hash.c +1 -1
- package/runtime/src/crypto_host.c +1 -1
- package/runtime/src/crypto_internal.h +1 -1
- package/runtime/src/crypto_kdf.c +1 -1
- package/runtime/src/crypto_key.c +14 -1
- package/runtime/src/crypto_pkey.c +1 -1
- package/runtime/src/crypto_subtle.c +142 -58
- package/runtime/src/crypto_tls.c +1 -1
- package/runtime/src/date.c +5 -2
- package/runtime/src/domexception.c +2 -2
- package/runtime/src/elements.c +56 -17
- package/runtime/src/elements.h +7 -2
- package/runtime/src/encoding.c +1 -1
- package/runtime/src/error.c +4 -4
- package/runtime/src/events.c +23 -14
- package/runtime/src/exception.c +1 -1
- package/runtime/src/fetch.c +241 -17
- package/runtime/src/function.c +31 -19
- package/runtime/src/gc.c +1716 -207
- package/runtime/src/gc_visit.h +87 -0
- package/runtime/src/generator.c +5 -3
- package/runtime/src/global.c +14 -6
- package/runtime/src/headers.c +10 -10
- package/runtime/src/inspect.c +76 -17
- package/runtime/src/internal.h +5 -2
- package/runtime/src/iterate.c +94 -2
- package/runtime/src/iterator.c +1 -1
- package/runtime/src/jobs.c +11 -5
- package/runtime/src/jsnum.c +2 -2
- package/runtime/src/json.c +1 -1
- package/runtime/src/math.c +9 -1
- package/runtime/src/module.c +3 -3
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +107 -74
- package/runtime/src/ops.c +21 -3
- package/runtime/src/os.c +192 -1
- package/runtime/src/os.h +33 -2
- package/runtime/src/process.c +73 -8
- package/runtime/src/promise.c +4 -4
- package/runtime/src/proxy.c +1 -1
- package/runtime/src/reflect.c +1 -1
- package/runtime/src/regexp.c +134 -2
- package/runtime/src/regexp_anchor.h +1 -1
- package/runtime/src/regexp_message.h +1 -1
- package/runtime/src/shape.c +10 -19
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +22 -8
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +64 -25
- package/runtime/src/string_builtins.c +7 -7
- package/runtime/src/symbol.c +2 -7
- package/runtime/src/test_host.c +3 -3
- package/runtime/src/tls_roots.gen.h +102 -620
- package/runtime/src/typedarray.c +8 -3
- package/runtime/src/tznames.gen.h +2 -1
- package/runtime/src/uri.c +1 -1
- package/runtime/src/url.c +42 -39
- package/runtime/src/weak.c +15 -12
- package/runtime/src/web.c +21 -3
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +7 -6
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +7 -7
- package/runtime/third_party/ada-idna/convert.mjs +89 -27
- package/runtime/third_party/ada-idna/idna.c +30 -31
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +2272 -1952
- package/runtime/third_party/boringssl/third_party/fiat/LICENSE +15 -0
- package/runtime/third_party/mozilla-ca/LICENSE +373 -0
- package/runtime/third_party/mozilla-ca/README.md +9 -0
- package/runtime/third_party/nodejs/LICENSE +47 -0
- package/runtime/third_party/nodejs/README.md +7 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +1 -1
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +2 -2
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/unicode/LICENSE +39 -0
- package/runtime/third_party/unicode/README.md +9 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE.fdlibm +10 -0
- package/runtime/third_party/v8-ieee754/README.md +3 -2
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +2 -2
package/node/prelude/fs.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
// node:fs
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
1
|
+
// node:fs: the synchronous file API, over the host primitives, and the callback API over it.
|
|
2
|
+
// Arguments are checked as Node's lib/fs.js checks them, in its order, with its errors
|
|
3
|
+
// (internal/fs_utils.js): a callback function's errors in its arguments are thrown, as Node's,
|
|
4
|
+
// and only the operation's outcome reaches the callback, on a later tick, though the I/O itself
|
|
5
|
+
// happened synchronously (so do node:fs/promises'). Contents are Buffers without an encoding,
|
|
6
|
+
// else strings in any of Buffer's encodings.
|
|
7
|
+
import {
|
|
8
|
+
errnoName, fsCall, fsClose, fsConstants, fsExists, fsMkdir, fsOpen, fsRead, fsReaddir, fsReadFile, fsRealpath, fsStat, fsUnlink, fsUtimes, fsWrite,
|
|
9
|
+
} from "visaljs:host";
|
|
10
|
+
import { systemError } from "./internal/errors.js";
|
|
11
|
+
import { lazyClass, lazyConstructor, lazyFunction } from "./internal/features.js";
|
|
12
|
+
import {
|
|
13
|
+
copyObject, emitRecursiveRmdirWarning, getOptions, getValidatedFd, getValidatedPath, getValidMode, kIoMaxLength, kMaxUserId, parseFileMode,
|
|
14
|
+
rmIsDirectory, stringToFlags, toUnixTimestamp, validateBufferArray, validateOffsetLengthRead, validateOffsetLengthWrite, validatePosition,
|
|
15
|
+
validateRmdirOptions, validateRmOptionsShape, validateStringAfterArrayBufferView, warnOnNonPortableTemplate,
|
|
16
|
+
} from "./internal/fs_utils.js";
|
|
17
|
+
import { AbortError, codes } from "./internal/streams/errors.js";
|
|
18
|
+
import {
|
|
19
|
+
kEmptyObject, validateBoolean, validateBuffer, validateFunction, validateInteger, validateObject, validateOneOf,
|
|
20
|
+
} from "./internal/streams/validators.js";
|
|
21
|
+
import { Stats, statsFrom } from "./internal/fs_stats.js";
|
|
22
|
+
import { dirname, resolve } from "./path.js";
|
|
8
23
|
|
|
9
|
-
|
|
10
|
-
if (typeof path !== "string") {
|
|
11
|
-
if (typeof path === "number") throw notSupported("A file descriptor as a path");
|
|
12
|
-
if (typeof URL === "function" && path instanceof URL) throw notSupported("A file: URL as a path");
|
|
13
|
-
throw invalidArgType("path", "of type string or an instance of Buffer or URL", path);
|
|
14
|
-
}
|
|
15
|
-
if (path.indexOf("\u0000") !== -1) throw invalidArgValue("path", "must be a string without null bytes", path);
|
|
16
|
-
}
|
|
24
|
+
const { ERR_FS_FILE_TOO_LARGE, ERR_INVALID_ARG_VALUE } = codes;
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (typeof options === "string") return options;
|
|
21
|
-
if (typeof options === "object") return options.encoding ?? undefined;
|
|
22
|
-
throw invalidArgType("options", "one of type string or an instance of Object", options);
|
|
23
|
-
}
|
|
26
|
+
/* a file descriptor where a path may be (readFile, writeFile, appendFile) */
|
|
27
|
+
const isFd = (path) => path === (path | 0);
|
|
24
28
|
|
|
25
29
|
function isUtf8(encoding) {
|
|
26
30
|
return encoding === "utf8" || encoding === "utf-8" || encoding === "UTF8" || encoding === "UTF-8";
|
|
@@ -31,94 +35,535 @@ function check(result, syscall, path) {
|
|
|
31
35
|
return result;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
/* a call that returns a number, an fd or a count, when it succeeds: negative is -errno */
|
|
39
|
+
function checkCount(result, syscall, path) {
|
|
40
|
+
if (result < 0) throw systemError(result, syscall, path);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* a name as the encoding asks: a string, or a Buffer for "buffer" */
|
|
45
|
+
function encoded(name, encoding) {
|
|
46
|
+
return encoding == null || isUtf8(encoding) ? name : encoding === "buffer" ? Buffer.from(name) : Buffer.from(name).toString(encoding);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* ---- the callback API: the arguments checked, then the work, its outcome on a later tick ---- */
|
|
50
|
+
|
|
51
|
+
function makeCallback(cb) {
|
|
52
|
+
validateFunction(cb, "cb");
|
|
53
|
+
return cb;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* the operation now, its result or error to the callback on a later turn of the event loop, as
|
|
57
|
+
* Node's request completes (timers run between a stream's reads, as in Node) */
|
|
58
|
+
function defer(callback, fn, ...args) {
|
|
59
|
+
let result, error = null;
|
|
60
|
+
try {
|
|
61
|
+
result = fn(...args);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
error = e;
|
|
64
|
+
}
|
|
65
|
+
/* a call without a result gives the callback only its error (null), as Node's */
|
|
66
|
+
setImmediate(() => (error ? callback(error) : result === undefined ? callback(null) : callback(null, result)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function checkAborted(signal, callback) {
|
|
70
|
+
if (signal?.aborted) {
|
|
71
|
+
callback(new AbortError(undefined, { cause: signal.reason }));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ---- open, close, read, write ------------------------------------------------------------ */
|
|
78
|
+
|
|
79
|
+
function doOpen(path, flags, mode) {
|
|
80
|
+
return checkCount(fsOpen(path, flags, mode), "open", path);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function openSync(path, flags, mode) {
|
|
84
|
+
return doOpen(getValidatedPath(path), stringToFlags(flags), parseFileMode(mode, "mode", 0o666));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function open(path, flags, mode, callback) {
|
|
88
|
+
path = getValidatedPath(path);
|
|
89
|
+
if (arguments.length < 3) {
|
|
90
|
+
callback = flags;
|
|
91
|
+
flags = "r";
|
|
92
|
+
mode = 0o666;
|
|
93
|
+
} else if (typeof mode === "function") {
|
|
94
|
+
callback = mode;
|
|
95
|
+
mode = 0o666;
|
|
96
|
+
} else {
|
|
97
|
+
mode = parseFileMode(mode, "mode", 0o666);
|
|
98
|
+
}
|
|
99
|
+
const flagsNumber = stringToFlags(flags);
|
|
100
|
+
callback = makeCallback(callback);
|
|
101
|
+
defer(callback, doOpen, path, flagsNumber, mode);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function doClose(fd) {
|
|
105
|
+
check(fsClose(fd), "close");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function closeSync(fd) {
|
|
109
|
+
doClose(getValidatedFd(fd));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function defaultCloseCallback(err) {
|
|
113
|
+
if (err != null) throw err;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function close(fd, callback = defaultCloseCallback) {
|
|
117
|
+
if (callback !== defaultCloseCallback) callback = makeCallback(callback);
|
|
118
|
+
defer(callback, doClose, getValidatedFd(fd));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* a position as the host takes it: -1 for the current one */
|
|
122
|
+
const hostPosition = (position) => (position == null || position === -1 ? -1 : Number(position));
|
|
123
|
+
|
|
124
|
+
function doRead(fd, buffer, offset, length, position) {
|
|
125
|
+
return checkCount(fsRead(fd, buffer, offset, length, hostPosition(position)), "read");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** readSync(fd, buffer, offset, length, position) or readSync(fd, buffer, { offset, length, position }):
|
|
129
|
+
* the bytes read, 0 at the end of the file. */
|
|
130
|
+
export function readSync(fd, buffer, offsetOrOptions, length, position) {
|
|
131
|
+
fd = getValidatedFd(fd);
|
|
132
|
+
validateBuffer(buffer);
|
|
133
|
+
let offset = offsetOrOptions;
|
|
134
|
+
if (arguments.length <= 3 || typeof offsetOrOptions === "object") {
|
|
135
|
+
if (offsetOrOptions !== undefined && offsetOrOptions !== null) validateObject(offsetOrOptions, "options");
|
|
136
|
+
({ offset = 0, length = buffer.byteLength - offset, position = null } = offsetOrOptions ?? kEmptyObject);
|
|
137
|
+
}
|
|
138
|
+
if (offset === undefined) offset = 0;
|
|
139
|
+
else validateInteger(offset, "offset", 0);
|
|
140
|
+
length |= 0;
|
|
141
|
+
if (position == null) position = -1;
|
|
142
|
+
else validatePosition(position, "position", length);
|
|
143
|
+
if (length === 0) return 0;
|
|
144
|
+
if (buffer.byteLength === 0) throw new ERR_INVALID_ARG_VALUE("buffer", buffer, "is empty and cannot be written");
|
|
145
|
+
validateOffsetLengthRead(offset, length, buffer.byteLength);
|
|
146
|
+
return doRead(fd, buffer, offset, length, position);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** read(fd, buffer, offset, length, position, callback), read(fd, buffer, options, callback),
|
|
150
|
+
* read(fd, options, callback) or read(fd, callback): the callback gets the bytes read and the buffer. */
|
|
151
|
+
export function read(fd, buffer, offsetOrOptions, length, position, callback) {
|
|
152
|
+
fd = getValidatedFd(fd);
|
|
153
|
+
let offset = offsetOrOptions;
|
|
154
|
+
let params = null;
|
|
155
|
+
if (arguments.length <= 4) {
|
|
156
|
+
if (arguments.length === 4) {
|
|
157
|
+
if (offsetOrOptions !== null) validateObject(offsetOrOptions, "options");
|
|
158
|
+
callback = length;
|
|
159
|
+
params = offsetOrOptions;
|
|
160
|
+
} else if (arguments.length === 3) {
|
|
161
|
+
if (!ArrayBuffer.isView(buffer)) {
|
|
162
|
+
params = buffer;
|
|
163
|
+
({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject);
|
|
164
|
+
}
|
|
165
|
+
callback = offsetOrOptions;
|
|
166
|
+
} else {
|
|
167
|
+
callback = buffer;
|
|
168
|
+
buffer = Buffer.alloc(16384);
|
|
169
|
+
}
|
|
170
|
+
if (params !== undefined && params !== null) validateObject(params, "options");
|
|
171
|
+
({ offset = 0, length = buffer?.byteLength - offset, position = null } = params ?? kEmptyObject);
|
|
172
|
+
}
|
|
173
|
+
validateBuffer(buffer);
|
|
174
|
+
validateFunction(callback, "cb");
|
|
175
|
+
if (offset == null) offset = 0;
|
|
176
|
+
else validateInteger(offset, "offset", 0);
|
|
177
|
+
length |= 0;
|
|
178
|
+
if (position == null) position = -1;
|
|
179
|
+
else validatePosition(position, "position", length);
|
|
180
|
+
if (length === 0) return process.nextTick(() => callback(null, 0, buffer));
|
|
181
|
+
if (buffer.byteLength === 0) throw new ERR_INVALID_ARG_VALUE("buffer", buffer, "is empty and cannot be written");
|
|
182
|
+
validateOffsetLengthRead(offset, length, buffer.byteLength);
|
|
183
|
+
defer((err, bytesRead) => callback(err, bytesRead || 0, buffer), doRead, fd, buffer, offset, length, position);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function doWrite(fd, buffer, offset, length, position) {
|
|
187
|
+
return checkCount(fsWrite(fd, buffer, offset, length, typeof position === "number" ? position : -1), "write");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Node's validateEncoding: hex takes whole bytes */
|
|
191
|
+
function validateEncoding(data, encoding) {
|
|
192
|
+
if (typeof encoding === "string" && encoding.toLowerCase() === "hex" && data.length % 2 !== 0) {
|
|
193
|
+
throw new ERR_INVALID_ARG_VALUE("encoding", encoding, `is invalid for data of length ${data.length}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* a string's bytes in an encoding (an unknown one is UTF-8, as Node's binding takes it) */
|
|
198
|
+
const stringBytes = (string, encoding) => Buffer.from(string, typeof encoding === "string" && Buffer.isEncoding(encoding) ? encoding : "utf8");
|
|
199
|
+
|
|
200
|
+
/** writeSync(fd, buffer, offset?, length?, position?) or writeSync(fd, string, position?, encoding?):
|
|
201
|
+
* the bytes written. A position that isn't a number writes at the current offset. */
|
|
202
|
+
export function writeSync(fd, buffer, offsetOrOptions, length, position) {
|
|
203
|
+
fd = getValidatedFd(fd);
|
|
204
|
+
let offset = offsetOrOptions;
|
|
205
|
+
if (ArrayBuffer.isView(buffer)) {
|
|
206
|
+
if (typeof offset === "object") {
|
|
207
|
+
({ offset = 0, length = buffer.byteLength - offset, position = null } = offsetOrOptions ?? kEmptyObject);
|
|
208
|
+
}
|
|
209
|
+
if (position === undefined) position = null;
|
|
210
|
+
if (offset == null) offset = 0;
|
|
211
|
+
else validateInteger(offset, "offset", 0);
|
|
212
|
+
if (typeof length !== "number") length = buffer.byteLength - offset;
|
|
213
|
+
validateOffsetLengthWrite(offset, length, buffer.byteLength);
|
|
214
|
+
return doWrite(fd, buffer, offset, length, position);
|
|
215
|
+
}
|
|
216
|
+
validateStringAfterArrayBufferView(buffer, "buffer");
|
|
217
|
+
validateEncoding(buffer, length);
|
|
218
|
+
const bytes = stringBytes(buffer, length);
|
|
219
|
+
return doWrite(fd, bytes, 0, bytes.length, offset);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** write(fd, buffer, offset?, length?, position?, callback) or write(fd, string, position?,
|
|
223
|
+
* encoding?, callback): the callback gets the bytes written and the data. */
|
|
224
|
+
export function write(fd, buffer, offsetOrOptions, length, position, callback) {
|
|
225
|
+
const wrapper = (err, written) => callback(err, written || 0, buffer);
|
|
226
|
+
fd = getValidatedFd(fd);
|
|
227
|
+
let offset = offsetOrOptions;
|
|
228
|
+
if (ArrayBuffer.isView(buffer)) {
|
|
229
|
+
callback ||= position || length || offset;
|
|
230
|
+
validateFunction(callback, "cb");
|
|
231
|
+
if (typeof offset === "object") {
|
|
232
|
+
({ offset = 0, length = buffer.byteLength - offset, position = null } = offsetOrOptions ?? kEmptyObject);
|
|
233
|
+
}
|
|
234
|
+
if (offset == null || typeof offset === "function") offset = 0;
|
|
235
|
+
else validateInteger(offset, "offset", 0);
|
|
236
|
+
if (typeof length !== "number") length = buffer.byteLength - offset;
|
|
237
|
+
if (typeof position !== "number") position = null;
|
|
238
|
+
validateOffsetLengthWrite(offset, length, buffer.byteLength);
|
|
239
|
+
return defer(wrapper, doWrite, fd, buffer, offset, length, position);
|
|
240
|
+
}
|
|
241
|
+
validateStringAfterArrayBufferView(buffer, "buffer");
|
|
242
|
+
if (typeof position !== "function") {
|
|
243
|
+
if (typeof offset === "function") {
|
|
244
|
+
position = offset;
|
|
245
|
+
offset = null;
|
|
246
|
+
} else {
|
|
247
|
+
position = length;
|
|
248
|
+
}
|
|
249
|
+
length = "utf8";
|
|
250
|
+
}
|
|
251
|
+
validateEncoding(buffer, length);
|
|
252
|
+
callback = position;
|
|
253
|
+
validateFunction(callback, "cb");
|
|
254
|
+
const bytes = stringBytes(buffer, length);
|
|
255
|
+
defer(wrapper, doWrite, fd, bytes, 0, bytes.length, offset);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* the buffers, in turn, from a position (or the current offset): the bytes moved */
|
|
259
|
+
function vectored(fn, syscall, fd, buffers, position) {
|
|
260
|
+
let total = 0;
|
|
261
|
+
let at = typeof position === "number" ? position : -1;
|
|
262
|
+
for (const buffer of buffers) {
|
|
263
|
+
const n = checkCount(fn(fd, buffer, 0, buffer.byteLength, at), syscall);
|
|
264
|
+
total += n;
|
|
265
|
+
if (at >= 0) at += n;
|
|
266
|
+
if (n < buffer.byteLength) break; /* the end of the file */
|
|
267
|
+
}
|
|
268
|
+
return total;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** readvSync(fd, buffers[, position]): the bytes read into the buffers, in turn. */
|
|
272
|
+
export function readvSync(fd, buffers, position) {
|
|
273
|
+
fd = getValidatedFd(fd);
|
|
274
|
+
validateBufferArray(buffers);
|
|
275
|
+
return vectored(fsRead, "read", fd, buffers, position);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** writevSync(fd, buffers[, position]): the bytes written from the buffers, in turn. */
|
|
279
|
+
export function writevSync(fd, buffers, position) {
|
|
280
|
+
fd = getValidatedFd(fd);
|
|
281
|
+
validateBufferArray(buffers);
|
|
282
|
+
if (buffers.length === 0) return 0;
|
|
283
|
+
return vectored(fsWrite, "write", fd, buffers, position);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function readv(fd, buffers, position, callback) {
|
|
287
|
+
fd = getValidatedFd(fd);
|
|
288
|
+
validateBufferArray(buffers);
|
|
289
|
+
callback ||= position;
|
|
290
|
+
validateFunction(callback, "cb");
|
|
291
|
+
defer((err, n) => callback(err, n || 0, buffers), vectored, fsRead, "read", fd, buffers, position);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function writev(fd, buffers, position, callback) {
|
|
295
|
+
fd = getValidatedFd(fd);
|
|
296
|
+
validateBufferArray(buffers);
|
|
297
|
+
callback ||= position;
|
|
298
|
+
validateFunction(callback, "cb");
|
|
299
|
+
if (buffers.length === 0) return process.nextTick(callback, null, 0, buffers);
|
|
300
|
+
defer((err, n) => callback(err, n || 0, buffers), vectored, fsWrite, "write", fd, buffers, position);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* ---- whole files ----------------------------------------------------------------------- */
|
|
304
|
+
|
|
305
|
+
/* a file's contents from an open descriptor: the size fstat gives (0 for what isn't a regular file:
|
|
306
|
+
* read to the end) */
|
|
307
|
+
function readAll(fd) {
|
|
308
|
+
const st = fsCall(FS_FSTAT, fd);
|
|
309
|
+
const size = Array.isArray(st) && (st[0] & S_IFMT) === S_IFREG ? st[1] : 0;
|
|
310
|
+
if (size > kIoMaxLength) throw new ERR_FS_FILE_TOO_LARGE(size);
|
|
311
|
+
if (size !== 0) {
|
|
312
|
+
const buffer = Buffer.allocUnsafe(size);
|
|
313
|
+
let pos = 0, n;
|
|
314
|
+
do {
|
|
315
|
+
n = doRead(fd, buffer, pos, size - pos, -1);
|
|
316
|
+
pos += n;
|
|
317
|
+
} while (n !== 0 && pos < size);
|
|
318
|
+
return pos < size ? buffer.subarray(0, pos) : buffer;
|
|
319
|
+
}
|
|
320
|
+
const chunks = [];
|
|
321
|
+
let n;
|
|
322
|
+
do {
|
|
323
|
+
const chunk = Buffer.allocUnsafe(8192);
|
|
324
|
+
n = doRead(fd, chunk, 0, 8192, -1);
|
|
325
|
+
if (n !== 0) chunks.push(chunk.subarray(0, n));
|
|
326
|
+
} while (n !== 0);
|
|
327
|
+
return Buffer.concat(chunks);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/* readFile's work, its options checked: a path read with the host's readFile when opened for reading
|
|
331
|
+
* (the common case), else opened and read, or an fd read from where it is */
|
|
332
|
+
function doReadFile(path, options) {
|
|
333
|
+
const encoding = options.encoding;
|
|
334
|
+
let contents;
|
|
335
|
+
if (!isFd(path) && stringToFlags(options.flag) === O_RDONLY) {
|
|
336
|
+
const asText = encoding != null && isUtf8(encoding);
|
|
337
|
+
const result = fsReadFile(path, !asText);
|
|
338
|
+
if (typeof result === "number") {
|
|
339
|
+
const code = errnoName(result);
|
|
340
|
+
/* opening a directory succeeds; reading it fails: Node reports that read, without a path */
|
|
341
|
+
if (code === "EISDIR") throw systemError(result, "read");
|
|
342
|
+
if (code === "EFBIG") throw new ERR_FS_FILE_TOO_LARGE(statSync(path).size);
|
|
343
|
+
}
|
|
344
|
+
contents = check(result, "open", path);
|
|
345
|
+
if (asText) return contents;
|
|
346
|
+
} else if (isFd(path)) {
|
|
347
|
+
contents = readAll(path);
|
|
348
|
+
} else {
|
|
349
|
+
const fd = doOpen(path, stringToFlags(options.flag), 0o666);
|
|
350
|
+
try {
|
|
351
|
+
contents = readAll(fd);
|
|
352
|
+
} finally {
|
|
353
|
+
doClose(fd);
|
|
354
|
+
}
|
|
37
355
|
}
|
|
356
|
+
return encoding == null || encoding === "buffer" ? contents : contents.toString(encoding);
|
|
38
357
|
}
|
|
39
358
|
|
|
40
359
|
export function readFileSync(path, options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const asText = encoding !== undefined && isUtf8(encoding);
|
|
45
|
-
const result = fsReadFile(path, !asText);
|
|
46
|
-
/* opening a directory succeeds; reading it fails: Node reports that read, without a path */
|
|
47
|
-
if (typeof result === "number" && errnoName(result) === "EISDIR") throw systemError(result, "read");
|
|
48
|
-
const contents = check(result, "open", path);
|
|
49
|
-
return asText || encoding === undefined || encoding === "buffer" ? contents : contents.toString(encoding);
|
|
360
|
+
options = getOptions(options, { flag: "r" });
|
|
361
|
+
if (!isFd(path)) path = getValidatedPath(path);
|
|
362
|
+
return doReadFile(path, options);
|
|
50
363
|
}
|
|
51
364
|
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
365
|
+
export function readFile(path, options, callback) {
|
|
366
|
+
callback ||= options;
|
|
367
|
+
validateFunction(callback, "cb");
|
|
368
|
+
options = getOptions(options, { flag: "r" });
|
|
369
|
+
if (!isFd(path)) {
|
|
370
|
+
if (checkAborted(options.signal, callback)) return;
|
|
371
|
+
stringToFlags(options.flag, "options.flag");
|
|
372
|
+
path = getValidatedPath(path);
|
|
373
|
+
}
|
|
374
|
+
/* on a later turn of the event loop, as Node's opens and reads on its thread pool: an abort before
|
|
375
|
+
* then stops it */
|
|
376
|
+
setImmediate(() => {
|
|
377
|
+
if (checkAborted(options.signal, callback)) return;
|
|
378
|
+
defer(callback, doReadFile, path, options);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/* writeFile's work, its data as bytes or a string and its options checked. With `flush`, the file is
|
|
383
|
+
* synced through fs.fsyncSync (a program may replace it, as Node's calls it); `keepOpen` leaves the
|
|
384
|
+
* descriptor open and unsynced, returned for the callback API's fs.fsync. */
|
|
385
|
+
function doWriteFile(path, data, options, keepOpen = false) {
|
|
386
|
+
const flag = options.flag || "w";
|
|
387
|
+
const flush = options.flush ?? false;
|
|
388
|
+
/* opened, written and closed: an error names the call that failed, as Node's */
|
|
389
|
+
if (typeof data === "string") data = Buffer.from(data, options.encoding || "utf8");
|
|
390
|
+
const userFd = isFd(path);
|
|
391
|
+
const fd = userFd ? path : doOpen(path, stringToFlags(flag), parseFileMode(options.mode, "mode", 0o666));
|
|
392
|
+
try {
|
|
393
|
+
let offset = 0, length = data.byteLength;
|
|
394
|
+
while (length > 0) {
|
|
395
|
+
const written = doWrite(fd, data, offset, length, null);
|
|
396
|
+
offset += written;
|
|
397
|
+
length -= written;
|
|
398
|
+
}
|
|
399
|
+
if (keepOpen) return fd;
|
|
400
|
+
if (flush) fs.fsyncSync(fd);
|
|
401
|
+
} catch (e) {
|
|
402
|
+
keepOpen = false;
|
|
403
|
+
throw e;
|
|
404
|
+
} finally {
|
|
405
|
+
if (!userFd && !keepOpen) doClose(fd);
|
|
56
406
|
}
|
|
57
|
-
const encoding = encodingOf(options);
|
|
58
|
-
validateEncodingName(encoding);
|
|
59
|
-
if (typeof data === "string" && encoding !== undefined && encoding !== "buffer" && !isUtf8(encoding)) data = Buffer.from(data, encoding);
|
|
60
|
-
const flag = options != null && typeof options === "object" ? options.flag : undefined;
|
|
61
|
-
check(fsWriteFile(path, data, append || flag === "a"), "open", path);
|
|
62
407
|
}
|
|
63
408
|
|
|
409
|
+
const writeFileDefaults = { encoding: "utf8", mode: 0o666, flag: "w", flush: false };
|
|
410
|
+
|
|
64
411
|
export function writeFileSync(path, data, options) {
|
|
65
|
-
|
|
412
|
+
options = getOptions(options, writeFileDefaults);
|
|
413
|
+
validateBoolean(options.flush ?? false, "options.flush");
|
|
414
|
+
if (!(typeof data === "string" && isUtf8(options.encoding))) {
|
|
415
|
+
if (!ArrayBuffer.isView(data)) {
|
|
416
|
+
validateStringAfterArrayBufferView(data, "data");
|
|
417
|
+
data = Buffer.from(data, options.encoding || "utf8");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (!isFd(path)) path = getValidatedPath(path);
|
|
421
|
+
doWriteFile(path, data, options);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export function writeFile(path, data, options, callback) {
|
|
425
|
+
callback ||= options;
|
|
426
|
+
validateFunction(callback, "cb");
|
|
427
|
+
options = getOptions(options, writeFileDefaults);
|
|
428
|
+
validateBoolean(options.flush ?? false, "options.flush");
|
|
429
|
+
if (!ArrayBuffer.isView(data)) {
|
|
430
|
+
validateStringAfterArrayBufferView(data, "data");
|
|
431
|
+
data = Buffer.from(data, options.encoding || "utf8");
|
|
432
|
+
}
|
|
433
|
+
if (!isFd(path)) {
|
|
434
|
+
if (checkAborted(options.signal, callback)) return;
|
|
435
|
+
path = getValidatedPath(path);
|
|
436
|
+
}
|
|
437
|
+
/* on a later turn of the event loop, as Node's opens and writes on its thread pool: an abort before
|
|
438
|
+
* then stops it */
|
|
439
|
+
setImmediate(() => {
|
|
440
|
+
if (checkAborted(options.signal, callback)) return;
|
|
441
|
+
if (!options.flush) return defer(callback, doWriteFile, path, data, options);
|
|
442
|
+
/* the flush through fs.fsync, then the close, as Node's writeAll */
|
|
443
|
+
let fd;
|
|
444
|
+
try {
|
|
445
|
+
fd = doWriteFile(path, data, options, true);
|
|
446
|
+
} catch (e) {
|
|
447
|
+
return process.nextTick(callback, e);
|
|
448
|
+
}
|
|
449
|
+
fs.fsync(fd, (err) => {
|
|
450
|
+
if (!isFd(path)) {
|
|
451
|
+
try {
|
|
452
|
+
doClose(fd);
|
|
453
|
+
} catch (e) {
|
|
454
|
+
err ??= e;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
callback(err ?? null);
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function appendOptions(path, options) {
|
|
463
|
+
options = copyObject(getOptions(options, { encoding: "utf8", mode: 0o666, flag: "a" }));
|
|
464
|
+
if (!options.flag || isFd(path)) options.flag = "a";
|
|
465
|
+
return options;
|
|
66
466
|
}
|
|
67
467
|
|
|
68
468
|
export function appendFileSync(path, data, options) {
|
|
69
|
-
|
|
469
|
+
writeFileSync(path, data, appendOptions(path, options));
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export function appendFile(path, data, options, callback) {
|
|
473
|
+
callback ||= options;
|
|
474
|
+
validateFunction(callback, "cb");
|
|
475
|
+
writeFile(path, data, appendOptions(path, options), callback);
|
|
70
476
|
}
|
|
71
477
|
|
|
478
|
+
let showExistsDeprecation = true;
|
|
72
479
|
export function existsSync(path) {
|
|
73
|
-
|
|
480
|
+
try {
|
|
481
|
+
path = getValidatedPath(path);
|
|
482
|
+
} catch (err) {
|
|
483
|
+
/* Node 24: a type no path can be, deprecated (DEP0187), warning once */
|
|
484
|
+
if (showExistsDeprecation && err?.code === "ERR_INVALID_ARG_TYPE") {
|
|
485
|
+
process.emitWarning("Passing invalid argument types to fs.existsSync is deprecated", "DeprecationWarning", "DEP0187");
|
|
486
|
+
showExistsDeprecation = false;
|
|
487
|
+
}
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
74
490
|
return fsExists(path);
|
|
75
491
|
}
|
|
76
492
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
493
|
+
/** Deprecated in Node: the callback gets only whether the path exists. */
|
|
494
|
+
export function exists(path, callback) {
|
|
495
|
+
validateFunction(callback, "cb");
|
|
496
|
+
let result;
|
|
497
|
+
try {
|
|
498
|
+
result = fsCall(FS_ACCESS, getValidatedPath(path), F_OK) === undefined;
|
|
499
|
+
} catch {
|
|
500
|
+
return callback(false);
|
|
501
|
+
}
|
|
502
|
+
process.nextTick(() => callback(result));
|
|
80
503
|
}
|
|
81
504
|
|
|
82
505
|
/* ---- stat ------------------------------------------------------------------------- */
|
|
83
506
|
|
|
84
|
-
const S_IFMT = 0o170000, S_IFREG = 0o100000, S_IFDIR = 0o040000
|
|
85
|
-
S_IFSOCK = 0o140000, S_IFCHR = 0o020000, S_IFBLK = 0o060000;
|
|
507
|
+
const S_IFMT = 0o170000, S_IFREG = 0o100000, S_IFDIR = 0o040000;
|
|
86
508
|
|
|
87
|
-
export
|
|
88
|
-
constructor(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs) {
|
|
89
|
-
Object.assign(this, { dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs });
|
|
90
|
-
this.atime = new Date(atimeMs);
|
|
91
|
-
this.mtime = new Date(mtimeMs);
|
|
92
|
-
this.ctime = new Date(ctimeMs);
|
|
93
|
-
this.birthtime = new Date(birthtimeMs);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
isFile() { return (this.mode & S_IFMT) === S_IFREG; }
|
|
97
|
-
isDirectory() { return (this.mode & S_IFMT) === S_IFDIR; }
|
|
98
|
-
isSymbolicLink() { return (this.mode & S_IFMT) === S_IFLNK; }
|
|
99
|
-
isFIFO() { return (this.mode & S_IFMT) === S_IFIFO; }
|
|
100
|
-
isSocket() { return (this.mode & S_IFMT) === S_IFSOCK; }
|
|
101
|
-
isCharacterDevice() { return (this.mode & S_IFMT) === S_IFCHR; }
|
|
102
|
-
isBlockDevice() { return (this.mode & S_IFMT) === S_IFBLK; }
|
|
103
|
-
}
|
|
509
|
+
export { Stats };
|
|
104
510
|
|
|
105
|
-
function
|
|
106
|
-
validatePath(path);
|
|
511
|
+
function doStat(path, follow, syscall, bigint, throwIfNoEntry) {
|
|
107
512
|
const r = fsStat(path, follow);
|
|
108
513
|
if (typeof r === "number") {
|
|
109
|
-
if (
|
|
514
|
+
if (throwIfNoEntry === false && errnoName(r) === "ENOENT") return undefined;
|
|
110
515
|
throw systemError(r, syscall, path);
|
|
111
516
|
}
|
|
112
|
-
|
|
113
|
-
return new Stats(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs);
|
|
517
|
+
return statsFrom(r, bigint);
|
|
114
518
|
}
|
|
115
519
|
|
|
116
|
-
|
|
117
|
-
return
|
|
520
|
+
function doFstat(fd, bigint) {
|
|
521
|
+
return statsFrom(check(fsCall(FS_FSTAT, fd), "fstat"), bigint);
|
|
118
522
|
}
|
|
119
523
|
|
|
120
|
-
export function
|
|
121
|
-
return
|
|
524
|
+
export function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
|
|
525
|
+
return doStat(getValidatedPath(path), true, "stat", options.bigint, options.throwIfNoEntry);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
|
|
529
|
+
return doStat(getValidatedPath(path), false, "lstat", options.bigint, options.throwIfNoEntry);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function fstatSync(fd, options = { bigint: false }) {
|
|
533
|
+
return doFstat(getValidatedFd(fd), options.bigint);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export function stat(path, options = { bigint: false, throwIfNoEntry: true }, callback) {
|
|
537
|
+
if (typeof options === "function") {
|
|
538
|
+
callback = options;
|
|
539
|
+
options = kEmptyObject;
|
|
540
|
+
} else if (options === null || typeof options !== "object") {
|
|
541
|
+
options = kEmptyObject;
|
|
542
|
+
} else {
|
|
543
|
+
options = getOptions(options, { bigint: false });
|
|
544
|
+
}
|
|
545
|
+
callback = makeCallback(callback);
|
|
546
|
+
path = getValidatedPath(path);
|
|
547
|
+
if (checkAborted(options.signal, callback)) return;
|
|
548
|
+
defer(callback, doStat, path, true, "stat", options.bigint, options.throwIfNoEntry);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export function lstat(path, options = { bigint: false }, callback) {
|
|
552
|
+
if (typeof options === "function") {
|
|
553
|
+
callback = options;
|
|
554
|
+
options = kEmptyObject;
|
|
555
|
+
}
|
|
556
|
+
callback = makeCallback(callback);
|
|
557
|
+
defer(callback, doStat, getValidatedPath(path), false, "lstat", options.bigint, true);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export function fstat(fd, options = { bigint: false }, callback) {
|
|
561
|
+
if (typeof options === "function") {
|
|
562
|
+
callback = options;
|
|
563
|
+
options = kEmptyObject;
|
|
564
|
+
}
|
|
565
|
+
callback = makeCallback(callback);
|
|
566
|
+
defer(callback, doFstat, getValidatedFd(fd), options.bigint);
|
|
122
567
|
}
|
|
123
568
|
|
|
124
569
|
/* ---- readdir ---------------------------------------------------------------------- */
|
|
@@ -132,7 +577,6 @@ export class Dirent {
|
|
|
132
577
|
constructor(name, type, path) {
|
|
133
578
|
this.name = name;
|
|
134
579
|
this.parentPath = path;
|
|
135
|
-
this.path = path;
|
|
136
580
|
this[kType] = type;
|
|
137
581
|
}
|
|
138
582
|
|
|
@@ -145,107 +589,650 @@ export class Dirent {
|
|
|
145
589
|
isBlockDevice() { return this[kType] === UV_DIRENT_BLOCK; }
|
|
146
590
|
}
|
|
147
591
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (options?.recursive) throw notSupported("readdir's recursive option");
|
|
151
|
-
const encoding = encodingOf(options);
|
|
152
|
-
validateEncodingName(encoding);
|
|
153
|
-
const r = check(fsReaddir(path), "scandir", path);
|
|
154
|
-
const names = [], types = [];
|
|
155
|
-
for (let i = 0; i < r.length; i += 2) {
|
|
156
|
-
names.push(r[i]);
|
|
157
|
-
types.push(r[i + 1]);
|
|
158
|
-
}
|
|
592
|
+
function doReaddir(path, options) {
|
|
593
|
+
const encoding = options.encoding;
|
|
159
594
|
/* in libuv's order, as Node's (it lists them through libuv too) */
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
595
|
+
const list = (dir) => {
|
|
596
|
+
const r = check(fsReaddir(dir), "scandir", dir);
|
|
597
|
+
const entries = [];
|
|
598
|
+
for (let i = 0; i < r.length; i += 2) entries.push([r[i], r[i + 1]]);
|
|
599
|
+
return entries;
|
|
600
|
+
};
|
|
601
|
+
if (!options.recursive) {
|
|
602
|
+
if (options.withFileTypes) return list(path).map(([name, type]) => new Dirent(encoded(name, encoding), type, path));
|
|
603
|
+
return list(path).map(([name]) => encoded(name, encoding));
|
|
604
|
+
}
|
|
605
|
+
/* Node's readdirSyncRecursive: each directory's entries, then the directories found, in turn;
|
|
606
|
+
* names relative to path. It goes into what stat (following links) says is a directory */
|
|
607
|
+
const results = [];
|
|
608
|
+
const queue = [[path, ""]];
|
|
609
|
+
for (let i = 0; i < queue.length; i++) {
|
|
610
|
+
const [dir, relative] = queue[i];
|
|
611
|
+
for (const [name, type] of list(dir)) {
|
|
612
|
+
const full = dir.endsWith("/") ? dir + name : dir + "/" + name;
|
|
613
|
+
const rel = relative ? relative + "/" + name : name;
|
|
614
|
+
results.push(options.withFileTypes ? new Dirent(encoded(name, encoding), type, dir) : encoded(rel, encoding));
|
|
615
|
+
const st = type === UV_DIRENT_DIR ? null : type === UV_DIRENT_LINK || type === 0 ? fsStat(full, true) : undefined;
|
|
616
|
+
if (st === null || (Array.isArray(st) && (st[0] & S_IFMT) === S_IFDIR)) queue.push([full, rel]);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return results;
|
|
163
620
|
}
|
|
164
621
|
|
|
165
|
-
|
|
622
|
+
function readdirOptions(options) {
|
|
623
|
+
options = getOptions(options);
|
|
624
|
+
if (options.recursive != null) validateBoolean(options.recursive, "options.recursive");
|
|
625
|
+
return options;
|
|
626
|
+
}
|
|
166
627
|
|
|
167
|
-
function
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
628
|
+
export function readdirSync(path, options) {
|
|
629
|
+
options = readdirOptions(options);
|
|
630
|
+
return doReaddir(getValidatedPath(path), options);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export function readdir(path, options, callback) {
|
|
634
|
+
callback = makeCallback(typeof options === "function" ? options : callback);
|
|
635
|
+
options = readdirOptions(options);
|
|
636
|
+
defer(callback, doReaddir, getValidatedPath(path), options);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/* ---- realpath, mkdir, mkdtemp ------------------------------------------------------- */
|
|
640
|
+
|
|
641
|
+
/** The canonical path. Node's own realpathSync walks the path with lstat, so its errors name the
|
|
642
|
+
* lstat of the first missing part, absolute; realpathSync.native's name the realpath call. */
|
|
643
|
+
function doRealpath(path, encoding) {
|
|
644
|
+
const r = fsRealpath(path);
|
|
645
|
+
if (typeof r === "number") {
|
|
646
|
+
const parts = resolve(path).split("/");
|
|
647
|
+
for (let i = 2; i <= parts.length; i++) {
|
|
648
|
+
const prefix = parts.slice(0, i).join("/");
|
|
649
|
+
const st = fsStat(prefix, false);
|
|
650
|
+
if (typeof st === "number") throw systemError(st, "lstat", prefix);
|
|
651
|
+
}
|
|
652
|
+
throw systemError(r, "realpath", path);
|
|
174
653
|
}
|
|
175
|
-
|
|
654
|
+
return encoded(r, encoding);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function doRealpathNative(path, encoding) {
|
|
658
|
+
return encoded(check(fsRealpath(path), "realpath", path), encoding);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export function realpathSync(path, options) {
|
|
662
|
+
options = getOptions(options);
|
|
663
|
+
return doRealpath(getValidatedPath(path), options.encoding);
|
|
176
664
|
}
|
|
177
665
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
666
|
+
realpathSync.native = function realpathSync(path, options) {
|
|
667
|
+
options = getOptions(options);
|
|
668
|
+
return doRealpathNative(getValidatedPath(path), options.encoding);
|
|
181
669
|
};
|
|
182
670
|
|
|
183
|
-
export
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
671
|
+
export function realpath(path, options, callback) {
|
|
672
|
+
if (typeof options === "function") callback = options;
|
|
673
|
+
else validateFunction(callback, "cb");
|
|
674
|
+
options = getOptions(options);
|
|
675
|
+
defer(callback, doRealpath, getValidatedPath(path), options.encoding);
|
|
676
|
+
}
|
|
187
677
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
678
|
+
realpath.native = function realpath(path, options, callback) {
|
|
679
|
+
callback = makeCallback(typeof options === "function" ? options : callback);
|
|
680
|
+
options = getOptions(options);
|
|
681
|
+
defer(callback, doRealpathNative, getValidatedPath(path), options.encoding);
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
/** Creates the directory; with `recursive`, its missing parents too, returning the first one
|
|
685
|
+
* created (undefined if it all existed). */
|
|
686
|
+
function doMkdir(path, mode, recursive) {
|
|
687
|
+
if (!recursive) {
|
|
688
|
+
check(fsMkdir(path, mode), "mkdir", path);
|
|
689
|
+
return undefined;
|
|
690
|
+
}
|
|
691
|
+
const missing = [];
|
|
692
|
+
for (let p = path; ; p = dirname(p)) {
|
|
693
|
+
const st = fsStat(p, true);
|
|
694
|
+
if (typeof st !== "number") {
|
|
695
|
+
/* a file where a directory goes: the OS's error (EEXIST for the path itself, else ENOTDIR) */
|
|
696
|
+
if ((st[0] & S_IFMT) !== S_IFDIR) throw systemError(fsMkdir(path, mode), "mkdir", path);
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
missing.push(p);
|
|
700
|
+
if (dirname(p) === p) break;
|
|
701
|
+
}
|
|
702
|
+
for (let i = missing.length - 1; i >= 0; i--) {
|
|
703
|
+
const r = fsMkdir(missing[i], mode);
|
|
704
|
+
if (typeof r === "number" && errnoName(r) !== "EEXIST") throw systemError(r, "mkdir", path);
|
|
705
|
+
}
|
|
706
|
+
return missing.length ? missing[missing.length - 1] : undefined;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/* mkdir's options: [mode, recursive] */
|
|
710
|
+
function mkdirOptions(options) {
|
|
711
|
+
let mode = 0o777;
|
|
712
|
+
let recursive = false;
|
|
713
|
+
if (typeof options === "number" || typeof options === "string") {
|
|
714
|
+
mode = parseFileMode(options, "mode");
|
|
715
|
+
} else if (options) {
|
|
716
|
+
if (options.recursive !== undefined) {
|
|
717
|
+
recursive = options.recursive;
|
|
718
|
+
validateBoolean(recursive, "options.recursive");
|
|
719
|
+
}
|
|
720
|
+
if (options.mode !== undefined) mode = parseFileMode(options.mode, "options.mode");
|
|
721
|
+
}
|
|
722
|
+
return [mode, recursive];
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export function mkdirSync(path, options) {
|
|
726
|
+
const [mode, recursive] = mkdirOptions(options);
|
|
727
|
+
return doMkdir(getValidatedPath(path), mode, recursive);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
export function mkdir(path, options, callback) {
|
|
731
|
+
const [mode, recursive] = typeof options === "function" ? [0o777, false] : mkdirOptions(options);
|
|
732
|
+
if (typeof options === "function") callback = options;
|
|
733
|
+
callback = makeCallback(callback);
|
|
734
|
+
defer(callback, doMkdir, getValidatedPath(path), mode, recursive);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** A new directory named `prefix` and six random characters: its path. */
|
|
738
|
+
function doMkdtemp(prefix, encoding) {
|
|
739
|
+
const template = prefix + "XXXXXX";
|
|
740
|
+
return encoded(check(fsCall(FS_MKDTEMP, template), "mkdtemp", template), encoding);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
export function mkdtempSync(prefix, options) {
|
|
744
|
+
options = getOptions(options);
|
|
745
|
+
prefix = getValidatedPath(prefix, "prefix");
|
|
746
|
+
warnOnNonPortableTemplate(prefix);
|
|
747
|
+
return doMkdtemp(prefix, options.encoding);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
export function mkdtemp(prefix, options, callback) {
|
|
751
|
+
callback = makeCallback(typeof options === "function" ? options : callback);
|
|
752
|
+
options = getOptions(options);
|
|
753
|
+
prefix = getValidatedPath(prefix, "prefix");
|
|
754
|
+
warnOnNonPortableTemplate(prefix);
|
|
755
|
+
defer(callback, doMkdtemp, prefix, options.encoding);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/** mkdtempSync's directory with a way to remove it, and what it holds: remove(), or a `using`
|
|
759
|
+
* declaration (Symbol.dispose). */
|
|
760
|
+
export function mkdtempDisposableSync(prefix, options) {
|
|
761
|
+
const path = mkdtempSync(prefix, options);
|
|
762
|
+
const fullPath = resolve(process.cwd(), `${path}`);
|
|
763
|
+
const remove = () => removeTree(fullPath, true);
|
|
764
|
+
return { path, remove, [Symbol.dispose]() { remove(); } };
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/* ---- utimes ------------------------------------------------------------------------- */
|
|
768
|
+
|
|
769
|
+
function doUtimes(path, atime, mtime) {
|
|
770
|
+
check(fsUtimes(path, atime, mtime), "utime", path);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function doFutimes(fd, atime, mtime) {
|
|
774
|
+
check(fsCall(FS_FUTIME, fd, atime, mtime), "futime");
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function doLutimes(path, atime, mtime) {
|
|
778
|
+
check(fsCall(FS_LUTIME, path, atime, mtime), "lutime", path);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
export function utimesSync(path, atime, mtime) {
|
|
782
|
+
doUtimes(getValidatedPath(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
export function utimes(path, atime, mtime, callback) {
|
|
786
|
+
callback = makeCallback(callback);
|
|
787
|
+
path = getValidatedPath(path);
|
|
788
|
+
defer(callback, doUtimes, path, toUnixTimestamp(atime), toUnixTimestamp(mtime));
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
export function futimesSync(fd, atime, mtime) {
|
|
792
|
+
doFutimes(getValidatedFd(fd), toUnixTimestamp(atime, "atime"), toUnixTimestamp(mtime, "mtime"));
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
export function futimes(fd, atime, mtime, callback) {
|
|
796
|
+
atime = toUnixTimestamp(atime, "atime");
|
|
797
|
+
mtime = toUnixTimestamp(mtime, "mtime");
|
|
798
|
+
callback = makeCallback(callback);
|
|
799
|
+
defer(callback, doFutimes, getValidatedFd(fd), atime, mtime);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
export function lutimesSync(path, atime, mtime) {
|
|
803
|
+
doLutimes(getValidatedPath(path), toUnixTimestamp(atime), toUnixTimestamp(mtime));
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export function lutimes(path, atime, mtime, callback) {
|
|
807
|
+
callback = makeCallback(callback);
|
|
808
|
+
path = getValidatedPath(path);
|
|
809
|
+
defer(callback, doLutimes, path, toUnixTimestamp(atime), toUnixTimestamp(mtime));
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/* ---- the other system calls, through fsCall ------------------------------------------ */
|
|
813
|
+
|
|
814
|
+
/* fsCall's operations (host_fs.c) */
|
|
815
|
+
const FS_RENAME = 0, FS_LINK = 1, FS_SYMLINK = 2, FS_READLINK = 3, FS_RMDIR = 4, FS_CHMOD = 5, FS_FCHMOD = 6, FS_CHOWN = 7,
|
|
816
|
+
FS_FCHOWN = 8, FS_LCHOWN = 9, FS_FSYNC = 10, FS_FDATASYNC = 11, FS_FTRUNCATE = 12, FS_FUTIME = 13, FS_LUTIME = 14,
|
|
817
|
+
FS_COPYFILE = 15, FS_MKDTEMP = 16, FS_ACCESS = 17, FS_FSTAT = 18;
|
|
818
|
+
|
|
819
|
+
/* a call naming a path (`chmod 'a'`), or a descriptor, its error naming the call alone */
|
|
820
|
+
function pathCall(op, syscall, path, a, b) {
|
|
821
|
+
check(fsCall(op, path, a, b), syscall, path);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function fdCall(op, syscall, fd, a, b) {
|
|
825
|
+
check(fsCall(op, fd, a, b), syscall);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/* a call naming two paths: its error names both (`rename 'a' -> 'b'`) */
|
|
829
|
+
function twoPaths(op, syscall, from, to, extra) {
|
|
830
|
+
const r = fsCall(op, from, to, extra);
|
|
831
|
+
if (typeof r === "number") throw systemError(r, syscall, from, to);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
export function renameSync(oldPath, newPath) {
|
|
835
|
+
twoPaths(FS_RENAME, "rename", getValidatedPath(oldPath, "oldPath"), getValidatedPath(newPath, "newPath"));
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
export function rename(oldPath, newPath, callback) {
|
|
839
|
+
callback = makeCallback(callback);
|
|
840
|
+
defer(callback, twoPaths, FS_RENAME, "rename", getValidatedPath(oldPath, "oldPath"), getValidatedPath(newPath, "newPath"));
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
export function linkSync(existingPath, newPath) {
|
|
844
|
+
twoPaths(FS_LINK, "link", getValidatedPath(existingPath, "existingPath"), getValidatedPath(newPath, "newPath"));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
export function link(existingPath, newPath, callback) {
|
|
848
|
+
callback = makeCallback(callback);
|
|
849
|
+
defer(callback, twoPaths, FS_LINK, "link", getValidatedPath(existingPath, "existingPath"), getValidatedPath(newPath, "newPath"));
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/* type "dir" or "junction" matters on Windows only, as in Node */
|
|
853
|
+
const symlinkType = (type) => (type === "dir" ? 1 : type === "junction" ? 2 : 0);
|
|
854
|
+
|
|
855
|
+
export function symlinkSync(target, path, type) {
|
|
856
|
+
validateOneOf(type, "type", ["dir", "file", "junction", null, undefined]);
|
|
857
|
+
twoPaths(FS_SYMLINK, "symlink", getValidatedPath(target, "target"), getValidatedPath(path), symlinkType(type));
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export function symlink(target, path, type, callback) {
|
|
861
|
+
if (callback === undefined) {
|
|
862
|
+
callback = makeCallback(type);
|
|
863
|
+
type = undefined;
|
|
864
|
+
} else {
|
|
865
|
+
validateOneOf(type, "type", ["dir", "file", "junction", null, undefined]);
|
|
866
|
+
}
|
|
867
|
+
defer(callback, twoPaths, FS_SYMLINK, "symlink", getValidatedPath(target, "target"), getValidatedPath(path), symlinkType(type));
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function doReadlink(path, encoding) {
|
|
871
|
+
return encoded(check(fsCall(FS_READLINK, path), "readlink", path), encoding);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
export function readlinkSync(path, options) {
|
|
875
|
+
options = getOptions(options);
|
|
876
|
+
return doReadlink(getValidatedPath(path), options.encoding);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
export function readlink(path, options, callback) {
|
|
880
|
+
callback = makeCallback(typeof options === "function" ? options : callback);
|
|
881
|
+
options = getOptions(options);
|
|
882
|
+
defer(callback, doReadlink, getValidatedPath(path), options.encoding);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
export function unlinkSync(path) {
|
|
886
|
+
path = getValidatedPath(path);
|
|
887
|
+
check(fsUnlink(path), "unlink", path);
|
|
191
888
|
}
|
|
192
889
|
|
|
193
890
|
export function unlink(path, callback) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.path = path;
|
|
207
|
-
this.start = options.start;
|
|
208
|
-
this.end = options.end ?? Infinity;
|
|
209
|
-
this.pos = options.start ?? 0;
|
|
210
|
-
this.bytesRead = 0;
|
|
211
|
-
this.pending = true;
|
|
212
|
-
/* opened on the next tick, as Node's: a missing file is an error even if nothing reads */
|
|
213
|
-
process.nextTick(() => {
|
|
214
|
-
const r = fsStat(path, true);
|
|
215
|
-
if (typeof r === "number") return this.destroy(systemError(r, "open", path));
|
|
216
|
-
this.pending = false;
|
|
217
|
-
this.emit("open");
|
|
218
|
-
this.emit("ready");
|
|
219
|
-
});
|
|
891
|
+
callback = makeCallback(callback);
|
|
892
|
+
defer(callback, unlinkSync, getValidatedPath(path));
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
export function copyFileSync(src, dest, mode) {
|
|
896
|
+
twoPaths(FS_COPYFILE, "copyfile", getValidatedPath(src, "src"), getValidatedPath(dest, "dest"), getValidMode(mode, "copyFile"));
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
export function copyFile(src, dest, mode, callback) {
|
|
900
|
+
if (typeof mode === "function") {
|
|
901
|
+
callback = mode;
|
|
902
|
+
mode = 0;
|
|
220
903
|
}
|
|
904
|
+
src = getValidatedPath(src, "src");
|
|
905
|
+
dest = getValidatedPath(dest, "dest");
|
|
906
|
+
callback = makeCallback(callback);
|
|
907
|
+
defer(callback, twoPaths, FS_COPYFILE, "copyfile", src, dest, getValidMode(mode, "copyFile"));
|
|
908
|
+
}
|
|
221
909
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.push(chunk);
|
|
233
|
-
});
|
|
910
|
+
const F_OK = 0;
|
|
911
|
+
|
|
912
|
+
export function accessSync(path, mode) {
|
|
913
|
+
pathCall(FS_ACCESS, "access", getValidatedPath(path), getValidMode(mode, "access"));
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
export function access(path, mode, callback) {
|
|
917
|
+
if (typeof mode === "function") {
|
|
918
|
+
callback = mode;
|
|
919
|
+
mode = F_OK;
|
|
234
920
|
}
|
|
921
|
+
path = getValidatedPath(path);
|
|
922
|
+
callback = makeCallback(callback);
|
|
923
|
+
defer(callback, pathCall, FS_ACCESS, "access", path, getValidMode(mode, "access"));
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
export function chmodSync(path, mode) {
|
|
927
|
+
pathCall(FS_CHMOD, "chmod", getValidatedPath(path), parseFileMode(mode, "mode"));
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
export function chmod(path, mode, callback) {
|
|
931
|
+
path = getValidatedPath(path);
|
|
932
|
+
mode = parseFileMode(mode, "mode");
|
|
933
|
+
callback = makeCallback(callback);
|
|
934
|
+
defer(callback, pathCall, FS_CHMOD, "chmod", path, mode);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
export function fchmodSync(fd, mode) {
|
|
938
|
+
fdCall(FS_FCHMOD, "fchmod", getValidatedFd(fd), parseFileMode(mode, "mode"));
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
export function fchmod(fd, mode, callback) {
|
|
942
|
+
mode = parseFileMode(mode, "mode");
|
|
943
|
+
callback = makeCallback(callback);
|
|
944
|
+
defer(callback, fdCall, FS_FCHMOD, "fchmod", getValidatedFd(fd), mode);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function validateIds(uid, gid) {
|
|
948
|
+
validateInteger(uid, "uid", -1, kMaxUserId);
|
|
949
|
+
validateInteger(gid, "gid", -1, kMaxUserId);
|
|
235
950
|
}
|
|
236
951
|
|
|
952
|
+
export function chownSync(path, uid, gid) {
|
|
953
|
+
path = getValidatedPath(path);
|
|
954
|
+
validateIds(uid, gid);
|
|
955
|
+
pathCall(FS_CHOWN, "chown", path, uid, gid);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
export function chown(path, uid, gid, callback) {
|
|
959
|
+
callback = makeCallback(callback);
|
|
960
|
+
path = getValidatedPath(path);
|
|
961
|
+
validateIds(uid, gid);
|
|
962
|
+
defer(callback, pathCall, FS_CHOWN, "chown", path, uid, gid);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
export function lchownSync(path, uid, gid) {
|
|
966
|
+
path = getValidatedPath(path);
|
|
967
|
+
validateIds(uid, gid);
|
|
968
|
+
pathCall(FS_LCHOWN, "lchown", path, uid, gid);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
export function lchown(path, uid, gid, callback) {
|
|
972
|
+
callback = makeCallback(callback);
|
|
973
|
+
path = getValidatedPath(path);
|
|
974
|
+
validateIds(uid, gid);
|
|
975
|
+
defer(callback, pathCall, FS_LCHOWN, "lchown", path, uid, gid);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
export function fchownSync(fd, uid, gid) {
|
|
979
|
+
validateIds(uid, gid);
|
|
980
|
+
fdCall(FS_FCHOWN, "fchown", getValidatedFd(fd), uid, gid);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
export function fchown(fd, uid, gid, callback) {
|
|
984
|
+
validateIds(uid, gid);
|
|
985
|
+
callback = makeCallback(callback);
|
|
986
|
+
defer(callback, fdCall, FS_FCHOWN, "fchown", getValidatedFd(fd), uid, gid);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
export function fsyncSync(fd) {
|
|
990
|
+
fdCall(FS_FSYNC, "fsync", getValidatedFd(fd));
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
export function fsync(fd, callback) {
|
|
994
|
+
callback = makeCallback(callback);
|
|
995
|
+
defer(callback, fdCall, FS_FSYNC, "fsync", getValidatedFd(fd));
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export function fdatasyncSync(fd) {
|
|
999
|
+
fdCall(FS_FDATASYNC, "fdatasync", getValidatedFd(fd));
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
export function fdatasync(fd, callback) {
|
|
1003
|
+
callback = makeCallback(callback);
|
|
1004
|
+
defer(callback, fdCall, FS_FDATASYNC, "fdatasync", getValidatedFd(fd));
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
export function ftruncateSync(fd, len = 0) {
|
|
1008
|
+
validateInteger(len, "len");
|
|
1009
|
+
fdCall(FS_FTRUNCATE, "ftruncate", getValidatedFd(fd), len < 0 ? 0 : len);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
export function ftruncate(fd, len = 0, callback) {
|
|
1013
|
+
if (typeof len === "function") {
|
|
1014
|
+
callback = len;
|
|
1015
|
+
len = 0;
|
|
1016
|
+
}
|
|
1017
|
+
validateInteger(len, "len");
|
|
1018
|
+
len = Math.max(0, len);
|
|
1019
|
+
callback = makeCallback(callback);
|
|
1020
|
+
defer(callback, fdCall, FS_FTRUNCATE, "ftruncate", getValidatedFd(fd), len);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/** As Node's: the file opened for writing, truncated, closed. */
|
|
1024
|
+
function doTruncate(path, len) {
|
|
1025
|
+
const fd = doOpen(path, O_RDWR, 0o666);
|
|
1026
|
+
try {
|
|
1027
|
+
fdCall(FS_FTRUNCATE, "ftruncate", fd, len);
|
|
1028
|
+
} finally {
|
|
1029
|
+
doClose(fd);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
export function truncateSync(path, len) {
|
|
1034
|
+
if (len === undefined) len = 0;
|
|
1035
|
+
const fd = openSync(path, "r+");
|
|
1036
|
+
try {
|
|
1037
|
+
ftruncateSync(fd, len);
|
|
1038
|
+
} finally {
|
|
1039
|
+
closeSync(fd);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
export function truncate(path, len, callback) {
|
|
1044
|
+
if (typeof len === "function") {
|
|
1045
|
+
callback = len;
|
|
1046
|
+
len = 0;
|
|
1047
|
+
} else if (len === undefined) {
|
|
1048
|
+
len = 0;
|
|
1049
|
+
}
|
|
1050
|
+
validateInteger(len, "len");
|
|
1051
|
+
len = Math.max(0, len);
|
|
1052
|
+
validateFunction(callback, "cb");
|
|
1053
|
+
defer(callback, doTruncate, getValidatedPath(path), len);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/* ---- rmdir, rm ------------------------------------------------------------------------- */
|
|
1057
|
+
|
|
1058
|
+
function removeTree(path, force) {
|
|
1059
|
+
const st = fsStat(path, false);
|
|
1060
|
+
if (typeof st === "number") {
|
|
1061
|
+
if (force && errnoName(st) === "ENOENT") return;
|
|
1062
|
+
throw systemError(st, "lstat", path);
|
|
1063
|
+
}
|
|
1064
|
+
if ((st[0] & S_IFMT) === S_IFDIR) {
|
|
1065
|
+
const entries = check(fsReaddir(path), "scandir", path);
|
|
1066
|
+
for (let i = 0; i < entries.length; i += 2) removeTree(path + "/" + entries[i], false);
|
|
1067
|
+
check(fsCall(FS_RMDIR, path), "rmdir", path);
|
|
1068
|
+
} else {
|
|
1069
|
+
check(fsUnlink(path), "rm", path);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
/* rm's work, its options checked: a file, or with `recursive` a directory and what it holds;
|
|
1074
|
+
* `force` ignores a missing path. A directory without `recursive` is ERR_FS_EISDIR, as in Node. */
|
|
1075
|
+
function doRm(path, options) {
|
|
1076
|
+
const st = fsStat(path, false);
|
|
1077
|
+
if (typeof st === "number") {
|
|
1078
|
+
if (options.force && errnoName(st) === "ENOENT") return;
|
|
1079
|
+
throw systemError(st, "lstat", path);
|
|
1080
|
+
}
|
|
1081
|
+
if ((st[0] & S_IFMT) === S_IFDIR) {
|
|
1082
|
+
if (!options.recursive) throw rmIsDirectory(path);
|
|
1083
|
+
return removeTree(path, options.force);
|
|
1084
|
+
}
|
|
1085
|
+
check(fsUnlink(path), "rm", path);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/* rmdir's work: with `recursive` (deprecated), a directory removed as rm removes it; what isn't a
|
|
1089
|
+
* directory left to rmdir's ENOTDIR, as Node's */
|
|
1090
|
+
function doRmdir(path, recursive) {
|
|
1091
|
+
if (recursive) {
|
|
1092
|
+
const st = check(fsStat(path, false), "lstat", path);
|
|
1093
|
+
if ((st[0] & S_IFMT) === S_IFDIR) return removeTree(path, false);
|
|
1094
|
+
}
|
|
1095
|
+
check(fsCall(FS_RMDIR, path), "rmdir", path);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
export function rmdirSync(path, options) {
|
|
1099
|
+
path = getValidatedPath(path);
|
|
1100
|
+
if (options?.recursive) {
|
|
1101
|
+
emitRecursiveRmdirWarning();
|
|
1102
|
+
validateRmOptionsShape({ ...options, force: false });
|
|
1103
|
+
} else {
|
|
1104
|
+
validateRmdirOptions(options);
|
|
1105
|
+
}
|
|
1106
|
+
doRmdir(path, !!options?.recursive);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
export function rmdir(path, options, callback) {
|
|
1110
|
+
if (typeof options === "function") {
|
|
1111
|
+
callback = options;
|
|
1112
|
+
options = undefined;
|
|
1113
|
+
}
|
|
1114
|
+
callback = makeCallback(callback);
|
|
1115
|
+
path = getValidatedPath(path);
|
|
1116
|
+
if (options?.recursive) {
|
|
1117
|
+
emitRecursiveRmdirWarning();
|
|
1118
|
+
validateRmOptionsShape({ ...options, force: false });
|
|
1119
|
+
} else {
|
|
1120
|
+
validateRmdirOptions(options);
|
|
1121
|
+
}
|
|
1122
|
+
defer(callback, doRmdir, path, !!options?.recursive);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
export function rmSync(path, options) {
|
|
1126
|
+
path = getValidatedPath(path);
|
|
1127
|
+
doRm(path, validateRmOptionsShape(options));
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
export function rm(path, options, callback) {
|
|
1131
|
+
if (typeof options === "function") {
|
|
1132
|
+
callback = options;
|
|
1133
|
+
options = undefined;
|
|
1134
|
+
}
|
|
1135
|
+
path = getValidatedPath(path);
|
|
1136
|
+
options = validateRmOptionsShape(options);
|
|
1137
|
+
validateFunction(callback, "cb");
|
|
1138
|
+
defer(callback, doRm, path, options);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/* ---- streams: Node's, in a module of their own (internal/fs_streams.js) ------------------- */
|
|
1142
|
+
|
|
1143
|
+
export const ReadStream = lazyConstructor("ReadStream", 2);
|
|
1144
|
+
export const WriteStream = lazyConstructor("WriteStream", 2);
|
|
1145
|
+
|
|
237
1146
|
export function createReadStream(path, options) {
|
|
238
1147
|
return new ReadStream(path, options);
|
|
239
1148
|
}
|
|
240
1149
|
|
|
1150
|
+
export function createWriteStream(path, options) {
|
|
1151
|
+
return new WriteStream(path, options);
|
|
1152
|
+
}
|
|
1153
|
+
|
|
241
1154
|
/* node:fs/promises, which imports this module: read when used, not while the modules load */
|
|
242
1155
|
export { default as promises } from "./fs_promises.js";
|
|
243
1156
|
import promises from "./fs_promises.js";
|
|
244
1157
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
1158
|
+
/* ---- util.promisify's results ------------------------------------------------------------ */
|
|
1159
|
+
|
|
1160
|
+
/* the callback's values as an object's (node:util's symbol); exists' promise, of a boolean */
|
|
1161
|
+
const kCustomPromisifyArgs = Symbol.for("visaljs.util.customPromisifyArgs");
|
|
1162
|
+
Object.defineProperty(read, kCustomPromisifyArgs, { value: ["bytesRead", "buffer"], enumerable: false });
|
|
1163
|
+
Object.defineProperty(write, kCustomPromisifyArgs, { value: ["bytesWritten", "buffer"], enumerable: false });
|
|
1164
|
+
Object.defineProperty(readv, kCustomPromisifyArgs, { value: ["bytesRead", "buffers"], enumerable: false });
|
|
1165
|
+
Object.defineProperty(writev, kCustomPromisifyArgs, { value: ["bytesWritten", "buffers"], enumerable: false });
|
|
1166
|
+
Object.defineProperty(exists, Symbol.for("nodejs.util.promisify.custom"), {
|
|
1167
|
+
value: function exists(path) {
|
|
1168
|
+
return new Promise((resolve) => fs.exists(path, resolve));
|
|
1169
|
+
},
|
|
1170
|
+
enumerable: false,
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
/* ---- the features in modules of their own ------------------------------------------------- */
|
|
1174
|
+
|
|
1175
|
+
/* their own modules, linked when the program names them (internal/features.js) */
|
|
1176
|
+
export const statfsSync = lazyFunction("statfsSync", 2);
|
|
1177
|
+
export const statfs = lazyFunction("statfs", 3);
|
|
1178
|
+
export const Dir = lazyClass("Dir");
|
|
1179
|
+
export const opendirSync = lazyFunction("opendirSync", 2);
|
|
1180
|
+
export const opendir = lazyFunction("opendir", 3);
|
|
1181
|
+
export const cpSync = lazyFunction("cpSync", 3);
|
|
1182
|
+
export const cp = lazyFunction("cp", 4);
|
|
1183
|
+
export const globSync = lazyFunction("globSync", 2);
|
|
1184
|
+
export const glob = lazyFunction("glob", 3);
|
|
1185
|
+
export const watch = lazyFunction("watch", 3);
|
|
1186
|
+
export const watchFile = lazyFunction("watchFile", 3);
|
|
1187
|
+
export const unwatchFile = lazyFunction("unwatchFile", 2);
|
|
1188
|
+
export const openAsBlob = lazyFunction("openAsBlob", 2);
|
|
1189
|
+
|
|
1190
|
+
/* lchmod: macOS's only (O_SYMLINK), as Node's */
|
|
1191
|
+
export const lchmod = undefined;
|
|
1192
|
+
export const lchmodSync = undefined;
|
|
1193
|
+
|
|
1194
|
+
/* the names Node keeps for its streams */
|
|
1195
|
+
export const FileReadStream = ReadStream;
|
|
1196
|
+
export const FileWriteStream = WriteStream;
|
|
1197
|
+
|
|
1198
|
+
/* the platform's (libuv's, then the C library's), in Node's order */
|
|
1199
|
+
export const constants = { __proto__: null };
|
|
1200
|
+
{
|
|
1201
|
+
const flat = fsConstants();
|
|
1202
|
+
for (let i = 0; i < flat.length; i += 2) constants[flat[i]] = flat[i + 1];
|
|
1203
|
+
}
|
|
1204
|
+
const { O_RDONLY, O_RDWR } = constants;
|
|
1205
|
+
|
|
1206
|
+
const fs = {
|
|
1207
|
+
constants, readFileSync, writeFileSync, appendFileSync, existsSync, unlinkSync, statSync, lstatSync, readdirSync, readFile, writeFile,
|
|
1208
|
+
unlink, stat, lstat, readdir, createReadStream, ReadStream, Stats, Dirent, realpathSync, realpath, mkdirSync, mkdir, utimesSync,
|
|
1209
|
+
utimes, openSync, open, closeSync, close, writeSync, readSync, read, write, appendFile, exists, createWriteStream, WriteStream,
|
|
1210
|
+
renameSync, rename, linkSync, link, symlinkSync, symlink, readlinkSync, readlink, copyFileSync, copyFile, accessSync, access,
|
|
1211
|
+
chmodSync, chmod, fchmodSync, fchmod, lchmod, lchmodSync, chownSync, chown, lchownSync, lchown, fchownSync, fchown, fstatSync, fstat,
|
|
1212
|
+
fsyncSync, fsync, fdatasyncSync, fdatasync, ftruncateSync, ftruncate, truncateSync, truncate, futimesSync, futimes, lutimesSync,
|
|
1213
|
+
lutimes, mkdtempSync, mkdtemp, mkdtempDisposableSync, rmdirSync, rmdir, rmSync, rm, readvSync, readv, writevSync, writev, statfsSync,
|
|
1214
|
+
statfs, Dir, opendirSync, opendir, cpSync, cp, globSync, glob, watch, watchFile, unwatchFile, openAsBlob, FileReadStream,
|
|
1215
|
+
FileWriteStream, _toUnixTimestamp: toUnixTimestamp,
|
|
248
1216
|
get promises() {
|
|
249
1217
|
return promises;
|
|
250
1218
|
},
|
|
251
1219
|
};
|
|
1220
|
+
|
|
1221
|
+
/* access()'s modes on fs itself: hidden, deprecated getters in Node 24 (DEP0176), warning once,
|
|
1222
|
+
* without a setter */
|
|
1223
|
+
let warnedModes = false;
|
|
1224
|
+
for (const [name, value] of [["F_OK", 0], ["R_OK", 4], ["W_OK", 2], ["X_OK", 1]]) {
|
|
1225
|
+
Object.defineProperty(fs, name, {
|
|
1226
|
+
enumerable: false,
|
|
1227
|
+
configurable: true,
|
|
1228
|
+
get() {
|
|
1229
|
+
if (!warnedModes) {
|
|
1230
|
+
warnedModes = true;
|
|
1231
|
+
process.emitWarning(`fs.${name} is deprecated, use fs.constants.${name} instead`, "DeprecationWarning", "DEP0176");
|
|
1232
|
+
}
|
|
1233
|
+
return value;
|
|
1234
|
+
},
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
export default fs;
|