summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAaron Power <theaaronepower@gmail.com>2018-08-31 20:15:22 +0100
committerRyan Dahl <ry@tinyclouds.org>2018-08-31 16:18:31 -0400
commit9b7e5a25583c7b286d0655870c937c3a31921f0a (patch)
treeb6087c48946b7dfa235046b1fed2bb7701f22bbe /js
parentf131445a46555f1634aecae0fc1d4979b4cefa6d (diff)
Document lStatSync & statSync and correct FileInfo.
Diffstat (limited to 'js')
-rw-r--r--js/os.ts54
1 files changed, 49 insertions, 5 deletions
diff --git a/js/os.ts b/js/os.ts
index e98f1557d..db389fd66 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -186,44 +186,88 @@ export function env(): { [index:string]: string } {
return createEnv(res);
}
+/**
+ * A FileInfo describes a file and is returned by `stat`, `lstat`,
+ * `statSync`, `lstatSync`.
+ */
export class FileInfo {
private _isFile: boolean;
private _isSymlink: boolean;
+ /** The size of the file, in bytes. */
len: number;
- modified: number;
- accessed: number;
- // Creation time is not available on all platforms.
+ /**
+ * The last modification time of the file. This corresponds to the `mtime`
+ * field from `stat` on Unix and `ftLastWriteTime` on Windows. This may not
+ * be available on all platforms.
+ */
+ modified: number | null;
+ /**
+ * The last access time of the file. This corresponds to the `atime`
+ * field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not
+ * be available on all platforms.
+ */
+ accessed: number | null;
+ /**
+ * The last access time of the file. This corresponds to the `birthtime`
+ * field from `stat` on Unix and `ftCreationTime` on Windows. This may not
+ * be available on all platforms.
+ */
created: number | null;
/* @internal */
constructor(private _msg: fbs.StatSyncRes) {
+ const modified = this._msg.modified().toFloat64();
+ const accessed = this._msg.accessed().toFloat64();
const created = this._msg.created().toFloat64();
this._isFile = this._msg.isFile();
this._isSymlink = this._msg.isSymlink();
this.len = this._msg.len().toFloat64();
- this.modified = this._msg.modified().toFloat64();
- this.accessed = this._msg.accessed().toFloat64();
+ this.modified = modified ? modified : null;
+ this.accessed = accessed ? accessed : null;
this.created = created ? created : null;
}
+ /**
+ * Returns whether this is info for a regular file. This result is mutually
+ * exclusive to `FileInfo.isDirectory` and `FileInfo.isSymlink`.
+ */
isFile() {
return this._isFile;
}
+ /**
+ * Returns whether this is info for a regular directory. This result is
+ * mutually exclusive to `FileInfo.isFile` and `FileInfo.isSymlink`.
+ */
isDirectory() {
return !this._isFile && !this._isSymlink;
}
+ /**
+ * Returns whether this is info for a symlink. This result is
+ * mutually exclusive to `FileInfo.isFile` and `FileInfo.isDirectory`.
+ */
isSymlink() {
return this._isSymlink;
}
}
+/**
+ * Queries the file system for information on the path provided.
+ * If the given path is a symlink information about the symlink will
+ * be returned.
+ * @returns FileInfo
+ */
export function lStatSync(filename: string): FileInfo {
return statSyncInner(filename, true);
}
+/**
+ * Queries the file system for information on the path provided.
+ * `statSync` Will always follow symlinks.
+ * @returns FileInfo
+ */
export function statSync(filename: string): FileInfo {
return statSyncInner(filename, false);
}