0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/stat.ts
Ryan Dahl c9614d86c1
Move //libdeno to //core/libdeno (#2015)
Fixes some sed errors introduced in c43cfe.

Unfortunately moving libdeno required splitting build.rs into two parts,
one for cli and one for core.

I've also removed the arm64 build - it's complicating things at this
re-org and we're not even testing it. I need to swing back to it and get
tools/test.py running for it.
2019-03-30 14:45:36 -04:00

68 lines
2.3 KiB
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as msg from "gen/cli/msg_generated";
import * as flatbuffers from "./flatbuffers";
import * as dispatch from "./dispatch";
import { assert } from "./util";
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);
msg.Stat.startStat(builder);
msg.Stat.addFilename(builder, filename_);
msg.Stat.addLstat(builder, lstat);
const inner = msg.Stat.endStat(builder);
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);
}
/** Queries the file system for information on the path provided. If the given
* path is a symlink information about the symlink will be returned.
*
* const fileInfo = await Deno.lstat("hello.txt");
* assert(fileInfo.isFile());
*/
export async function lstat(filename: string): Promise<FileInfo> {
return res(await dispatch.sendAsync(...req(filename, true)));
}
/** Queries the file system for information on the path provided synchronously.
* If the given path is a symlink information about the symlink will be
* returned.
*
* const fileInfo = Deno.lstatSync("hello.txt");
* assert(fileInfo.isFile());
*/
export function lstatSync(filename: string): FileInfo {
return res(dispatch.sendSync(...req(filename, true)));
}
/** Queries the file system for information on the path provided. `stat` Will
* always follow symlinks.
*
* const fileInfo = await Deno.stat("hello.txt");
* assert(fileInfo.isFile());
*/
export async function stat(filename: string): Promise<FileInfo> {
return res(await dispatch.sendAsync(...req(filename, false)));
}
/** Queries the file system for information on the path provided synchronously.
* `statSync` Will always follow symlinks.
*
* const fileInfo = Deno.statSync("hello.txt");
* assert(fileInfo.isFile());
*/
export function statSync(filename: string): FileInfo {
return res(dispatch.sendSync(...req(filename, false)));
}