@molecule/api-code-sandbox-e2b 1.2.5 → 1.2.6
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/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +43 -8
- package/package.json +1 -1
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,qBAAqB,EAErB,aAAa,EAKb,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EAGf,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAGV,SAAS,EACT,oBAAoB,EAMrB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,qBAAqB,EAErB,aAAa,EAKb,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EAGf,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAGV,SAAS,EACT,oBAAoB,EAMrB,MAAM,YAAY,CAAA;AA+yBnB;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,IAAI,SAAQ;IAErB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0D;IACjF,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAsB;IAEtD;;;;;OAKG;gBACS,MAAM,GAAE,SAAc,EAAE,cAAc,CAAC,EAAE,oBAAoB;IAYzE;;;;OAIG;YACW,MAAM;IASpB;;;;;;;;;;;;;;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,EAAE,CAAC;IAmB/E;;;;;;;;;;OAUG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAevD;;;;;;;;;;;OAWG;IACG,YAAY,IAAI,OAAO,CAAC,aAAa,CAAC;IAwB5C;;;;;OAKG;YACW,YAAY;IAa1B;;;;;OAKG;YACW,WAAW;CA6B1B;AAED,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAA;IACf,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAA;IAClB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,CA8B1E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,GAAE,SAAc,EACtB,cAAc,CAAC,EAAE,oBAAoB,GACpC,kBAAkB,CAEpB;AAED,kEAAkE;AAClE,eAAO,MAAM,QAAQ,EAAE,eAAkC,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -128,6 +128,8 @@ function bareSnapshotName(snapshot) {
|
|
|
128
128
|
const withoutTag = full.includes(':') ? full.slice(0, full.lastIndexOf(':')) : full;
|
|
129
129
|
return withoutTag.includes('/') ? withoutTag.slice(withoutTag.lastIndexOf('/') + 1) : withoutTag;
|
|
130
130
|
}
|
|
131
|
+
/** How much of an incoming archive `importFiles` holds before spooling it into the sandbox. */
|
|
132
|
+
const IMPORT_PIECE_BYTES = 8 * 1024 * 1024;
|
|
131
133
|
/**
|
|
132
134
|
* Single-quote a value for POSIX `sh` so an arbitrary path is one argument.
|
|
133
135
|
*
|
|
@@ -653,14 +655,47 @@ class E2BSandbox {
|
|
|
653
655
|
* @param archive - POSIX tar byte stream to extract there.
|
|
654
656
|
*/
|
|
655
657
|
async importFiles(path, archive) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
|
|
658
|
+
// Spooled into the sandbox in bounded pieces: the archive is never held
|
|
659
|
+
// whole in this process (an uploaded tarball can inflate to gigabytes, and
|
|
660
|
+
// this process is shared by every tenant).
|
|
661
|
+
const tag = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
662
|
+
const tarPath = `/tmp/mol-import-${tag}.tar`;
|
|
663
|
+
const piecePath = `${tarPath}.piece`;
|
|
664
|
+
let pending = [];
|
|
665
|
+
let pendingBytes = 0;
|
|
666
|
+
let pieces = 0;
|
|
667
|
+
const flush = async () => {
|
|
668
|
+
if (pendingBytes === 0)
|
|
669
|
+
return;
|
|
670
|
+
const piece = Buffer.concat(pending);
|
|
671
|
+
pending = [];
|
|
672
|
+
pendingBytes = 0;
|
|
673
|
+
await this.sbx.files.write(piecePath, new Blob([piece]));
|
|
674
|
+
const r = await this.sbx.commands.run(`cat ${piecePath} ${pieces === 0 ? '>' : '>>'} ${tarPath} && rm -f ${piecePath}`, { timeoutMs: 120_000 });
|
|
675
|
+
if (r.exitCode !== 0) {
|
|
676
|
+
throw new Error(`importFiles: spooling the archive failed (${r.exitCode}): ${r.stderr.slice(0, 300)}`);
|
|
677
|
+
}
|
|
678
|
+
pieces++;
|
|
679
|
+
};
|
|
680
|
+
try {
|
|
681
|
+
for await (const chunk of archive) {
|
|
682
|
+
pending.push(chunk);
|
|
683
|
+
pendingBytes += chunk.length;
|
|
684
|
+
if (pendingBytes >= IMPORT_PIECE_BYTES)
|
|
685
|
+
await flush();
|
|
686
|
+
}
|
|
687
|
+
await flush();
|
|
688
|
+
if (pieces === 0)
|
|
689
|
+
await this.sbx.commands.run(`: > ${tarPath}`, { timeoutMs: 30_000 });
|
|
690
|
+
const r = await this.sbx.commands.run(`mkdir -p ${shellQuote(path)} && tar xf ${tarPath} -C ${shellQuote(path)} --no-same-owner --no-same-permissions`, { timeoutMs: 300_000 });
|
|
691
|
+
if (r.exitCode !== 0) {
|
|
692
|
+
throw new Error(`importFiles: tar extract failed (${r.exitCode}): ${r.stderr.slice(0, 300)}`);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
finally {
|
|
696
|
+
await this.sbx.commands
|
|
697
|
+
.run(`rm -f ${tarPath} ${piecePath}`, { timeoutMs: 30_000 })
|
|
698
|
+
.catch(() => undefined);
|
|
664
699
|
}
|
|
665
700
|
}
|
|
666
701
|
/**
|
package/package.json
CHANGED