Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fromJSON(fsJson: any) {
this.volume = new Volume();
this.fromJSONFixed(this.volume, fsJson);
// @ts-ignore
this.fs = createFsFromVolume(this.volume);
this.volume.releasedFds = [0, 1, 2];
const fdErr = this.volume.openSync("/dev/stderr", "w");
const fdOut = this.volume.openSync("/dev/stdout", "w");
const fdIn = this.volume.openSync("/dev/stdin", "r");
assert(fdErr === 2, `invalid handle for stderr: ${fdErr}`);
assert(fdOut === 1, `invalid handle for stdout: ${fdOut}`);
assert(fdIn === 0, `invalid handle for stdin: ${fdIn}`);
}
static async create(
containerFactory: (options: ContainerFactoryOptions) => Promise,
volume: Volume = new Volume(),
initialState: State = new State(),
console: Console = new Console()
): Promise {
const container = await containerFactory({ image: this.image, config: this.config });
const fs = await ContainerFS.fromJSON(container, {});
return new this(container, this.buildFs(volume, fs), console, initialState) as T;
}
}
constructor() {
this.volume = new Volume();
this.fs = createFsFromVolume(this.volume);
this.fromJSON({
"/dev/stdin": "",
"/dev/stdout": "",
"/dev/stderr": ""
});
}
constructor() {
this.volume = new Volume();
this.fs = createFsFromVolume(this.volume);
this.fromJSON({
"/dev/stdin": "",
"/dev/stdout": "",
"/dev/stderr": ""
});
}
Capsule.create = function (containerFactory, volume, initialState, console) {
if (volume === void 0) { volume = new volume_1.Volume(); }
if (initialState === void 0) { initialState = new state_1.default(); }
if (console === void 0) { console = new console_1.default(); }
return __awaiter(this, void 0, Promise, function () {
var container, fs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, containerFactory({ image: this.image, config: this.config })];
case 1:
container = _a.sent();
return [4 /*yield*/, container_1.ContainerFS.fromJSON(container, {})];
case 2:
fs = _a.sent();
return [2 /*return*/, new this(container, this.buildFs(volume, fs), console, initialState)];
}
});
});