node.js - 节点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 软件。
解决方案
似乎 unzipper 不支持所有加密方法。这个问题产生了一个尚未开发的功能请求。
推荐阅读
- ios - 跨多个 MTKView 共享一个 MTLCommandBuffer
- python - LSTM keras,音乐MIDI生成,输出收敛到固定配置
- html - 如何使用 flex 创建自定义马赛克
- python - 基于另一个 DataFrame 的 DataFrame 的新列
- javascript - 如何将包含 javascript 库的脚本标签传递到 php 文件中
- css - 调整容器中的图像,无论是垂直还是水平,都保持纵横比
- http2 - 是否可以在 Akamai 中使用相同的域名测试 http/2 和 http/1.1?
- react-native - React Native iOS,如何使用我自己的 RCTBridgeDelegate.loadSource 方法调用 RCTBridge 的重新加载
- java - 使用 ADFS 的 CAS 委托身份验证
- python - np.einsum 4 矩阵乘法的性能