Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward compatibility #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const initProps = (props) => {
break;
case 1:
prop = "entryPoint";
propObj.entryPoint = props[idx].replaceAll(`"`, "");
propObj.entryPoint = props[idx].replace(/"/g, "");
break;
case 2:
prop = "symlinks";
Expand All @@ -40,7 +40,7 @@ const initProps = (props) => {
propObj.doCompress = Number(props[idx]);
break;
}
} catch {
} catch (e) {
throw new Error(
`Error while parsing the binary props! ${READ_ERR}\nParsing ${prop} at index ${idx}`
);
Expand All @@ -56,11 +56,11 @@ if (!argv.i || !argv.o)
throw new Error("You need to provide an input file and an output directory!");

const binary = fs.readFileSync(argv.i, { encoding: "utf-8" });
let rawProps = binary.match(/\{.*}\n,\n".*"\n,\n\{.*}\n,\n\{.*}\n,\n([012])/g);
let rawProps = binary.match(/\{.*}\n,\n".*"/g);

try {
rawProps = rawProps[0].split("\n,\n");
} catch {
} catch (e) {
throw new Error(`Error while reading the binary props! ${READ_ERR}`);
}

Expand Down Expand Up @@ -240,17 +240,34 @@ const getFile = (fd, [startPos, size]) => {
try {
if (DOCOMPRESS === GZIP) code = gunzipSync(code);
else if (DOCOMPRESS === BROTLI) code = brotliDecompressSync(code);
} catch {}
} catch (e) {}

return code;
};

const mkdirRecursiveSync = (targetDir) => {
const sep = path.sep; // path separator (usually '\' on Windows and '/' on Linux)
const initDir = path.isAbsolute(targetDir) ? sep : ''; // if the path is absolute, start from root, else empty string
const baseDir = '.';

// Split the path and reduce through it, creating one directory at a time
targetDir.split(sep).reduce((parentDir, childDir) => {
const currentDir = path.resolve(parentDir, childDir);

if (!fs.existsSync(currentDir)) {
fs.mkdirSync(currentDir);
}

return currentDir;
}, initDir || baseDir);
}

const writeFile = (vfsPath, outputPath, blob) => {
if (vfsPath.startsWith("C:")) vfsPath = vfsPath.replace("C:", "");

outputPath = path.join(path.resolve(outputPath), vfsPath);

if (!fs.existsSync(outputPath)) fs.mkdirSync(path.dirname(outputPath), { recursive: true });
if (!fs.existsSync(outputPath)) mkdirRecursiveSync(path.dirname(outputPath));

fs.writeFileSync(outputPath, blob);
};
Expand Down