From 6b3be01a00d9eaa134a5e58570239d6c1cd3bf54 Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Mon, 22 Jun 2020 20:58:52 +0800 Subject: feat(unstable): add Deno.fstatSync and fstat (#6425) --- cli/js/deno_unstable.ts | 1 + cli/js/lib.deno.unstable.d.ts | 22 ++++++++++++++++++++++ cli/js/ops/fs/stat.ts | 8 ++++++++ 3 files changed, 31 insertions(+) (limited to 'cli/js') diff --git a/cli/js/deno_unstable.ts b/cli/js/deno_unstable.ts index 967eafdcd..2327b554d 100644 --- a/cli/js/deno_unstable.ts +++ b/cli/js/deno_unstable.ts @@ -4,6 +4,7 @@ export { umask } from "./ops/fs/umask.ts"; export { linkSync, link } from "./ops/fs/link.ts"; +export { fstatSync, fstat } from "./ops/fs/stat.ts"; export { fsyncSync, fsync } from "./ops/fs/sync.ts"; export { symlinkSync, symlink } from "./ops/fs/symlink.ts"; export { loadavg, osRelease, hostname } from "./ops/os.ts"; diff --git a/cli/js/lib.deno.unstable.d.ts b/cli/js/lib.deno.unstable.d.ts index daecf6604..cc7dea987 100644 --- a/cli/js/lib.deno.unstable.d.ts +++ b/cli/js/lib.deno.unstable.d.ts @@ -1142,4 +1142,26 @@ declare namespace Deno { * ``` */ export function fsync(rid: number): Promise; + + /** **UNSTABLE**: New API, yet to be vetted. + * Synchronously returns a `Deno.FileInfo` for the given file stream. + * + * ```ts + * const file = Deno.openSync("file.txt", { read: true }); + * const fileInfo = Deno.fstatSync(file.rid); + * assert(fileInfo.isFile); + * ``` + */ + export function fstatSync(rid: number): FileInfo; + + /** **UNSTABLE**: New API, yet to be vetted. + * Returns a `Deno.FileInfo` for the given file stream. + * + * ```ts + * const file = await Deno.open("file.txt", { read: true }); + * const fileInfo = await Deno.fstat(file.rid); + * assert(fileInfo.isFile); + * ``` + */ + export function fstat(rid: number): Promise; } diff --git a/cli/js/ops/fs/stat.ts b/cli/js/ops/fs/stat.ts index 93d31fc3f..402adeafc 100644 --- a/cli/js/ops/fs/stat.ts +++ b/cli/js/ops/fs/stat.ts @@ -66,6 +66,14 @@ export function parseFileInfo(response: StatResponse): FileInfo { }; } +export function fstatSync(rid: number): FileInfo { + return parseFileInfo(sendSync("op_fstat", { rid })); +} + +export async function fstat(rid: number): Promise { + return parseFileInfo(await sendAsync("op_fstat", { rid })); +} + export async function lstat(path: string | URL): Promise { path = pathFromURL(path); const res = (await sendAsync("op_stat", { -- cgit v1.2.3