freestyle-sync 0.1.7 → 0.1.8
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/src/main.js +12 -11
- package/package.json +1 -1
package/dist/src/main.js
CHANGED
|
@@ -22,7 +22,7 @@ const execFileAsync = promisify(execFile);
|
|
|
22
22
|
const CLI_NAME = "freestyle-sync";
|
|
23
23
|
const CACHE_VERSION = 1;
|
|
24
24
|
const PLUGIN_PREFERENCES_VERSION = 1;
|
|
25
|
-
const
|
|
25
|
+
const ARCHIVE_CHUNK_BYTES = 1024 * 1024;
|
|
26
26
|
const MS_PER_SECOND = 1000;
|
|
27
27
|
const DEFAULT_FREESTYLE_API_URL = "https://api.freestyle.sh";
|
|
28
28
|
const DEFAULT_STACK_API_URL = "https://api.stack-auth.com";
|
|
@@ -1392,20 +1392,18 @@ async function createTar(args) {
|
|
|
1392
1392
|
});
|
|
1393
1393
|
}
|
|
1394
1394
|
async function uploadArchiveInChunks(vm, vmId, archivePath, remoteArchivePath, label) {
|
|
1395
|
-
const
|
|
1396
|
-
const
|
|
1397
|
-
const chunkCount = Math.max(1, Math.ceil(encoded.length / ARCHIVE_CHUNK_CHARS));
|
|
1395
|
+
const archiveSize = (await stat(archivePath)).size;
|
|
1396
|
+
const chunkCount = Math.max(1, Math.ceil(archiveSize / ARCHIVE_CHUNK_BYTES));
|
|
1398
1397
|
const chunkDir = `/tmp/freestyle-sync-${label}-${Date.now()}.chunks`;
|
|
1399
|
-
console.log(`VM ${vmId}: streaming ${formatBytes(
|
|
1398
|
+
console.log(`VM ${vmId}: streaming ${formatBytes(archiveSize)} ${label} archive in ${chunkCount} chunk${chunkCount === 1 ? "" : "s"}...`);
|
|
1400
1399
|
await checkedExec(vm, `rm -rf ${shellQuote(chunkDir)} && mkdir -p ${shellQuote(chunkDir)}`);
|
|
1401
1400
|
const width = String(chunkCount - 1).length;
|
|
1402
1401
|
const canRenderInlineProgress = process.stdout.isTTY;
|
|
1403
1402
|
const logEvery = Math.max(1, Math.ceil(chunkCount / 4));
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
const
|
|
1407
|
-
|
|
1408
|
-
await vm.fs.writeTextFile(`${chunkDir}/${chunkName}`, chunk);
|
|
1403
|
+
let index = 0;
|
|
1404
|
+
for await (const chunk of createReadStream(archivePath, { highWaterMark: ARCHIVE_CHUNK_BYTES })) {
|
|
1405
|
+
const chunkName = `${String(index).padStart(width, "0")}.chunk`;
|
|
1406
|
+
await vm.fs.writeFile(`${chunkDir}/${chunkName}`, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
1409
1407
|
const uploadedChunks = index + 1;
|
|
1410
1408
|
if (chunkCount > 1) {
|
|
1411
1409
|
const progressMessage = `VM ${vmId}: uploaded ${uploadedChunks}/${chunkCount} ${label} archive chunks`;
|
|
@@ -1419,8 +1417,11 @@ async function uploadArchiveInChunks(vm, vmId, archivePath, remoteArchivePath, l
|
|
|
1419
1417
|
console.log(progressMessage);
|
|
1420
1418
|
}
|
|
1421
1419
|
}
|
|
1420
|
+
index += 1;
|
|
1422
1421
|
}
|
|
1423
|
-
await checkedExec(vm,
|
|
1422
|
+
await checkedExec(vm, archiveSize === 0
|
|
1423
|
+
? `: > ${shellQuote(remoteArchivePath)} && rm -rf ${shellQuote(chunkDir)}`
|
|
1424
|
+
: `cat ${shellQuote(chunkDir)}/*.chunk > ${shellQuote(remoteArchivePath)} && rm -rf ${shellQuote(chunkDir)}`);
|
|
1424
1425
|
}
|
|
1425
1426
|
async function mkdirRemote(vm, directories) {
|
|
1426
1427
|
for (const chunk of chunkArray(directories, 50)) {
|