2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2021-02-04 17:18:32 -05:00
|
|
|
"use strict";
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
((window) => {
|
2020-09-16 16:22:43 -04:00
|
|
|
const core = window.Deno.core;
|
2021-07-03 11:17:23 -04:00
|
|
|
const {
|
|
|
|
Date,
|
|
|
|
MathTrunc,
|
|
|
|
SymbolAsyncIterator,
|
|
|
|
SymbolIterator,
|
|
|
|
} = window.__bootstrap.primordials;
|
2020-07-19 13:49:44 -04:00
|
|
|
const { pathFromURL } = window.__bootstrap.util;
|
|
|
|
const build = window.__bootstrap.build.build;
|
|
|
|
|
|
|
|
function chmodSync(path, mode) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_chmod_sync", { path: pathFromURL(path), mode });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function chmod(path, mode) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_chmod_async", { path: pathFromURL(path), mode });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function chownSync(
|
|
|
|
path,
|
|
|
|
uid,
|
|
|
|
gid,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_chown_sync", { path: pathFromURL(path), uid, gid });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function chown(
|
|
|
|
path,
|
|
|
|
uid,
|
|
|
|
gid,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync(
|
2020-09-16 16:22:43 -04:00
|
|
|
"op_chown_async",
|
|
|
|
{ path: pathFromURL(path), uid, gid },
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyFileSync(
|
|
|
|
fromPath,
|
|
|
|
toPath,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_copy_file_sync", {
|
2020-07-19 13:49:44 -04:00
|
|
|
from: pathFromURL(fromPath),
|
|
|
|
to: pathFromURL(toPath),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function copyFile(
|
|
|
|
fromPath,
|
|
|
|
toPath,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_copy_file_async", {
|
2020-07-19 13:49:44 -04:00
|
|
|
from: pathFromURL(fromPath),
|
|
|
|
to: pathFromURL(toPath),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cwd() {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opSync("op_cwd");
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function chdir(directory) {
|
2021-06-03 10:32:18 -04:00
|
|
|
core.opSync("op_chdir", pathFromURL(directory));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeTempDirSync(options = {}) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opSync("op_make_temp_dir_sync", options);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeTempDir(options = {}) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opAsync("op_make_temp_dir_async", options);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeTempFileSync(options = {}) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opSync("op_make_temp_file_sync", options);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeTempFile(options = {}) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opAsync("op_make_temp_file_async", options);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function mkdirArgs(path, options) {
|
2020-10-27 08:21:32 -04:00
|
|
|
const args = { path: pathFromURL(path), recursive: false };
|
2020-07-19 13:49:44 -04:00
|
|
|
if (options != null) {
|
|
|
|
if (typeof options.recursive == "boolean") {
|
|
|
|
args.recursive = options.recursive;
|
|
|
|
}
|
|
|
|
if (options.mode) {
|
|
|
|
args.mode = options.mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mkdirSync(path, options) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_mkdir_sync", mkdirArgs(path, options));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function mkdir(
|
|
|
|
path,
|
|
|
|
options,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_mkdir_async", mkdirArgs(path, options));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function readDirSync(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opSync("op_read_dir_sync", pathFromURL(path))[
|
2021-07-03 11:17:23 -04:00
|
|
|
SymbolIterator
|
2020-07-19 13:49:44 -04:00
|
|
|
]();
|
|
|
|
}
|
|
|
|
|
|
|
|
function readDir(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
const array = core.opAsync(
|
2020-09-16 16:22:43 -04:00
|
|
|
"op_read_dir_async",
|
2021-04-05 12:40:24 -04:00
|
|
|
pathFromURL(path),
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
return {
|
2021-07-03 11:17:23 -04:00
|
|
|
async *[SymbolAsyncIterator]() {
|
2020-07-19 13:49:44 -04:00
|
|
|
yield* await array;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function readLinkSync(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opSync("op_read_link_sync", pathFromURL(path));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function readLink(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opAsync("op_read_link_async", pathFromURL(path));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function realPathSync(path) {
|
2021-05-17 00:31:21 -04:00
|
|
|
return core.opSync("op_realpath_sync", pathFromURL(path));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function realPath(path) {
|
2021-05-17 00:31:21 -04:00
|
|
|
return core.opAsync("op_realpath_async", pathFromURL(path));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeSync(
|
|
|
|
path,
|
|
|
|
options = {},
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_remove_sync", {
|
2020-07-19 13:49:44 -04:00
|
|
|
path: pathFromURL(path),
|
|
|
|
recursive: !!options.recursive,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function remove(
|
|
|
|
path,
|
|
|
|
options = {},
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_remove_async", {
|
2020-07-19 13:49:44 -04:00
|
|
|
path: pathFromURL(path),
|
|
|
|
recursive: !!options.recursive,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function renameSync(oldpath, newpath) {
|
2021-06-03 10:14:37 -04:00
|
|
|
core.opSync("op_rename_sync", {
|
|
|
|
oldpath: pathFromURL(oldpath),
|
|
|
|
newpath: pathFromURL(newpath),
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function rename(oldpath, newpath) {
|
2021-06-03 10:14:37 -04:00
|
|
|
await core.opAsync("op_rename_async", {
|
|
|
|
oldpath: pathFromURL(oldpath),
|
|
|
|
newpath: pathFromURL(newpath),
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseFileInfo(response) {
|
|
|
|
const unix = build.os === "darwin" || build.os === "linux";
|
|
|
|
return {
|
|
|
|
isFile: response.isFile,
|
|
|
|
isDirectory: response.isDirectory,
|
|
|
|
isSymlink: response.isSymlink,
|
|
|
|
size: response.size,
|
|
|
|
mtime: response.mtime != null ? new Date(response.mtime) : null,
|
|
|
|
atime: response.atime != null ? new Date(response.atime) : null,
|
|
|
|
birthtime: response.birthtime != null
|
|
|
|
? new Date(response.birthtime)
|
|
|
|
: null,
|
|
|
|
// Only non-null if on Unix
|
|
|
|
dev: unix ? response.dev : null,
|
|
|
|
ino: unix ? response.ino : null,
|
|
|
|
mode: unix ? response.mode : null,
|
|
|
|
nlink: unix ? response.nlink : null,
|
|
|
|
uid: unix ? response.uid : null,
|
|
|
|
gid: unix ? response.gid : null,
|
|
|
|
rdev: unix ? response.rdev : null,
|
|
|
|
blksize: unix ? response.blksize : null,
|
|
|
|
blocks: unix ? response.blocks : null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function fstatSync(rid) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return parseFileInfo(core.opSync("op_fstat_sync", rid));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fstat(rid) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return parseFileInfo(await core.opAsync("op_fstat_async", rid));
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function lstat(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
const res = await core.opAsync("op_stat_async", {
|
2020-07-19 13:49:44 -04:00
|
|
|
path: pathFromURL(path),
|
|
|
|
lstat: true,
|
|
|
|
});
|
|
|
|
return parseFileInfo(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
function lstatSync(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
const res = core.opSync("op_stat_sync", {
|
2020-07-19 13:49:44 -04:00
|
|
|
path: pathFromURL(path),
|
|
|
|
lstat: true,
|
|
|
|
});
|
|
|
|
return parseFileInfo(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function stat(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
const res = await core.opAsync("op_stat_async", {
|
2020-07-19 13:49:44 -04:00
|
|
|
path: pathFromURL(path),
|
|
|
|
lstat: false,
|
|
|
|
});
|
|
|
|
return parseFileInfo(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
function statSync(path) {
|
2021-04-12 15:55:05 -04:00
|
|
|
const res = core.opSync("op_stat_sync", {
|
2020-07-19 13:49:44 -04:00
|
|
|
path: pathFromURL(path),
|
|
|
|
lstat: false,
|
|
|
|
});
|
|
|
|
return parseFileInfo(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
function coerceLen(len) {
|
|
|
|
if (len == null || len < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ftruncateSync(rid, len) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_ftruncate_sync", { rid, len: coerceLen(len) });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function ftruncate(rid, len) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_ftruncate_async", { rid, len: coerceLen(len) });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function truncateSync(path, len) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_truncate_sync", { path, len: coerceLen(len) });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function truncate(path, len) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_truncate_async", { path, len: coerceLen(len) });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function umask(mask) {
|
2021-04-12 15:55:05 -04:00
|
|
|
return core.opSync("op_umask", mask);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function linkSync(oldpath, newpath) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_link_sync", { oldpath, newpath });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function link(oldpath, newpath) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_link_async", { oldpath, newpath });
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2020-09-01 10:03:07 -04:00
|
|
|
function toUnixTimeFromEpoch(value) {
|
|
|
|
if (value instanceof Date) {
|
|
|
|
const time = value.valueOf();
|
2021-07-03 11:17:23 -04:00
|
|
|
const seconds = MathTrunc(time / 1e3);
|
|
|
|
const nanoseconds = MathTrunc(time - (seconds * 1e3)) * 1e6;
|
2020-09-01 10:03:07 -04:00
|
|
|
|
|
|
|
return [
|
|
|
|
seconds,
|
|
|
|
nanoseconds,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
const seconds = value;
|
|
|
|
const nanoseconds = 0;
|
|
|
|
|
|
|
|
return [
|
|
|
|
seconds,
|
|
|
|
nanoseconds,
|
|
|
|
];
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2020-08-31 14:29:43 -04:00
|
|
|
function futimeSync(
|
|
|
|
rid,
|
|
|
|
atime,
|
|
|
|
mtime,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_futime_sync", {
|
2020-08-31 14:29:43 -04:00
|
|
|
rid,
|
2020-09-01 10:03:07 -04:00
|
|
|
atime: toUnixTimeFromEpoch(atime),
|
|
|
|
mtime: toUnixTimeFromEpoch(mtime),
|
2020-08-31 14:29:43 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function futime(
|
|
|
|
rid,
|
|
|
|
atime,
|
|
|
|
mtime,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_futime_async", {
|
2020-08-31 14:29:43 -04:00
|
|
|
rid,
|
2020-09-01 10:03:07 -04:00
|
|
|
atime: toUnixTimeFromEpoch(atime),
|
|
|
|
mtime: toUnixTimeFromEpoch(mtime),
|
2020-08-31 14:29:43 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
function utimeSync(
|
|
|
|
path,
|
|
|
|
atime,
|
|
|
|
mtime,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_utime_sync", {
|
2021-05-31 14:05:57 -04:00
|
|
|
path: pathFromURL(path),
|
2020-09-01 10:03:07 -04:00
|
|
|
atime: toUnixTimeFromEpoch(atime),
|
|
|
|
mtime: toUnixTimeFromEpoch(mtime),
|
2020-07-19 13:49:44 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function utime(
|
|
|
|
path,
|
|
|
|
atime,
|
|
|
|
mtime,
|
|
|
|
) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_utime_async", {
|
2021-05-31 14:05:57 -04:00
|
|
|
path: pathFromURL(path),
|
2020-09-01 10:03:07 -04:00
|
|
|
atime: toUnixTimeFromEpoch(atime),
|
|
|
|
mtime: toUnixTimeFromEpoch(mtime),
|
2020-07-19 13:49:44 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function symlinkSync(
|
|
|
|
oldpath,
|
|
|
|
newpath,
|
|
|
|
options,
|
|
|
|
) {
|
2021-06-03 10:16:00 -04:00
|
|
|
core.opSync("op_symlink_sync", {
|
|
|
|
oldpath: pathFromURL(oldpath),
|
|
|
|
newpath: pathFromURL(newpath),
|
|
|
|
options,
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function symlink(
|
|
|
|
oldpath,
|
|
|
|
newpath,
|
|
|
|
options,
|
|
|
|
) {
|
2021-06-03 10:16:00 -04:00
|
|
|
await core.opAsync("op_symlink_async", {
|
|
|
|
oldpath: pathFromURL(oldpath),
|
|
|
|
newpath: pathFromURL(newpath),
|
|
|
|
options,
|
|
|
|
});
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function fdatasyncSync(rid) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_fdatasync_sync", rid);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fdatasync(rid) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_fdatasync_async", rid);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function fsyncSync(rid) {
|
2021-04-12 15:55:05 -04:00
|
|
|
core.opSync("op_fsync_sync", rid);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fsync(rid) {
|
2021-04-12 15:55:05 -04:00
|
|
|
await core.opAsync("op_fsync_async", rid);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-08-24 09:21:31 -04:00
|
|
|
function flockSync(rid, exclusive) {
|
|
|
|
core.opSync("op_flock_sync", rid, exclusive === true);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function flock(rid, exclusive) {
|
|
|
|
await core.opAsync("op_flock_async", rid, exclusive === true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function funlockSync(rid) {
|
|
|
|
core.opSync("op_funlock_sync", rid);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function funlock(rid) {
|
|
|
|
await core.opAsync("op_funlock_async", rid);
|
|
|
|
}
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
window.__bootstrap.fs = {
|
|
|
|
cwd,
|
|
|
|
chdir,
|
|
|
|
chmodSync,
|
|
|
|
chmod,
|
|
|
|
chown,
|
|
|
|
chownSync,
|
|
|
|
copyFile,
|
|
|
|
copyFileSync,
|
|
|
|
makeTempFile,
|
|
|
|
makeTempDir,
|
|
|
|
makeTempFileSync,
|
|
|
|
makeTempDirSync,
|
|
|
|
mkdir,
|
|
|
|
mkdirSync,
|
|
|
|
readDir,
|
|
|
|
readDirSync,
|
|
|
|
readLinkSync,
|
|
|
|
readLink,
|
|
|
|
realPathSync,
|
|
|
|
realPath,
|
|
|
|
remove,
|
|
|
|
removeSync,
|
|
|
|
renameSync,
|
|
|
|
rename,
|
|
|
|
lstat,
|
|
|
|
lstatSync,
|
|
|
|
stat,
|
|
|
|
statSync,
|
|
|
|
ftruncate,
|
|
|
|
ftruncateSync,
|
|
|
|
truncate,
|
|
|
|
truncateSync,
|
|
|
|
umask,
|
|
|
|
link,
|
|
|
|
linkSync,
|
2021-04-12 07:33:05 -04:00
|
|
|
fstatSync,
|
|
|
|
fstat,
|
2020-08-31 14:29:43 -04:00
|
|
|
futime,
|
|
|
|
futimeSync,
|
2020-07-19 13:49:44 -04:00
|
|
|
utime,
|
|
|
|
utimeSync,
|
|
|
|
symlink,
|
|
|
|
symlinkSync,
|
|
|
|
fdatasync,
|
|
|
|
fdatasyncSync,
|
|
|
|
fsync,
|
|
|
|
fsyncSync,
|
2021-08-24 09:21:31 -04:00
|
|
|
flock,
|
|
|
|
flockSync,
|
|
|
|
funlock,
|
|
|
|
funlockSync,
|
2020-07-19 13:49:44 -04:00
|
|
|
};
|
|
|
|
})(this);
|