首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将非ZIP文件解压缩到磁盘上的文件?

将非ZIP文件解压缩到磁盘上的文件?
EN

Stack Overflow用户
提问于 2020-08-16 16:01:20
回答 2查看 363关注 0票数 0

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

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

例如,AdmZip (错误消息):

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

代码语言:javascript
复制
var AdmZip = require('adm-zip');
var admZip2 = new AdmZip("C:\\temp\\Test\\Microsoft_System.zip");
admZip2.extractAllTo("C:\\temp\\Test\\System", true)

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

你会怎么做?

您可以在这里下载.app文件:

RJzRCAOmam5dAt-9/view?usp=共享

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

(谢谢你的帮助:)

编辑:

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

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

编辑2:

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

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

代码语言:javascript
复制
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);
        };
    });
  });
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-16 20:05:47

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

链接(https://www.npmjs.com/package/jszip)

示例(提取)

代码语言:javascript
复制
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);
                });
            });
        });
    }
});
票数 1
EN

Stack Overflow用户

发布于 2020-08-16 20:01:26

该文件是附加到某种可执行文件的有效zip文件。最简单的方法是提取它,调用解压缩器,如unzipada.exe免费的开源软件可用的这里。预先生成的Windows可执行文件部分中的可执行文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63439023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档