Node.js 使用adm-zip/unzipper/yauzl解压在节点10中以静默方式失败
我一直在尝试向我的代码中添加一个用例,在这个用例中,我试图解压缩一个太大而无法放入磁盘空间的zip文件,我希望我的代码会抛出一个PC。我尝试了多个库,但没有一个库在没有完成压缩的情况下抛出错误,而不是默默地失败。我希望他们抛出一个PC错误,但是所有的包似乎都记录了第一个info语句,该语句声明解压已经开始,但之后什么都没有。他们中的大多数人都会创建不完整的文件夹,不管他们在磁盘空间用完之前能写什么。下面是我的代码对于每个库的外观 我的代码使用: 代码使用: 代码使用: 代码使用:Node.js 使用adm-zip/unzipper/yauzl解压在节点10中以静默方式失败,node.js,npm,unzip,adm-zip,Node.js,Npm,Unzip,Adm Zip,我一直在尝试向我的代码中添加一个用例,在这个用例中,我试图解压缩一个太大而无法放入磁盘空间的zip文件,我希望我的代码会抛出一个PC。我尝试了多个库,但没有一个库在没有完成压缩的情况下抛出错误,而不是默默地失败。我希望他们抛出一个PC错误,但是所有的包似乎都记录了第一个info语句,该语句声明解压已经开始,但之后什么都没有。他们中的大多数人都会创建不完整的文件夹,不管他们在磁盘空间用完之前能写什么。下面是我的代码对于每个库的外观 我的代码使用: 代码使用: 代码使用: 代码使用: 我的代码有问题
我的代码有问题吗?有什么特别的事件需要我听吗?在Yauzl和unzipper上都出现了一些线索和错误后,unzipper似乎可以工作(在解压缩过程中磁盘空间用完时抛出ENOSPC),代码如下
exports.unzip2 = function(source, destination) {
return new Promise(function(resolve, reject) {
console.info("Started un-zipping from source: %s to destination: %s", source, destination);
try {
var sourceStream = fs.createReadStream(source);
sourceStream.on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});
var destinationStream = unzipper.Extract({ path: destination });
destinationStream.on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});
destinationStream.on('close',function (){
console.log("Completed extract!");
resolve();
});
sourceStream.pipe(destinationStream).on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});;
} catch (error) {
console.error("something went wrong", err.code);
reject(new Error(err));
}
});
};
在Yauzl和unzipper上都出现了一些跟踪和错误之后,unzipper似乎可以使用以下代码工作(当解压缩过程中磁盘空间用完时抛出ENOSPC)
exports.unzip2 = function(source, destination) {
return new Promise(function(resolve, reject) {
console.info("Started un-zipping from source: %s to destination: %s", source, destination);
try {
var sourceStream = fs.createReadStream(source);
sourceStream.on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});
var destinationStream = unzipper.Extract({ path: destination });
destinationStream.on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});
destinationStream.on('close',function (){
console.log("Completed extract!");
resolve();
});
sourceStream.pipe(destinationStream).on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});;
} catch (error) {
console.error("something went wrong", err.code);
reject(new Error(err));
}
});
};
exports.unzip2 = function(source, destination) {
console.info("Started un-zipping from source: %s to destination: %s", source, destination);
try {
fs.createReadStream(source)
.pipe(unzipper.Extract({ path: destination }))
.on('error',function (err){
console.error("something went wrong", err.code);
throw err;
});
} catch (error) {
console.error("Unzipping failed. Reason: %s", error)
throw new Error(error)
}
};
exports.extractArchive = async function(source, destination) {
try {
extract(source, { dir: destination }, function (err) {
if (err) {
console.error("Something went wrong!", err.code);
throw err;
}
});
console.log('Extraction complete')
} catch (err) {
// handle any errors
}
};
exports.unzip2 = function(source, destination) {
return new Promise(function(resolve, reject) {
console.info("Started un-zipping from source: %s to destination: %s", source, destination);
try {
var sourceStream = fs.createReadStream(source);
sourceStream.on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});
var destinationStream = unzipper.Extract({ path: destination });
destinationStream.on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});
destinationStream.on('close',function (){
console.log("Completed extract!");
resolve();
});
sourceStream.pipe(destinationStream).on('error',function (err){
console.error("something went wrong", err.code);
reject(new Error(err));
});;
} catch (error) {
console.error("something went wrong", err.code);
reject(new Error(err));
}
});
};