securityos/node_modules/wasi-js/dist/unzip.js

29 lines
1.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const fflate_1 = require("fflate");
function unzip({ data, fs, directory }) {
// const t0 = new Date().valueOf();
if (data instanceof ArrayBuffer) {
data = new Uint8Array(data);
}
if (!(data instanceof Uint8Array)) {
throw Error("impossible"); // was converted above. this is for typescript.
}
const z = (0, fflate_1.unzipSync)(data);
for (const [relativePath, content] of Object.entries(z)) {
const outputFilename = (0, path_1.join)(directory, relativePath);
fs.mkdirSync((0, path_1.dirname)(outputFilename), { recursive: true });
if (outputFilename.endsWith('/')) {
// it is a directory, not a file.
continue;
}
fs.writeFileSync(outputFilename, content);
fs.chmodSync(outputFilename, 0o777);
}
// console.log(
// `extract ${data.length / 10 ** 6} MB in ${new Date().valueOf() - t0}ms`
// );
}
exports.default = unzip;
//# sourceMappingURL=unzip.js.map