summaryrefslogtreecommitdiff
path: root/cli/js/ops/fs/stat.ts
blob: 032cc97ee2b4029159ea4fd3185c8f75b97a71e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
import { FileInfo, FileInfoImpl } from "../../file_info.ts";

export interface StatResponse {
  isFile: boolean;
  isSymlink: boolean;
  len: number;
  modified: number;
  accessed: number;
  created: number;
  name: string | null;
  // Unix only members
  dev: number;
  ino: number;
  mode: number;
  nlink: number;
  uid: number;
  gid: number;
  rdev: number;
  blksize: number;
  blocks: number;
}

export async function lstat(path: string): Promise<FileInfo> {
  const res = (await sendAsync("op_stat", {
    path,
    lstat: true
  })) as StatResponse;
  return new FileInfoImpl(res);
}

export function lstatSync(path: string): FileInfo {
  const res = sendSync("op_stat", {
    path,
    lstat: true
  }) as StatResponse;
  return new FileInfoImpl(res);
}

export async function stat(path: string): Promise<FileInfo> {
  const res = (await sendAsync("op_stat", {
    path,
    lstat: false
  })) as StatResponse;
  return new FileInfoImpl(res);
}

export function statSync(path: string): FileInfo {
  const res = sendSync("op_stat", {
    path,
    lstat: false
  }) as StatResponse;
  return new FileInfoImpl(res);
}