boggan / unrar.js

Pure javascript unrar library. salvaged from bitjs
MIT License
6 stars 3 forks source link

unrar.js

This is a pure-javascript implementation of unrar. The code has been ported from Jeff Schiller's bitjs, Thanks :).

how to use:

synchronous usage:

var unrar = require('unrar.js'),
    fs = require('fs'),
    unpackedFiles;

unpackedFiles = unrar.unrarSync("ARCHIVE_PATH", {
    onProgress: function(data) {
        var l_nPercent = Math.round((data.currentBytesUnarchived / data.totalUncompressedBytesInArchive) * 100);
        console.log("Progress: ", l_nPercent, "%");
    }
});

unpackedFiles.forEach(function(file){
    console.log(file.filename, file.fileData.length);
});

asynchronous usage:

var unrar = require('unrar.js'),
    fs = require('fs');

unrar.unrar("ARCHIVE_PATH", "OUTPUT_DIRECTORY", {
    onProgress: function(data) {
        var l_nPercent = Math.round((data.currentBytesUnarchived / data.totalUncompressedBytesInArchive) * 100);
        console.log("Progress: ", l_nPercent, "%");
    }
}, function(err, unpackedFiles) {
    unpackedFiles.forEach(function(file){
        console.log(file.filename, file.fileData.length);
    });
});

the asynchronous method needs to write to disk because it runs in a child process, and transferring the binaries over a string channel is pretty damn slow. Maybe one day, I'll try using local sockets ;)

Changelog