-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export class VirtualFile { | ||
private _date = new Date(); | ||
constructor( | ||
private _fileId: number, | ||
private _path: string, | ||
private _content: string | ||
) {} | ||
|
||
get path() { | ||
return this._path; | ||
} | ||
|
||
get fileId() { | ||
return this._fileId; | ||
} | ||
|
||
getBuffer() { | ||
return Buffer.from(this._content); | ||
} | ||
|
||
getSize() { | ||
return Buffer.byteLength(this.getBuffer()); | ||
} | ||
|
||
getAttr() { | ||
return { | ||
mtime: this._date, | ||
atime: this._date, | ||
ctime: this._date, | ||
blocks: 1, | ||
ino: this.fileId, | ||
nlink: 1, | ||
size: this.getSize(), | ||
mode: 33188, | ||
uid: process.getuid ? process.getuid() : 0, | ||
gid: process.getgid ? process.getgid() : 0, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { VirtualFile } from "./VirtualFile"; | ||
|
||
export class VirtualFiles { | ||
constructor(private _files: Map<string, VirtualFile>) {} | ||
|
||
filePaths(path: string) { | ||
if (path === "/") { | ||
return Array.from(this._files.keys()); | ||
} | ||
return []; | ||
} | ||
|
||
isVirtualFile(path: string) { | ||
// TODO: find correct directory | ||
return this._files.has(path); | ||
} | ||
|
||
getVirtualFile(path: string) { | ||
return this._files.get(path); | ||
} | ||
} |