我试图在Windows 8.1中使用node.js提取.rar文件。有没有好办法呢?
提前致谢
答案 0 :(得分:2)
var Unrar = require('unrar'),
fs = require('fs'),
archive = new Unrar('t.rar');
archive.list(function(err, entries) {
for (var i = 0; i < entries.length; i++) {
var name = entries[i].name;
var type = entries[i].type
if (type !== 'File') {
fs.mkdirSync(name)
}
}
for (var i = 0; i < entries.length; i++) {
var name = entries[i].name;
var type = entries[i].type;
if (type !== 'File') {
continue;
}
var stream = archive.stream(name);
try {
fs.writeFileSync(name, stream);
} catch (e) {
throw e;
}
}
});
请检查unrar这可能会有所帮助
*此脚本在Linux Ubuntu上进行了测试
答案 1 :(得分:1)
const unrarp = require('unrar-promise');
unrarp
.extractAll('rar-file-path', 'extract-directory')
.then(result => {
cb(null, result);
})
.catch(err => {
cb(err);
});
答案 2 :(得分:0)
您还可以使用DecompressZip模块提取zip / rar文件。Documentation and installation of Decompress-zip
var DecompressZip = require('decompress-zip');
var unzipper = new DecompressZip(filename)
unzipper.on('error', function (err) {
console.log('Caught an error');
});
unzipper.on('extract', function (log) {
console.log('Finished extracting');
});
unzipper.on('progress', function (fileIndex, fileCount) {
console.log('Extracted file ' + (fileIndex + 1) + ' of ' + fileCount);
});
unzipper.extract({
path: 'some/path',
filter: function (file) {
return file.type !== "SymbolicLink";
}
});