将非 ZIP 文件提取到磁盘上的文件?

Extract a non ZIP file to files on disk?

我得到了一个结构类似于 zip 文件的应用程序文件。 现在我想提取应用程序文件中的所有文件。

我试图在代码中将应用程序转换为 zip 文件(只需复制并粘贴为 zip 文件),但它是一个“SFX ZIP 存档”,node.js 中的大多数解压缩程序都可以已读。

例如 AdmZip(错误信息):

rejected promise not handled within 1 second: Error: Invalid CEN header (bad signature)

var AdmZip = require('adm-zip');
var admZip2 = new AdmZip("C:\temp\Test\Microsoft_System.zip");
admZip2.extractAllTo("C:\temp\Test\System", true)

所以现在我不知道如何处理它,因为我需要将所有 subfolder/subfiles 的文件解压到计算机上的特定文件夹中。

你会怎么做?

您可以在此处下载 .app 文件:

https://drive.google.com/file/d/1i7v_SsRwJdykhxu_rJzRCAOmam5dAt-9/view?usp=sharing

如果你打开它,你应该看到这样的东西:

感谢您的帮助:)

编辑:

我已经在使用 JSZip 将 zip 文件重新保存为普通的 ZIP 存档。但这是一个额外的步骤,需要一些时间。

也许有人知道如何使用 JSZip 将文件解压缩到某个路径:)

编辑 2:

仅供参考:这是一个 VS 代码扩展项目

编辑 3: 我得到了对我有用的东西。 对于我的解决方案,我使用了 Workers(因为并行)

var zip = new JSZip();
zip.loadAsync(data).then(async function (contents) {
zip.remove('SymbolReference.json');
zip.remove('[Content_Types].xml');
zip.remove('MediaIdListing.xml');
zip.remove('navigation.xml');
zip.remove('NavxManifest.xml');
zip.remove('Translations');
zip.remove('layout');
zip.remove('ProfileSymbolReferences');
zip.remove('addin');
zip.remove('logo');

//workerdata.files = Object.keys(contents.files)
//so you loop through contents.files and foreach file you get the dirname
//then check if the dir exists (create if not)
//after this you create the file with its content
//you have to rewrite some code to fit your code, because this whole code are
//from 2 files, hope it helps someone :)

Object.keys(workerData.files.slice(workerData.startIndex, workerData.endIndex)).forEach(function (filename, index) {
  workerData.zip.file(filename).async('nodebuffer').then(async function (content) {
    var destPath = path.join(workerData.baseAppFolderApp, filename);
    var dirname = path.dirname(destPath);

    // Create Directory if is doesn't exists
    await createOnNotExist(dirname);

    files[index] = false;
    fs.writeFile(destPath, content, async function (err) {
        // This is code for my logic
        files[index] = true;
        if (!files.includes(false)) {
            parentPort.postMessage(workerData);
        };
    });
  });
});

该文件是附加到某种可执行文件的有效 zip 文件。 最简单的方法是调用 unzipada.exe 之类的解压缩器来提取它 - 免费,open-source 软件可用 here。 Pre-built Windows 个可执行文件在“文件”部分可用。

jsZip 是一个用于使用 JavaScript 创建、读取和编辑 .zip 文件的库,具有可爱而简单的 API.

link (https://www.npmjs.com/package/jszip)

示例(提取)

var JSZip = require('JSZip');

fs.readFile(filePath, function(err, data) {
    if (!err) {
        var zip = new JSZip();
        zip.loadAsync(data).then(function(contents) {
            Object.keys(contents.files).forEach(function(filename) {
                zip.file(filename).async('nodebuffer').then(function(content) {
                    var dest = path + filename;
                    fs.writeFileSync(dest, content);
                });
            });
        });
    }
});