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

问题描述

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

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

例如AdmZip(错误消息):

拒绝的承诺在1秒钟内未处理:错误:无效的CEN 标头(错误签名)

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

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

您将如何做?

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

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

如果打开它,应该会看到以下内容

App file in WinRar

感谢您的帮助:)

编辑:

我已经在使用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之类的解压缩程序-un here提供的免费开源软件。文件部分中提供了预构建的Windows可执行文件。

,

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

链接(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);
                });
            });
        });
    }
});