diff options
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 109 |
1 files changed, 0 insertions, 109 deletions
@@ -166,115 +166,6 @@ export function env(): { [index: string]: string } { } /** - * A FileInfo describes a file and is returned by `stat`, `lstat`, - * `statSync`, `lstatSync`. - */ -export class FileInfo { - private readonly _isFile: boolean; - private readonly _isSymlink: boolean; - /** The size of the file, in bytes. */ - len: number; - /** - * 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 = 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); -} - -function statSyncInner(filename: string, lstat: boolean): FileInfo { - /* Ideally we could write - const res = sendSync({ - command: fbs.Command.STAT_FILE_SYNC, - StatFilename: filename, - StatLStat: lstat, - }); - return new FileInfo(res); - */ - const builder = new flatbuffers.Builder(); - const filename_ = builder.createString(filename); - fbs.StatSync.startStatSync(builder); - fbs.StatSync.addFilename(builder, filename_); - fbs.StatSync.addLstat(builder, lstat); - const msg = fbs.StatSync.endStatSync(builder); - const baseRes = sendSync(builder, fbs.Any.StatSync, msg); - assert(baseRes != null); - assert(fbs.Any.StatSyncRes === baseRes!.msgType()); - const res = new fbs.StatSyncRes(); - assert(baseRes!.msg(res) != null); - return new FileInfo(res); -} - -/** * Renames (moves) oldpath to newpath. * import { renameSync } from "deno"; * const oldpath = 'from/path'; |