diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-08-26 16:18:42 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-26 10:18:42 -0400 |
commit | a6f6209f5277f2737bc67efad5c91ab168aff6b5 (patch) | |
tree | 88e8449e61e09cf5037def8d723ec43654d31b06 /js/stat.ts | |
parent | 520f9631e09aa720fd8c03513ee8ea967f5ed4b2 (diff) |
port fs ops to JSON (#2812)
Diffstat (limited to 'js/stat.ts')
-rw-r--r-- | js/stat.ts | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/js/stat.ts b/js/stat.ts index 1fcce82af..1cc8d070a 100644 --- a/js/stat.ts +++ b/js/stat.ts @@ -1,24 +1,18 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers"; -import { assert } from "./util"; +import { sendSync, sendAsync } from "./dispatch_json"; +import * as dispatch from "./dispatch"; import { FileInfo, FileInfoImpl } from "./file_info"; -function req( - filename: string, - lstat: boolean -): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] { - const builder = flatbuffers.createBuilder(); - const filename_ = builder.createString(filename); - const inner = msg.Stat.createStat(builder, filename_, lstat); - return [builder, msg.Any.Stat, inner]; -} - -function res(baseRes: null | msg.Base): FileInfo { - assert(baseRes != null); - assert(msg.Any.StatRes === baseRes!.innerType()); - const res = new msg.StatRes(); - assert(baseRes!.inner(res) != null); - return new FileInfoImpl(res); +export interface StatResponse { + isFile: boolean; + isSymlink: boolean; + len: number; + modified: number; + accessed: number; + created: number; + mode: number; + hasMode: boolean; // false on windows + name: string | null; } /** Queries the file system for information on the path provided. If the given @@ -28,7 +22,11 @@ function res(baseRes: null | msg.Base): FileInfo { * assert(fileInfo.isFile()); */ export async function lstat(filename: string): Promise<FileInfo> { - return res(await sendAsync(...req(filename, true))); + const res = (await sendAsync(dispatch.OP_STAT, { + filename, + lstat: true + })) as StatResponse; + return new FileInfoImpl(res); } /** Queries the file system for information on the path provided synchronously. @@ -39,7 +37,11 @@ export async function lstat(filename: string): Promise<FileInfo> { * assert(fileInfo.isFile()); */ export function lstatSync(filename: string): FileInfo { - return res(sendSync(...req(filename, true))); + const res = sendSync(dispatch.OP_STAT, { + filename, + lstat: true + }) as StatResponse; + return new FileInfoImpl(res); } /** Queries the file system for information on the path provided. `stat` Will @@ -49,7 +51,11 @@ export function lstatSync(filename: string): FileInfo { * assert(fileInfo.isFile()); */ export async function stat(filename: string): Promise<FileInfo> { - return res(await sendAsync(...req(filename, false))); + const res = (await sendAsync(dispatch.OP_STAT, { + filename, + lstat: false + })) as StatResponse; + return new FileInfoImpl(res); } /** Queries the file system for information on the path provided synchronously. @@ -59,5 +65,9 @@ export async function stat(filename: string): Promise<FileInfo> { * assert(fileInfo.isFile()); */ export function statSync(filename: string): FileInfo { - return res(sendSync(...req(filename, false))); + const res = sendSync(dispatch.OP_STAT, { + filename, + lstat: false + }) as StatResponse; + return new FileInfoImpl(res); } |