0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/cli/js/file_info.ts

88 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-01-02 15:13:47 -05:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { StatResponse } from "./ops/fs/stat.ts";
import { build } from "./build.ts";
2018-10-03 17:56:56 -04:00
export interface FileInfo {
size: number;
2018-10-03 17:56:56 -04:00
modified: number | null;
accessed: number | null;
created: number | null;
name: string | null;
dev: number | null;
ino: number | null;
2018-10-03 17:56:56 -04:00
mode: number | null;
nlink: number | null;
uid: number | null;
gid: number | null;
rdev: number | null;
blksize: number | null;
blocks: number | null;
2018-10-03 17:56:56 -04:00
isFile(): boolean;
isDirectory(): boolean;
isSymlink(): boolean;
}
// @internal
2018-10-03 17:56:56 -04:00
export class FileInfoImpl implements FileInfo {
readonly #isFile: boolean;
readonly #isDirectory: boolean;
readonly #isSymlink: boolean;
size: number;
2018-10-03 17:56:56 -04:00
modified: number | null;
accessed: number | null;
created: number | null;
name: string | null;
dev: number | null;
ino: number | null;
mode: number | null;
nlink: number | null;
uid: number | null;
gid: number | null;
rdev: number | null;
blksize: number | null;
blocks: number | null;
2018-10-03 17:56:56 -04:00
/* @internal */
constructor(res: StatResponse) {
const isUnix = build.os === "mac" || build.os === "linux";
const modified = res.modified;
const accessed = res.accessed;
const created = res.created;
const name = res.name;
// Unix only
const { dev, ino, mode, nlink, uid, gid, rdev, blksize, blocks } = res;
2018-10-03 17:56:56 -04:00
this.#isFile = res.isFile;
this.#isDirectory = res.isDirectory;
this.#isSymlink = res.isSymlink;
this.size = res.size;
2018-10-03 17:56:56 -04:00
this.modified = modified ? modified : null;
this.accessed = accessed ? accessed : null;
this.created = created ? created : null;
this.name = name ? name : null;
// Only non-null if on Unix
this.dev = isUnix ? dev : null;
this.ino = isUnix ? ino : null;
this.mode = isUnix ? mode : null;
this.nlink = isUnix ? nlink : null;
this.uid = isUnix ? uid : null;
this.gid = isUnix ? gid : null;
this.rdev = isUnix ? rdev : null;
this.blksize = isUnix ? blksize : null;
this.blocks = isUnix ? blocks : null;
2018-10-03 17:56:56 -04:00
}
isFile(): boolean {
return this.#isFile;
2018-10-03 17:56:56 -04:00
}
isDirectory(): boolean {
return this.#isDirectory;
2018-10-03 17:56:56 -04:00
}
isSymlink(): boolean {
return this.#isSymlink;
2018-10-03 17:56:56 -04:00
}
}