2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-09 19:22:15 -04:00
|
|
|
import { StatResponse } from "./ops/fs/stat.ts";
|
2020-01-16 09:46:32 -05:00
|
|
|
import { build } from "./build.ts";
|
2018-10-03 17:56:56 -04:00
|
|
|
|
|
|
|
export interface FileInfo {
|
2020-03-14 22:57:42 -04:00
|
|
|
size: number;
|
2018-10-03 17:56:56 -04:00
|
|
|
modified: number | null;
|
|
|
|
accessed: number | null;
|
|
|
|
created: number | null;
|
2020-01-16 09:46:32 -05:00
|
|
|
name: string | null;
|
|
|
|
dev: number | null;
|
|
|
|
ino: number | null;
|
2018-10-03 17:56:56 -04:00
|
|
|
mode: number | null;
|
2020-01-16 09:46:32 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-07 19:33:30 -04:00
|
|
|
// @internal
|
2018-10-03 17:56:56 -04:00
|
|
|
export class FileInfoImpl implements FileInfo {
|
2020-03-28 13:03:49 -04:00
|
|
|
readonly #isFile: boolean;
|
2020-03-31 13:46:25 -04:00
|
|
|
readonly #isDirectory: boolean;
|
2020-03-28 13:03:49 -04:00
|
|
|
readonly #isSymlink: boolean;
|
2020-03-14 22:57:42 -04:00
|
|
|
size: number;
|
2018-10-03 17:56:56 -04:00
|
|
|
modified: number | null;
|
|
|
|
accessed: number | null;
|
|
|
|
created: number | null;
|
|
|
|
name: string | null;
|
|
|
|
|
2020-01-16 09:46:32 -05:00
|
|
|
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 */
|
2020-03-28 13:03:49 -04:00
|
|
|
constructor(res: StatResponse) {
|
2020-01-16 09:46:32 -05:00
|
|
|
const isUnix = build.os === "mac" || build.os === "linux";
|
2020-03-28 13:03:49 -04:00
|
|
|
const modified = res.modified;
|
|
|
|
const accessed = res.accessed;
|
|
|
|
const created = res.created;
|
|
|
|
const name = res.name;
|
2020-01-16 09:46:32 -05:00
|
|
|
// Unix only
|
2020-03-28 13:03:49 -04:00
|
|
|
const { dev, ino, mode, nlink, uid, gid, rdev, blksize, blocks } = res;
|
2018-10-03 17:56:56 -04:00
|
|
|
|
2020-03-28 13:03:49 -04:00
|
|
|
this.#isFile = res.isFile;
|
2020-03-31 13:46:25 -04:00
|
|
|
this.#isDirectory = res.isDirectory;
|
2020-03-28 13:03:49 -04:00
|
|
|
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;
|
2020-01-16 09:46:32 -05:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
isFile(): boolean {
|
2020-03-28 13:03:49 -04:00
|
|
|
return this.#isFile;
|
2018-10-03 17:56:56 -04:00
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
isDirectory(): boolean {
|
2020-03-31 13:46:25 -04:00
|
|
|
return this.#isDirectory;
|
2018-10-03 17:56:56 -04:00
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
isSymlink(): boolean {
|
2020-03-28 13:03:49 -04:00
|
|
|
return this.#isSymlink;
|
2018-10-03 17:56:56 -04:00
|
|
|
}
|
|
|
|
}
|