diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-01-11 07:37:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 15:37:25 -0700 |
commit | 515a34b4de222e35c7ade1b92614d746e73d4c2e (patch) | |
tree | 8284201fc826a33f12597959a8a8be14e0f524bd /ext/fs/30_fs.js | |
parent | d4893eb51a01c5a692d8ca74a3b8ff95c5fd1d9f (diff) |
refactor: use `core.ensureFastOps()` (#21888)
Diffstat (limited to 'ext/fs/30_fs.js')
-rw-r--r-- | ext/fs/30_fs.js | 122 |
1 files changed, 78 insertions, 44 deletions
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 3b4392006..277a1c73c 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -1,39 +1,75 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { core, primordials } from "ext:core/mod.js"; -const ops = core.ops; const { + isDate, +} = core; +const { + op_fs_chdir, op_fs_chmod_async, - op_fs_ftruncate_async, - op_fs_truncate_async, - op_fs_link_async, - op_fs_flock_async, + op_fs_chmod_sync, op_fs_chown_async, + op_fs_chown_sync, op_fs_copy_file_async, + op_fs_copy_file_sync, + op_fs_cwd, op_fs_fdatasync_async, + op_fs_fdatasync_sync, + op_fs_flock_async, + op_fs_flock_sync, op_fs_fstat_async, + op_fs_fstat_sync, op_fs_fsync_async, + op_fs_fsync_sync, + op_fs_ftruncate_async, + op_fs_ftruncate_sync, op_fs_funlock_async, + op_fs_funlock_sync, op_fs_futime_async, + op_fs_futime_sync, + op_fs_link_async, + op_fs_link_sync, op_fs_lstat_async, + op_fs_lstat_sync, op_fs_make_temp_dir_async, + op_fs_make_temp_dir_sync, op_fs_make_temp_file_async, + op_fs_make_temp_file_sync, op_fs_mkdir_async, + op_fs_mkdir_sync, op_fs_open_async, + op_fs_open_sync, op_fs_read_dir_async, + op_fs_read_dir_sync, op_fs_read_file_async, + op_fs_read_file_sync, op_fs_read_file_text_async, + op_fs_read_file_text_sync, op_fs_read_link_async, + op_fs_read_link_sync, op_fs_realpath_async, + op_fs_realpath_sync, op_fs_remove_async, + op_fs_remove_sync, op_fs_rename_async, + op_fs_rename_sync, op_fs_seek_async, + op_fs_seek_sync, op_fs_stat_async, + op_fs_stat_sync, op_fs_symlink_async, + op_fs_symlink_sync, + op_fs_truncate_async, + op_fs_truncate_sync, + op_fs_umask, op_fs_utime_async, + op_fs_utime_sync, op_fs_write_file_async, + op_fs_write_file_sync, } = core.ensureFastOps(); - +const { + op_cancel_handle, +} = core.ensureFastOps(true); const { ArrayPrototypeFilter, Date, @@ -50,9 +86,7 @@ const { SymbolIterator, Uint32Array, } = primordials; -const { - isDate, -} = core; + import { read, readSync, write, writeSync } from "ext:deno_io/12_io.js"; import * as abortSignal from "ext:deno_web/03_abort_signal.js"; import { @@ -63,7 +97,7 @@ import { import { pathFromURL, SymbolDispose } from "ext:deno_web/00_infra.js"; function chmodSync(path, mode) { - ops.op_fs_chmod_sync(pathFromURL(path), mode); + op_fs_chmod_sync(pathFromURL(path), mode); } async function chmod(path, mode) { @@ -75,7 +109,7 @@ function chownSync( uid, gid, ) { - ops.op_fs_chown_sync(pathFromURL(path), uid, gid); + op_fs_chown_sync(pathFromURL(path), uid, gid); } async function chown( @@ -94,7 +128,7 @@ function copyFileSync( fromPath, toPath, ) { - ops.op_fs_copy_file_sync( + op_fs_copy_file_sync( pathFromURL(fromPath), pathFromURL(toPath), ); @@ -111,15 +145,15 @@ async function copyFile( } function cwd() { - return ops.op_fs_cwd(); + return op_fs_cwd(); } function chdir(directory) { - ops.op_fs_chdir(pathFromURL(directory)); + op_fs_chdir(pathFromURL(directory)); } function makeTempDirSync(options = {}) { - return ops.op_fs_make_temp_dir_sync( + return op_fs_make_temp_dir_sync( options.dir, options.prefix, options.suffix, @@ -135,7 +169,7 @@ function makeTempDir(options = {}) { } function makeTempFileSync(options = {}) { - return ops.op_fs_make_temp_file_sync( + return op_fs_make_temp_file_sync( options.dir, options.prefix, options.suffix, @@ -151,7 +185,7 @@ function makeTempFile(options = {}) { } function mkdirSync(path, options) { - ops.op_fs_mkdir_sync( + op_fs_mkdir_sync( pathFromURL(path), options?.recursive ?? false, options?.mode, @@ -167,7 +201,7 @@ async function mkdir(path, options) { } function readDirSync(path) { - return ops.op_fs_read_dir_sync(pathFromURL(path))[ + return op_fs_read_dir_sync(pathFromURL(path))[ SymbolIterator ](); } @@ -187,7 +221,7 @@ function readDir(path) { } function readLinkSync(path) { - return ops.op_fs_read_link_sync(pathFromURL(path)); + return op_fs_read_link_sync(pathFromURL(path)); } function readLink(path) { @@ -195,7 +229,7 @@ function readLink(path) { } function realPathSync(path) { - return ops.op_fs_realpath_sync(pathFromURL(path)); + return op_fs_realpath_sync(pathFromURL(path)); } function realPath(path) { @@ -206,7 +240,7 @@ function removeSync( path, options = {}, ) { - ops.op_fs_remove_sync( + op_fs_remove_sync( pathFromURL(path), !!options.recursive, ); @@ -223,7 +257,7 @@ async function remove( } function renameSync(oldpath, newpath) { - ops.op_fs_rename_sync( + op_fs_rename_sync( pathFromURL(oldpath), pathFromURL(newpath), ); @@ -357,7 +391,7 @@ function parseFileInfo(response) { } function fstatSync(rid) { - ops.op_fs_fstat_sync(rid, statBuf); + op_fs_fstat_sync(rid, statBuf); return statStruct(statBuf); } @@ -371,7 +405,7 @@ async function lstat(path) { } function lstatSync(path) { - ops.op_fs_lstat_sync(pathFromURL(path), statBuf); + op_fs_lstat_sync(pathFromURL(path), statBuf); return statStruct(statBuf); } @@ -381,7 +415,7 @@ async function stat(path) { } function statSync(path) { - ops.op_fs_stat_sync(pathFromURL(path), statBuf); + op_fs_stat_sync(pathFromURL(path), statBuf); return statStruct(statBuf); } @@ -393,7 +427,7 @@ function coerceLen(len) { } function ftruncateSync(rid, len) { - ops.op_fs_ftruncate_sync(rid, coerceLen(len)); + op_fs_ftruncate_sync(rid, coerceLen(len)); } async function ftruncate(rid, len) { @@ -401,7 +435,7 @@ async function ftruncate(rid, len) { } function truncateSync(path, len) { - ops.op_fs_truncate_sync(path, coerceLen(len)); + op_fs_truncate_sync(path, coerceLen(len)); } async function truncate(path, len) { @@ -409,11 +443,11 @@ async function truncate(path, len) { } function umask(mask) { - return ops.op_fs_umask(mask); + return op_fs_umask(mask); } function linkSync(oldpath, newpath) { - ops.op_fs_link_sync(oldpath, newpath); + op_fs_link_sync(oldpath, newpath); } async function link(oldpath, newpath) { @@ -448,7 +482,7 @@ function futimeSync( ) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); - ops.op_fs_futime_sync(rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec); + op_fs_futime_sync(rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec); } async function futime( @@ -474,7 +508,7 @@ function utimeSync( ) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); - ops.op_fs_utime_sync( + op_fs_utime_sync( pathFromURL(path), atimeSec, atimeNsec, @@ -504,7 +538,7 @@ function symlinkSync( newpath, options, ) { - ops.op_fs_symlink_sync( + op_fs_symlink_sync( pathFromURL(oldpath), pathFromURL(newpath), options?.type, @@ -524,7 +558,7 @@ async function symlink( } function fdatasyncSync(rid) { - ops.op_fs_fdatasync_sync(rid); + op_fs_fdatasync_sync(rid); } async function fdatasync(rid) { @@ -532,7 +566,7 @@ async function fdatasync(rid) { } function fsyncSync(rid) { - ops.op_fs_fsync_sync(rid); + op_fs_fsync_sync(rid); } async function fsync(rid) { @@ -540,7 +574,7 @@ async function fsync(rid) { } function flockSync(rid, exclusive) { - ops.op_fs_flock_sync(rid, exclusive === true); + op_fs_flock_sync(rid, exclusive === true); } async function flock(rid, exclusive) { @@ -548,7 +582,7 @@ async function flock(rid, exclusive) { } function funlockSync(rid) { - ops.op_fs_funlock_sync(rid); + op_fs_funlock_sync(rid); } async function funlock(rid) { @@ -560,7 +594,7 @@ function seekSync( offset, whence, ) { - return ops.op_fs_seek_sync(rid, offset, whence); + return op_fs_seek_sync(rid, offset, whence); } function seek( @@ -576,7 +610,7 @@ function openSync( options, ) { if (options) checkOpenOptions(options); - const rid = ops.op_fs_open_sync( + const rid = op_fs_open_sync( pathFromURL(path), options, ); @@ -720,7 +754,7 @@ function checkOpenOptions(options) { const File = FsFile; function readFileSync(path) { - return ops.op_fs_read_file_sync(pathFromURL(path)); + return op_fs_read_file_sync(pathFromURL(path)); } async function readFile(path, options) { @@ -728,7 +762,7 @@ async function readFile(path, options) { let abortHandler; if (options?.signal) { options.signal.throwIfAborted(); - cancelRid = ops.op_cancel_handle(); + cancelRid = op_cancel_handle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } @@ -750,7 +784,7 @@ async function readFile(path, options) { } function readTextFileSync(path) { - return ops.op_fs_read_file_text_sync(pathFromURL(path)); + return op_fs_read_file_text_sync(pathFromURL(path)); } async function readTextFile(path, options) { @@ -758,7 +792,7 @@ async function readTextFile(path, options) { let abortHandler; if (options?.signal) { options.signal.throwIfAborted(); - cancelRid = ops.op_cancel_handle(); + cancelRid = op_cancel_handle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } @@ -785,7 +819,7 @@ function writeFileSync( options = {}, ) { options.signal?.throwIfAborted(); - ops.op_fs_write_file_sync( + op_fs_write_file_sync( pathFromURL(path), options.mode, options.append ?? false, @@ -804,7 +838,7 @@ async function writeFile( let abortHandler; if (options.signal) { options.signal.throwIfAborted(); - cancelRid = ops.op_cancel_handle(); + cancelRid = op_cancel_handle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } |