I am trying to extract .rar files using node.js in windows 8.1. Is there any good way to do this?
Thanks in advance
I am trying to extract .rar files using node.js in windows 8.1. Is there any good way to do this?
Thanks in advance
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;
}
}
});
Please check unrar this may help
*This script tested on Linux Ubuntu
You can also use DecompressZip module for extracting zip/rar files.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";
}
});