Skip to content

Commit beca8b7

Browse files
code-asherkylecarbs
authored andcommitted
Fix Stats class
Dates were strings.
1 parent dcf23ed commit beca8b7

File tree

1 file changed

+62
-64
lines changed
  • packages/protocol/src/browser/modules

1 file changed

+62
-64
lines changed

packages/protocol/src/browser/modules/fs.ts

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class FS {
186186
};
187187
});
188188
}, fd).then((stats) => {
189-
callback(undefined!, Stats.fromObject(stats));
189+
callback(undefined!, new Stats(stats));
190190
}).catch((ex) => {
191191
callback(ex, undefined!);
192192
});
@@ -292,7 +292,7 @@ export class FS {
292292
};
293293
});
294294
}, path).then((stats) => {
295-
callback(undefined!, Stats.fromObject(stats));
295+
callback(undefined!, new Stats(stats));
296296
}).catch((ex) => {
297297
callback(ex, undefined!);
298298
});
@@ -483,7 +483,7 @@ export class FS {
483483
};
484484
});
485485
}, path).then((stats) => {
486-
callback(undefined!, Stats.fromObject(stats));
486+
callback(undefined!, new Stats(stats));
487487
}).catch((ex) => {
488488
callback(ex, undefined!);
489489
});
@@ -652,94 +652,92 @@ class Watcher extends EventEmitter implements fs.FSWatcher {
652652

653653
}
654654

655+
interface IStats {
656+
dev: number;
657+
ino: number;
658+
mode: number;
659+
nlink: number;
660+
uid: number;
661+
gid: number;
662+
rdev: number;
663+
size: number;
664+
blksize: number;
665+
blocks: number;
666+
atimeMs: number;
667+
mtimeMs: number;
668+
ctimeMs: number;
669+
birthtimeMs: number;
670+
atime: string;
671+
mtime: string;
672+
ctime: string;
673+
birthtime: string;
674+
_isFile: boolean;
675+
_isDirectory: boolean;
676+
_isBlockDevice: boolean;
677+
_isCharacterDevice: boolean;
678+
_isSymbolicLink: boolean;
679+
_isFIFO: boolean;
680+
_isSocket: boolean;
681+
}
682+
655683
class Stats implements fs.Stats {
656684

657-
// tslint:disable-next-line no-any
658-
public static fromObject(object: any): Stats {
659-
return new Stats(object);
660-
}
661-
662-
// @ts-ignore
663-
public readonly dev: number;
664-
// @ts-ignore
665-
public readonly ino: number;
666-
// @ts-ignore
667-
public readonly mode: number;
668-
// @ts-ignore
669-
public readonly nlink: number;
670-
// @ts-ignore
671-
public readonly uid: number;
672-
// @ts-ignore
673-
public readonly gid: number;
674-
// @ts-ignore
675-
public readonly rdev: number;
676-
// @ts-ignore
677-
public readonly size: number;
678-
// @ts-ignore
679-
public readonly blksize: number;
680-
// @ts-ignore
681-
public readonly blocks: number;
682-
// @ts-ignore
683-
public readonly atimeMs: number;
684-
// @ts-ignore
685-
public readonly mtimeMs: number;
686-
// @ts-ignore
687-
public readonly ctimeMs: number;
688-
// @ts-ignore
689-
public readonly birthtimeMs: number;
690-
// @ts-ignore
691685
public readonly atime: Date;
692-
// @ts-ignore
693686
public readonly mtime: Date;
694-
// @ts-ignore
695687
public readonly ctime: Date;
696-
// @ts-ignore
697688
public readonly birthtime: Date;
698-
// @ts-ignore
699-
private readonly _isFile: boolean;
700-
// @ts-ignore
701-
private readonly _isDirectory: boolean;
702-
// @ts-ignore
703-
private readonly _isBlockDevice: boolean;
704-
// @ts-ignore
705-
private readonly _isCharacterDevice: boolean;
706-
// @ts-ignore
707-
private readonly _isSymbolicLink: boolean;
708-
// @ts-ignore
709-
private readonly _isFIFO: boolean;
710-
// @ts-ignore
711-
private readonly _isSocket: boolean;
712-
713-
private constructor(stats: object) {
714-
Object.assign(this, stats);
689+
690+
private constructor(private readonly stats: IStats) {
691+
this.atime = new Date(stats.atime);
692+
this.mtime = new Date(stats.mtime);
693+
this.ctime = new Date(stats.ctime);
694+
this.birthtime = new Date(stats.birthtime);
715695
}
716696

697+
public get dev(): number {
698+
return this.stats.dev;
699+
}
700+
701+
public get ino(): number { return this.stats.ino; }
702+
public get mode(): number { return this.stats.mode; }
703+
public get nlink(): number { return this.stats.nlink; }
704+
public get uid(): number { return this.stats.uid; }
705+
public get gid(): number { return this.stats.gid; }
706+
public get rdev(): number { return this.stats.rdev; }
707+
public get size(): number { return this.stats.size; }
708+
public get blksize(): number { return this.stats.blksize; }
709+
public get blocks(): number { return this.stats.blocks; }
710+
public get atimeMs(): number { return this.stats.atimeMs; }
711+
public get mtimeMs(): number { return this.stats.mtimeMs; }
712+
public get ctimeMs(): number { return this.stats.ctimeMs; }
713+
public get birthtimeMs(): number { return this.stats.birthtimeMs; }
714+
717715
public isFile(): boolean {
718-
return this._isFile;
716+
return this.stats._isFile;
719717
}
720718

721719
public isDirectory(): boolean {
722-
return this._isDirectory;
720+
return this.stats._isDirectory;
723721
}
724722

725723
public isBlockDevice(): boolean {
726-
return this._isBlockDevice;
724+
return this.stats._isBlockDevice;
727725
}
728726

729727
public isCharacterDevice(): boolean {
730-
return this._isCharacterDevice;
728+
return this.stats._isCharacterDevice;
731729
}
732730

733731
public isSymbolicLink(): boolean {
734-
return this._isSymbolicLink;
732+
return this.stats._isSymbolicLink;
735733
}
736734

737735
public isFIFO(): boolean {
738-
return this._isFIFO;
736+
return this.stats._isFIFO;
739737
}
740738

741739
public isSocket(): boolean {
742-
return this._isSocket;
740+
return this.stats._isSocket;
743741
}
744742

745743
public toObject(): object {

0 commit comments

Comments
 (0)