@dhruv2mars/offdex 0.0.4 → 0.0.5

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.
Files changed (2) hide show
  1. package/bin/install-lib.js +36 -9
  2. package/package.json +1 -1
@@ -5,6 +5,7 @@ import http from "node:http";
5
5
  import https from "node:https";
6
6
  import { homedir } from "node:os";
7
7
  import { join } from "node:path";
8
+ import { gunzipSync } from "node:zlib";
8
9
 
9
10
  const REPO = "Dhruv2mars/offdex";
10
11
  const SUPPORTED_TARGETS = new Map([
@@ -58,6 +59,10 @@ export function checksumsAssetNameFor(platform = process.platform, arch = proces
58
59
  return `checksums-${platform}-${arch}.txt`;
59
60
  }
60
61
 
62
+ export function compressedAssetNameFor(platform = process.platform, arch = process.arch) {
63
+ return `${assetNameFor(platform, arch)}.gz`;
64
+ }
65
+
61
66
  export function resolveInstallRoot(env = process.env, home = homedir()) {
62
67
  return env.OFFDEX_INSTALL_ROOT || join(home, ".offdex");
63
68
  }
@@ -281,6 +286,7 @@ export async function installRuntime({
281
286
  const installBin = resolveInstalledBin(env, platform, home);
282
287
  const installMeta = resolveInstallMetaPath(env, home);
283
288
  const asset = assetNameFor(platform, arch);
289
+ const compressedAsset = compressedAssetNameFor(platform, arch);
284
290
  const checksumsAsset = checksumsAssetNameFor(platform, arch);
285
291
  const baseUrl = env.OFFDEX_RELEASE_BASE_URL
286
292
  || `https://github.com/${REPO}/releases/download/v${version}`;
@@ -293,21 +299,42 @@ export async function installRuntime({
293
299
  } catch {
294
300
  throw new Error(`failed_download:${checksumsAsset}`);
295
301
  }
296
- const expectedChecksum = parseChecksumForAsset(checksumsText, asset);
302
+ const expectedCompressedChecksum = parseChecksumForAsset(checksumsText, compressedAsset);
303
+ const expectedChecksum = expectedCompressedChecksum || parseChecksumForAsset(checksumsText, asset);
297
304
  if (!expectedChecksum) {
298
305
  throw new Error(`missing_checksum:${asset}`);
299
306
  }
300
307
 
301
308
  const tempPath = `${installBin}.download`;
302
309
  try {
303
- try {
304
- await downloadFn(`${baseUrl}/${asset}`, tempPath, 0, { onProgress });
305
- } catch {
306
- throw new Error(`failed_download:${asset}`);
307
- }
308
- const actualChecksum = createHash("sha256").update(readFileSync(tempPath)).digest("hex");
309
- if (actualChecksum !== expectedChecksum) {
310
- throw new Error(`checksum_mismatch:${asset}`);
310
+ if (expectedCompressedChecksum) {
311
+ const compressedPath = `${tempPath}.gz`;
312
+ try {
313
+ await downloadFn(`${baseUrl}/${compressedAsset}`, compressedPath, 0, { onProgress });
314
+ } catch {
315
+ throw new Error(`failed_download:${compressedAsset}`);
316
+ }
317
+ try {
318
+ const actualCompressedChecksum = createHash("sha256")
319
+ .update(readFileSync(compressedPath))
320
+ .digest("hex");
321
+ if (actualCompressedChecksum !== expectedCompressedChecksum) {
322
+ throw new Error(`checksum_mismatch:${compressedAsset}`);
323
+ }
324
+ await writeFile(tempPath, gunzipSync(readFileSync(compressedPath)));
325
+ } finally {
326
+ await rm(compressedPath, { force: true });
327
+ }
328
+ } else {
329
+ try {
330
+ await downloadFn(`${baseUrl}/${asset}`, tempPath, 0, { onProgress });
331
+ } catch {
332
+ throw new Error(`failed_download:${asset}`);
333
+ }
334
+ const actualChecksum = createHash("sha256").update(readFileSync(tempPath)).digest("hex");
335
+ if (actualChecksum !== expectedChecksum) {
336
+ throw new Error(`checksum_mismatch:${asset}`);
337
+ }
311
338
  }
312
339
  if (platform !== "win32") {
313
340
  await chmod(tempPath, 0o755);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhruv2mars/offdex",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Codex mobile bridge CLI for Offdex",
5
5
  "type": "module",
6
6
  "bin": {