【问题标题】:Unzip a password-protected archive using node-js使用 node-js 解压缩受密码保护的存档
【发布时间】:2018-07-26 19:01:14
【问题描述】:

我需要将受密码保护的存档(首选 zip)的内容读取到 node-js 应用程序,而不将受保护的内容写入文件

此外,该应用程序是跨平台的,因此this 之类的解决方案无济于事

我也看了here,但答案中没有代码

【问题讨论】:

    标签: node.js passwords unzip compression


    【解决方案1】:

    我能找到的唯一支持加密的库是:https://github.com/rf00/minizip-asm.js

    不幸的是,它没有得到很好的维护。

    【讨论】:

    • 这正是我选择的库
    【解决方案2】:

    此解决方案将读取您可以从 base64 获取的文件缓冲区或通过读取 zip 文件,然后在内存中解压缩并打开受密码保护的文件。我希望这会有所帮助 -

    const unzipper = require("unzipper");
    
    const unzipAndUnlockZipFileFromBuffer = async (zippedFileBase64, password) => {
      try {
        const zipBuffer = Buffer.from(zippedFileBase64, "base64"); // Change base64 to buffer
        const zipDirectory = await unzipper.Open.buffer(zipBuffer); // unzip a buffered file
        const file = zipDirectory.files[0]; // find the file you want
    
        // if you want to find a specific file by path
        // const file = zipDirectory.files.find((f) => f.path === "filename");
    
        const extracted = await file.buffer(password); // unlock the file with the password
    
        console.log(extracted.toString()); // file content
      } catch (e) {
        console.log(e);
      }
    };
    
    const zippedFileBase64 = "{{BASE64}}";
    const password = "1234";
    unzipAndUnlockZipFileFromBuffer(zippedFileBase64, password);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      相关资源
      最近更新 更多