typescript-virtual-container 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/SSHClient/index.d.ts +138 -0
- package/dist/SSHClient/index.d.ts.map +1 -0
- package/dist/SSHClient/index.js +216 -0
- package/dist/SSHMimic/exec.d.ts +4 -0
- package/dist/SSHMimic/exec.d.ts.map +1 -0
- package/dist/SSHMimic/exec.js +21 -0
- package/dist/SSHMimic/executor.d.ts +9 -0
- package/dist/SSHMimic/executor.d.ts.map +1 -0
- package/dist/SSHMimic/executor.js +131 -0
- package/dist/SSHMimic/hostKey.d.ts +2 -0
- package/dist/SSHMimic/hostKey.d.ts.map +1 -0
- package/dist/SSHMimic/hostKey.js +17 -0
- package/dist/SSHMimic/index.d.ts +39 -0
- package/dist/SSHMimic/index.d.ts.map +1 -0
- package/dist/SSHMimic/index.js +113 -0
- package/dist/SSHMimic/loginFormat.d.ts +2 -0
- package/dist/SSHMimic/loginFormat.d.ts.map +1 -0
- package/dist/SSHMimic/loginFormat.js +10 -0
- package/dist/SSHMimic/prompt.d.ts +2 -0
- package/dist/SSHMimic/prompt.d.ts.map +1 -0
- package/dist/SSHMimic/prompt.js +9 -0
- package/dist/VirtualFileSystem/archive.d.ts +5 -0
- package/dist/VirtualFileSystem/archive.d.ts.map +1 -0
- package/dist/VirtualFileSystem/archive.js +56 -0
- package/dist/VirtualFileSystem/index.d.ts +131 -0
- package/dist/VirtualFileSystem/index.d.ts.map +1 -0
- package/dist/VirtualFileSystem/index.js +355 -0
- package/dist/VirtualFileSystem/internalTypes.d.ts +18 -0
- package/dist/VirtualFileSystem/internalTypes.d.ts.map +1 -0
- package/dist/VirtualFileSystem/internalTypes.js +0 -0
- package/dist/VirtualFileSystem/path.d.ts +9 -0
- package/dist/VirtualFileSystem/path.d.ts.map +1 -0
- package/dist/VirtualFileSystem/path.js +49 -0
- package/dist/VirtualFileSystem/snapshot.d.ts +5 -0
- package/dist/VirtualFileSystem/snapshot.d.ts.map +1 -0
- package/dist/VirtualFileSystem/snapshot.js +59 -0
- package/dist/VirtualFileSystem/tree.d.ts +3 -0
- package/dist/VirtualFileSystem/tree.d.ts.map +1 -0
- package/dist/VirtualFileSystem/tree.js +19 -0
- package/dist/VirtualShell/index.d.ts +86 -0
- package/dist/VirtualShell/index.d.ts.map +1 -0
- package/dist/VirtualShell/index.js +129 -0
- package/dist/VirtualShell/shell.d.ts +5 -0
- package/dist/VirtualShell/shell.d.ts.map +1 -0
- package/dist/VirtualShell/shell.js +473 -0
- package/dist/VirtualShell/shellParser.d.ts +4 -0
- package/dist/VirtualShell/shellParser.d.ts.map +1 -0
- package/dist/VirtualShell/shellParser.js +207 -0
- package/dist/VirtualUserManager/index.d.ts +168 -0
- package/dist/VirtualUserManager/index.d.ts.map +1 -0
- package/dist/VirtualUserManager/index.js +375 -0
- package/dist/commands/adduser.d.ts +3 -0
- package/dist/commands/adduser.d.ts.map +1 -0
- package/dist/commands/adduser.js +18 -0
- package/dist/commands/cat.d.ts +3 -0
- package/dist/commands/cat.d.ts.map +1 -0
- package/dist/commands/cat.js +15 -0
- package/dist/commands/cd.d.ts +3 -0
- package/dist/commands/cd.d.ts.map +1 -0
- package/dist/commands/cd.js +17 -0
- package/dist/commands/clear.d.ts +3 -0
- package/dist/commands/clear.d.ts.map +1 -0
- package/dist/commands/clear.js +5 -0
- package/dist/commands/command-helpers.d.ts +23 -0
- package/dist/commands/command-helpers.d.ts.map +1 -0
- package/dist/commands/command-helpers.js +139 -0
- package/dist/commands/curl.d.ts +3 -0
- package/dist/commands/curl.d.ts.map +1 -0
- package/dist/commands/curl.js +44 -0
- package/dist/commands/deluser.d.ts +3 -0
- package/dist/commands/deluser.d.ts.map +1 -0
- package/dist/commands/deluser.js +15 -0
- package/dist/commands/echo.d.ts +3 -0
- package/dist/commands/echo.d.ts.map +1 -0
- package/dist/commands/echo.js +22 -0
- package/dist/commands/env.d.ts +3 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/env.js +18 -0
- package/dist/commands/exit.d.ts +3 -0
- package/dist/commands/exit.d.ts.map +1 -0
- package/dist/commands/exit.js +5 -0
- package/dist/commands/export.d.ts +3 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +34 -0
- package/dist/commands/grep.d.ts +3 -0
- package/dist/commands/grep.d.ts.map +1 -0
- package/dist/commands/grep.js +69 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +7 -0
- package/dist/commands/helpers.d.ts +26 -0
- package/dist/commands/helpers.d.ts.map +1 -0
- package/dist/commands/helpers.js +160 -0
- package/dist/commands/hostname.d.ts +3 -0
- package/dist/commands/hostname.d.ts.map +1 -0
- package/dist/commands/hostname.js +5 -0
- package/dist/commands/htop.d.ts +3 -0
- package/dist/commands/htop.d.ts.map +1 -0
- package/dist/commands/htop.js +10 -0
- package/dist/commands/index.d.ts +8 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +212 -0
- package/dist/commands/ls.d.ts +3 -0
- package/dist/commands/ls.d.ts.map +1 -0
- package/dist/commands/ls.js +47 -0
- package/dist/commands/mkdir.d.ts +3 -0
- package/dist/commands/mkdir.d.ts.map +1 -0
- package/dist/commands/mkdir.js +21 -0
- package/dist/commands/nano.d.ts +3 -0
- package/dist/commands/nano.d.ts.map +1 -0
- package/dist/commands/nano.js +27 -0
- package/dist/commands/neofetch.d.ts +3 -0
- package/dist/commands/neofetch.d.ts.map +1 -0
- package/dist/commands/neofetch.js +32 -0
- package/dist/commands/pwd.d.ts +3 -0
- package/dist/commands/pwd.d.ts.map +1 -0
- package/dist/commands/pwd.js +5 -0
- package/dist/commands/rm.d.ts +3 -0
- package/dist/commands/rm.d.ts.map +1 -0
- package/dist/commands/rm.js +29 -0
- package/dist/commands/set.d.ts +7 -0
- package/dist/commands/set.d.ts.map +1 -0
- package/dist/commands/set.js +64 -0
- package/dist/commands/sh.d.ts +4 -0
- package/dist/commands/sh.d.ts.map +1 -0
- package/dist/commands/sh.js +45 -0
- package/dist/commands/su.d.ts +3 -0
- package/dist/commands/su.d.ts.map +1 -0
- package/dist/commands/su.js +24 -0
- package/dist/commands/sudo.d.ts +3 -0
- package/dist/commands/sudo.d.ts.map +1 -0
- package/dist/commands/sudo.js +47 -0
- package/dist/commands/touch.d.ts +3 -0
- package/dist/commands/touch.d.ts.map +1 -0
- package/dist/commands/touch.js +18 -0
- package/dist/commands/tree.d.ts +3 -0
- package/dist/commands/tree.d.ts.map +1 -0
- package/dist/commands/tree.js +11 -0
- package/dist/commands/unset.d.ts +3 -0
- package/dist/commands/unset.d.ts.map +1 -0
- package/dist/commands/unset.js +15 -0
- package/dist/commands/wget.d.ts +3 -0
- package/dist/commands/wget.d.ts.map +1 -0
- package/dist/commands/wget.js +113 -0
- package/dist/commands/who.d.ts +3 -0
- package/dist/commands/who.d.ts.map +1 -0
- package/dist/commands/who.js +15 -0
- package/dist/commands/whoami.d.ts +3 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/modules/neofetch.d.ts +19 -0
- package/dist/modules/neofetch.d.ts.map +1 -0
- package/dist/modules/neofetch.js +284 -0
- package/dist/modules/shellInteractive.d.ts +6 -0
- package/dist/modules/shellInteractive.d.ts.map +1 -0
- package/dist/modules/shellInteractive.js +26 -0
- package/dist/modules/shellRuntime.d.ts +11 -0
- package/dist/modules/shellRuntime.d.ts.map +1 -0
- package/dist/modules/shellRuntime.js +52 -0
- package/dist/standalone.d.ts +2 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +25 -0
- package/dist/types/commands.d.ts +89 -0
- package/dist/types/commands.d.ts.map +1 -0
- package/dist/types/commands.js +0 -0
- package/dist/types/pipeline.d.ts +23 -0
- package/dist/types/pipeline.d.ts.map +1 -0
- package/dist/types/pipeline.js +0 -0
- package/dist/types/streams.d.ts +32 -0
- package/dist/types/streams.d.ts.map +1 -0
- package/dist/types/streams.js +0 -0
- package/dist/types/vfs.d.ts +71 -0
- package/dist/types/vfs.d.ts.map +1 -0
- package/dist/types/vfs.js +0 -0
- package/package.json +4 -2
- package/src/VirtualShell/shell.ts +3 -3
- package/src/commands/neofetch.ts +1 -1
- package/{modules → src/modules}/neofetch.ts +56 -51
- package/{modules → src/modules}/shellInteractive.ts +16 -4
- package/tsconfig.json +20 -8
- /package/{modules → src/modules}/shellRuntime.ts +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Server as SshServer } from "ssh2";
|
|
2
|
+
import { VirtualShell } from "../VirtualShell";
|
|
3
|
+
import { loadOrCreateHostKey } from "./hostKey";
|
|
4
|
+
/**
|
|
5
|
+
* SSH server facade that wires the virtual shell runtime into ssh2 sessions.
|
|
6
|
+
*
|
|
7
|
+
* This class is exported as `VirtualSshServer` for public API compatibility.
|
|
8
|
+
* Create an instance, call {@link SshMimic.start}, and stop it with
|
|
9
|
+
* {@link SshMimic.stop} when your process exits.
|
|
10
|
+
*/
|
|
11
|
+
class SshMimic {
|
|
12
|
+
port;
|
|
13
|
+
server;
|
|
14
|
+
shell;
|
|
15
|
+
shellHostname;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new SSH mimic server instance.
|
|
18
|
+
*
|
|
19
|
+
* @param port TCP port to bind on localhost.
|
|
20
|
+
* @param hostname Virtual hostname used for the SSH ident and default shell label.
|
|
21
|
+
* @param shell Optional preconfigured virtual shell instance to reuse.
|
|
22
|
+
*/
|
|
23
|
+
constructor({ port, hostname = "typescript-vm", shell = new VirtualShell(hostname), }) {
|
|
24
|
+
this.port = port;
|
|
25
|
+
this.shellHostname = hostname;
|
|
26
|
+
this.server = null;
|
|
27
|
+
this.shell = shell;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Starts server and initializes virtual filesystem, users, and handlers.
|
|
31
|
+
*
|
|
32
|
+
* @returns Promise resolved with bound listening port.
|
|
33
|
+
*/
|
|
34
|
+
async start() {
|
|
35
|
+
const shell = this.shell;
|
|
36
|
+
const privateKey = loadOrCreateHostKey();
|
|
37
|
+
this.server = new SshServer({
|
|
38
|
+
hostKeys: [privateKey],
|
|
39
|
+
ident: `SSH-2.0-${shell.hostname}`,
|
|
40
|
+
}, (client) => {
|
|
41
|
+
let authUser = "root";
|
|
42
|
+
let remoteAddress = "unknown";
|
|
43
|
+
let sessionId = null;
|
|
44
|
+
client.on("authentication", (ctx) => {
|
|
45
|
+
shell;
|
|
46
|
+
if (ctx.method === "password") {
|
|
47
|
+
const candidateUser = ctx.username || "root";
|
|
48
|
+
remoteAddress = ctx.ip ?? remoteAddress;
|
|
49
|
+
if (!shell.users.verifyPassword(candidateUser, ctx.password ?? "")) {
|
|
50
|
+
ctx.reject();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
authUser = candidateUser;
|
|
54
|
+
sessionId = shell.users.registerSession(authUser, remoteAddress).id;
|
|
55
|
+
const homePath = `/home/${authUser}`;
|
|
56
|
+
if (!shell.vfs.exists(homePath)) {
|
|
57
|
+
shell.vfs.mkdir(homePath, 0o755);
|
|
58
|
+
shell.vfs.writeFile(`${homePath}/README.txt`, `Welcome to ${shell?.hostname ?? this.shellHostname}`);
|
|
59
|
+
void shell.vfs.flushMirror();
|
|
60
|
+
}
|
|
61
|
+
ctx.accept();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
ctx.reject();
|
|
65
|
+
});
|
|
66
|
+
client.on("close", () => {
|
|
67
|
+
shell.users.unregisterSession(sessionId);
|
|
68
|
+
sessionId = null;
|
|
69
|
+
});
|
|
70
|
+
client.on("ready", () => {
|
|
71
|
+
client.on("session", (accept) => {
|
|
72
|
+
const session = accept();
|
|
73
|
+
const terminalSize = { cols: 80, rows: 24 };
|
|
74
|
+
session.on("pty", (acceptPty, _rejectPty, info) => {
|
|
75
|
+
terminalSize.cols = info?.cols ?? terminalSize.cols;
|
|
76
|
+
terminalSize.rows = info?.rows ?? terminalSize.rows;
|
|
77
|
+
acceptPty();
|
|
78
|
+
});
|
|
79
|
+
session.on("window-change", (_acceptChange, _rejectChange, info) => {
|
|
80
|
+
terminalSize.cols = info?.cols ?? terminalSize.cols;
|
|
81
|
+
terminalSize.rows = info?.rows ?? terminalSize.rows;
|
|
82
|
+
});
|
|
83
|
+
session.on("shell", (acceptShell) => {
|
|
84
|
+
const stream = acceptShell();
|
|
85
|
+
shell?.startInteractiveSession(stream, authUser, sessionId, remoteAddress, terminalSize);
|
|
86
|
+
});
|
|
87
|
+
session.on("exec", (acceptExec, _rejectExec, info) => {
|
|
88
|
+
const _stream = acceptExec();
|
|
89
|
+
shell?.executeCommand(info.command.trim(), authUser, `/home/${authUser}`);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
this.server?.once("error", (err) => reject(err));
|
|
96
|
+
this.server?.listen(this.port, "127.0.0.1", () => {
|
|
97
|
+
console.log(`SSH Mimic listening on port ${this.port}`);
|
|
98
|
+
resolve(this.port);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Stops server if running.
|
|
104
|
+
*/
|
|
105
|
+
stop() {
|
|
106
|
+
if (this.server) {
|
|
107
|
+
this.server.close(() => {
|
|
108
|
+
console.log("SSH Mimic stopped");
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export { SshMimic };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginFormat.d.ts","sourceRoot":"","sources":["../../src/SSHMimic/loginFormat.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CASlD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function formatLoginDate(date) {
|
|
2
|
+
const weekday = date.toLocaleString("en-US", { weekday: "short" });
|
|
3
|
+
const month = date.toLocaleString("en-US", { month: "short" });
|
|
4
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
5
|
+
const hh = date.getHours().toString().padStart(2, "0");
|
|
6
|
+
const mm = date.getMinutes().toString().padStart(2, "0");
|
|
7
|
+
const ss = date.getSeconds().toString().padStart(2, "0");
|
|
8
|
+
const year = date.getFullYear();
|
|
9
|
+
return `${weekday} ${month} ${day} ${hh}:${mm}:${ss} ${year}`;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/SSHMimic/prompt.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACb,MAAM,CASR"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function buildPrompt(user, host, cwdName) {
|
|
2
|
+
const isRoot = user === "root";
|
|
3
|
+
const colorUser = isRoot ? "\u001b[31;1m" : "\u001b[35;1m";
|
|
4
|
+
const colorWhite = "\u001b[37;1m";
|
|
5
|
+
const colorBlue = "\u001b[34;1m";
|
|
6
|
+
const colorReset = "\u001b[0m";
|
|
7
|
+
const symbol = isRoot ? "#" : "$";
|
|
8
|
+
return `${colorWhite}[${colorUser}${user}${colorWhite}@${colorBlue}${host}${colorReset} ${cwdName}${colorWhite}]${colorReset}${symbol} `;
|
|
9
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { VfsSnapshot } from "../types/vfs";
|
|
2
|
+
export declare function archiveExists(archivePath: string): Promise<boolean>;
|
|
3
|
+
export declare function createTarBuffer(snapshotJson: string): Promise<Buffer>;
|
|
4
|
+
export declare function readSnapshotFromTar(tarBuffer: Buffer): Promise<VfsSnapshot>;
|
|
5
|
+
//# sourceMappingURL=archive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../../src/VirtualFileSystem/archive.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOzE;AAED,wBAAsB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuB3E;AAED,wBAAsB,mBAAmB,CACxC,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAiCtB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import * as tarStream from "tar-stream";
|
|
3
|
+
export async function archiveExists(archivePath) {
|
|
4
|
+
try {
|
|
5
|
+
await fs.access(archivePath);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function createTarBuffer(snapshotJson) {
|
|
13
|
+
const pack = tarStream.pack();
|
|
14
|
+
const chunks = [];
|
|
15
|
+
const finished = new Promise((resolve, reject) => {
|
|
16
|
+
pack.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
17
|
+
pack.on("error", reject);
|
|
18
|
+
pack.on("end", () => resolve(Buffer.concat(chunks)));
|
|
19
|
+
});
|
|
20
|
+
pack.entry({ name: "snapshot.json", mode: 0o600 }, snapshotJson, (error) => {
|
|
21
|
+
if (error) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
pack.finalize();
|
|
25
|
+
});
|
|
26
|
+
return finished;
|
|
27
|
+
}
|
|
28
|
+
export async function readSnapshotFromTar(tarBuffer) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const extract = tarStream.extract();
|
|
31
|
+
let snapshotText = "";
|
|
32
|
+
let found = false;
|
|
33
|
+
extract.on("entry", (header, stream, next) => {
|
|
34
|
+
if (header.name === "snapshot.json") {
|
|
35
|
+
found = true;
|
|
36
|
+
stream.on("data", (chunk) => {
|
|
37
|
+
snapshotText += chunk.toString("utf8");
|
|
38
|
+
});
|
|
39
|
+
stream.on("end", next);
|
|
40
|
+
stream.resume();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
stream.resume();
|
|
44
|
+
stream.on("end", next);
|
|
45
|
+
});
|
|
46
|
+
extract.on("finish", () => {
|
|
47
|
+
if (!found) {
|
|
48
|
+
reject(new Error("snapshot.json missing from archive"));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
resolve(JSON.parse(snapshotText));
|
|
52
|
+
});
|
|
53
|
+
extract.on("error", reject);
|
|
54
|
+
extract.end(tarBuffer);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { RemoveOptions, VfsNodeStats, WriteFileOptions } from "../types/vfs";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory virtual filesystem with tar.gz mirror persistence.
|
|
4
|
+
*
|
|
5
|
+
* Paths are normalized to POSIX-like absolute paths. Use
|
|
6
|
+
* {@link VirtualFileSystem.restoreMirror} on startup and
|
|
7
|
+
* {@link VirtualFileSystem.flushMirror} to persist pending changes.
|
|
8
|
+
*/
|
|
9
|
+
declare class VirtualFileSystem {
|
|
10
|
+
private readonly root;
|
|
11
|
+
private readonly archivePath;
|
|
12
|
+
private dirty;
|
|
13
|
+
private computeNodeUsageBytes;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a virtual filesystem instance.
|
|
16
|
+
*
|
|
17
|
+
* @param baseDir Base directory used to resolve mirror archive location.
|
|
18
|
+
*/
|
|
19
|
+
constructor(baseDir?: string);
|
|
20
|
+
/**
|
|
21
|
+
* Restores filesystem state from mirror archive.
|
|
22
|
+
*
|
|
23
|
+
* If archive does not exist or cannot be read, creates fresh mirror file.
|
|
24
|
+
*/
|
|
25
|
+
restoreMirror(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Persists current filesystem state to mirror archive.
|
|
28
|
+
*
|
|
29
|
+
* No-op when nothing changed and archive already exists.
|
|
30
|
+
*/
|
|
31
|
+
flushMirror(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates directory and any missing parent directories.
|
|
34
|
+
*
|
|
35
|
+
* @param targetPath Absolute or relative path to directory.
|
|
36
|
+
* @param mode POSIX-like mode bits for new directories.
|
|
37
|
+
*/
|
|
38
|
+
mkdir(targetPath: string, mode?: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Writes UTF-8 text or binary content into file.
|
|
41
|
+
*
|
|
42
|
+
* Parent directories are created when missing.
|
|
43
|
+
*
|
|
44
|
+
* @param targetPath Destination file path.
|
|
45
|
+
* @param content File content as string or Buffer.
|
|
46
|
+
* @param options Optional write behavior (mode, compression).
|
|
47
|
+
*/
|
|
48
|
+
writeFile(targetPath: string, content: string | Buffer, options?: WriteFileOptions): void;
|
|
49
|
+
/**
|
|
50
|
+
* Reads file content as UTF-8 text.
|
|
51
|
+
*
|
|
52
|
+
* Compressed files are transparently decompressed.
|
|
53
|
+
*
|
|
54
|
+
* @param targetPath Path to file.
|
|
55
|
+
* @returns UTF-8 string content.
|
|
56
|
+
*/
|
|
57
|
+
readFile(targetPath: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Checks whether node exists at path.
|
|
60
|
+
*
|
|
61
|
+
* @param targetPath Node path.
|
|
62
|
+
* @returns True when file or directory exists.
|
|
63
|
+
*/
|
|
64
|
+
exists(targetPath: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Updates mode bits for file or directory.
|
|
67
|
+
*
|
|
68
|
+
* @param targetPath Node path.
|
|
69
|
+
* @param mode New POSIX-like mode.
|
|
70
|
+
*/
|
|
71
|
+
chmod(targetPath: string, mode: number): void;
|
|
72
|
+
/**
|
|
73
|
+
* Returns metadata for file or directory.
|
|
74
|
+
*
|
|
75
|
+
* @param targetPath Node path.
|
|
76
|
+
* @returns Typed stat object based on node type.
|
|
77
|
+
*/
|
|
78
|
+
stat(targetPath: string): VfsNodeStats;
|
|
79
|
+
/**
|
|
80
|
+
* Lists direct children names of directory.
|
|
81
|
+
*
|
|
82
|
+
* @param dirPath Directory path, defaults to root.
|
|
83
|
+
* @returns Sorted child names.
|
|
84
|
+
*/
|
|
85
|
+
list(dirPath?: string): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Renders ASCII tree view of directory hierarchy.
|
|
88
|
+
*
|
|
89
|
+
* @param dirPath Directory path, defaults to root.
|
|
90
|
+
* @returns Multi-line tree string.
|
|
91
|
+
*/
|
|
92
|
+
tree(dirPath?: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Computes total stored file bytes under a path.
|
|
95
|
+
*
|
|
96
|
+
* File usage is based on in-memory stored bytes, including compressed
|
|
97
|
+
* payload size when files are marked as compressed.
|
|
98
|
+
*
|
|
99
|
+
* @param targetPath File or directory path to measure, defaults to root.
|
|
100
|
+
* @returns Total byte usage for file content under target path.
|
|
101
|
+
*/
|
|
102
|
+
getUsageBytes(targetPath?: string): number;
|
|
103
|
+
/**
|
|
104
|
+
* Compresses file content with gzip and flags node as compressed.
|
|
105
|
+
*
|
|
106
|
+
* @param targetPath Path to file.
|
|
107
|
+
*/
|
|
108
|
+
compressFile(targetPath: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Decompresses gzip-compressed file content.
|
|
111
|
+
*
|
|
112
|
+
* @param targetPath Path to file.
|
|
113
|
+
*/
|
|
114
|
+
decompressFile(targetPath: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Removes file or directory node.
|
|
117
|
+
*
|
|
118
|
+
* @param targetPath Path to remove.
|
|
119
|
+
* @param options Removal options, including recursive delete.
|
|
120
|
+
*/
|
|
121
|
+
remove(targetPath: string, options?: RemoveOptions): void;
|
|
122
|
+
/**
|
|
123
|
+
* Moves or renames node to destination path.
|
|
124
|
+
*
|
|
125
|
+
* @param fromPath Existing source path.
|
|
126
|
+
* @param toPath Destination path.
|
|
127
|
+
*/
|
|
128
|
+
move(fromPath: string, toPath: string): void;
|
|
129
|
+
}
|
|
130
|
+
export default VirtualFileSystem;
|
|
131
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/VirtualFileSystem/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,MAAM,cAAc,CAAC;AAOtB;;;;;;GAMG;AACH,cAAM,iBAAiB;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwB;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,KAAK,CAAS;IAEtB,OAAO,CAAC,qBAAqB;IAY7B;;;;OAIG;gBACS,OAAO,GAAE,MAAsB;IAa3C;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB3C;;;;OAIG;IACU,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAazC;;;;;OAKG;IACI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,GAAE,MAAc,GAAG,IAAI;IAiC5D;;;;;;;;OAQG;IACI,SAAS,CACf,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,GAAE,gBAAqB,GAC5B,IAAI;IAyCP;;;;;;;OAOG;IACI,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAU3C;;;;;OAKG;IACI,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAS1C;;;;;OAKG;IACI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAOpD;;;;;OAKG;IACI,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IA4B7C;;;;;OAKG;IACI,IAAI,CAAC,OAAO,GAAE,MAAY,GAAG,MAAM,EAAE;IAS5C;;;;;OAKG;IACI,IAAI,CAAC,OAAO,GAAE,MAAY,GAAG,MAAM;IAW1C;;;;;;;;OAQG;IACI,aAAa,CAAC,UAAU,GAAE,MAAY,GAAG,MAAM;IAKtD;;;;OAIG;IACI,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAc7C;;;;OAIG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAc/C;;;;;OAKG;IACI,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAiCpE;;;;;OAKG;IACI,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAsCnD;AAED,eAAe,iBAAiB,CAAC"}
|