首页 > 解决方案 > 节点js中的解压缩流“密码错误”问题

问题描述

我正在提取节点 js 中受密码保护的 zip,为此我正在使用解压缩节点模块。下面是我正在使用的代码。

const unzipper = require('unzipper');
const fs = require('fs');
const path = require('path');


async function checkPasswordValid(zipFilePath, password) {
    let directory = null;
    try {
        directory = await unzipper.Open.file(zipFilePath);
        return new Promise((resolve, reject) => {
            // console.log(directory.files[0].path)
            directory.files[0].stream(password)
                .on('error', (err) => {
                    console.log('I am heere too bro in error')
                    console.log(err.message);

                })
                .on("readable", () => {
                    console.log('I am heere too bro')

                })
        });
    }
    catch (err) {
        console.log('I am heere too bro in error in catch')
        console.log(err.message);
    }
}


let zpath = 'D:/NodeJs/upload/zip/text.zip';
let exPath = 'D:/NodeJs/upload/extractFile/';
let pass = 'DEXTER';
checkPasswordValid(zpath, pass) 

当我尝试使用密码手动打开 zip 时,它工作正常,但是当我使用与节点模块解压缩器相同的密码时,我遇到了以下错误。

I am heere too bro in error
BAD_PASSWORD
(node:6100) UnhandledPromiseRejectionWarning: #<Object>
(node:6100) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6100) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我不知道我在哪里做错了。代码对我来说看起来很完美,但不起作用。为了制作受密码保护的 zip,我在 Windows 10 上使用了 winrar 软件。

标签: node.jszipnode-modulesunzip

解决方案


似乎 unzipper 不支持所有加密方法。这个问题产生了一个尚未开发的功能请求。


推荐阅读