Skip to content

Commit

Permalink
get: refactor out macos unzip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Dec 4, 2023
1 parent 4d4851a commit a34620e
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions src/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import yauzl from "yauzl-promise";

import util from "./util.js";

import "./nwbuild.js";
import streamp from "node:stream/promises";

/**
Expand Down Expand Up @@ -93,7 +92,6 @@ async function get({
ffmpeg = false,
nativeAddon = false,
}) {

await getNwjs({
version,
flavor,
Expand Down Expand Up @@ -147,6 +145,7 @@ const getNwjs = async ({
force: true,
});
}
console.log('we here');

if (fs.existsSync(out) === true) {
await fsm.rm(
Expand All @@ -156,10 +155,15 @@ const getNwjs = async ({
),
{ recursive: true, force: true },
);
await compressing[platform === "linux" ? "tgz" : "zip"].uncompress(
out,
cacheDir,
);
if (true) {

Check failure on line 158 in src/get.js

View workflow job for this annotation

GitHub Actions / e2e (macos-12, 21)

Unexpected constant condition
// if (platform === "osx" && process.platform === "darwin") {
await decompressOSX({ out, cacheDir });
} else {
await compressing[platform === "linux" ? "tgz" : "zip"].uncompress(
out,
cacheDir,
);
}

return;
}
Expand Down Expand Up @@ -224,27 +228,7 @@ const getNwjs = async ({
{ recursive: true, force: true },
);
if (platform === "osx" && process.platform === "darwin") {
const zip = await yauzl.open(out, {
supportMacArchive: false,
});
try {
for await (const entry of zip) {
const fullEntryPath = path.resolve(cacheDir, entry.filename);
if (entry.filename.endsWith("/")) {
await fsm.mkdir(fullEntryPath, { recursive: true });
} else {
await fsm.mkdir(path.dirname(fullEntryPath), { recursive: true });
const readStream = await entry.openReadStream();
const writeStream = fs.createWriteStream(fullEntryPath);
await streamp.pipeline(readStream, writeStream)
}
}
}
catch (e) {
console.error(e);
} finally {
await zip.close();
}
await decompressOSX({ out, cacheDir });
} else {
await compressing[platform === "linux" ? "tgz" : "zip"].uncompress(
out,
Expand Down Expand Up @@ -413,4 +397,26 @@ const getNodeHeaders = async ({
});
}

const decompressOSX = async ({ out, cacheDir }) => {
const zip = await yauzl.open(out);
try {
for await (const entry of zip) {
const fullEntryPath = path.resolve(cacheDir, entry.filename);
if (entry.filename.endsWith("/")) {
await fsm.mkdir(fullEntryPath, { recursive: true });
} else {
await fsm.mkdir(path.dirname(fullEntryPath), { recursive: true });
const readStream = await entry.openReadStream();
const writeStream = fs.createWriteStream(fullEntryPath);
await streamp.pipeline(readStream, writeStream)
}
}
}
catch (e) {
console.error(e);
} finally {
await zip.close();
}
}

export default get;

0 comments on commit a34620e

Please sign in to comment.