rar-to-zip is a batch rar file to zip file converter. It was written for converting tons of cbr comic files to CBZ.
I don't want to kick off an discussion about CBR vs CBZ: I know, that RAR has a slightly better compression rate than ZIP. But I see an advantage in the possibillity of extracting single files from an zip (extracting the first picture as cover or an meta data xml file and so on). Also the support of zip seems to be better, especially in Java/Android.
In this tool neither unrar nor zip is implemented in JavaScript. The "exec command" of node.js is used to call a function on your system. You must have an unrar and a zip tool in the path (or in the same directory of your node app).
You system mut have an unrar and a zip utility. Here you will find the nessesary information for an installation:
System | Tool | Comment |
---|---|---|
Windows | Unrar | UnRAR for Windows: Command line freeware Windows UnRAR. |
Windows | Zip | 7za.exe: 7-Zip für 32-bit Windows (See also 7-Zip command line examples) |
Mac OS X | Unrar | See Install command line RAR and UnRAR tools on Mac OS X |
Mac OS X | Zip | Zip is already preinstalled on Mac OS X, since OSX based on Unix. See zip manual page |
var r2z = require('rar-to-zip');
r2z.convert(rarFile, options, callback);
var r2z = require('./index.js');
var options = {
tmpDir: "out",
// Windows:
//execUnrarTemplate: "UnRAR x \"%s\" \"%s\"",
//execZipTemplate : "7za.exe a -r -tzip -mx0 \"%s\" \"%s\"",
// Mac OS X:
execUnrarTemplate: "unrar x \"%s\" \"%s\"",
execZipTemplate : "zip -r -0 %s %s",
zipSuffix : 'cbz',
skipIfZipAlreadyExists: false,
beforeCleanup: function(sourceFile, targetFile, tempDir){
console.log('Before cleanup');
}
};
var callback = function(err, newfile){
if (err) return console.error('Error:', err);
console.info('Created:', newfile);
};
r2z.convert('test/abc.rar', options, callback);
var r2z = require('rar-to-zip');
r2z.convertByGlob(pattern, options, callback);
var r2z = require('./index.js');
var options = {
tmpDir: "out",
// Windows:
//execUnrarTemplate: "UnRAR x \"%s\" \"%s\"",
//execZipTemplate : "7za.exe a -r -tzip -mx0 \"%s\" \"%s\"",
// Mac OS X:
execUnrarTemplate: "unrar x \"%s\" \"%s\"",
execZipTemplate : "zip -r -0 %s %s",
zipSuffix : 'cbz',
skipIfZipAlreadyExists: false
};
r2z.convertByGlob('test/**/*.*r', options, null);
Information about glob file pattern can be found here: Glob Primer.
Key | Possible values | Comment |
---|---|---|
silent | true / false (default) | true will skip logging (except errors) |
tmpDir | <String> path to tmp dir | if null, tmp dir will created automatically |
execUnrarTemplate | <String> | Template for exec command. Depends of used unrar util. Sample: 'UnRAR x "%s" "%s" ' (Windows) or 'unrar x "%s" "%s" ' (Mac) |
unrarEscapeSpaceInFileName | true / false (default) | if true, space characters in the two path/file names for the exec call will be escapes: "a b.rar" -> "a\ b.rar" |
execZipTemplate | <String> | Template for exec command. Depends of used zip util. Examples: '7za.exe a -r -tzip -mx0 "%s" '%s" ' (Windows) or 'zip -r -0 %s %s ' (Mac) |
zipEscapeSpaceInFileName | true / false (default) | default: Mac or Linux (true), windows (false) |
zipSuffix | <String> | Suffix of the target file: "cbz" : "abc.cbr" -> "abc.cbz" |
beforeCleanup | <function> | will be called before the temp directory is cleaned. function(sourceFile, targetFile, tempDir){} |
skipIfZipAlreadyExists | true / false (default | If true, an existing file will not be overwritten. |
// Display help for CLI:
node node_modules/rar-to-zip/index.js -h
// Explicit mode:
node node_modules/rar-to-zip/index.js -f test/abc.rar
node node_modules/rar-to-zip/index.js -f test/abc.rar -t out -Z "7za.exe a -r -tzip -mx0 \"%s\" \"%s\""
// glob mode:
node node_modules/rar-to-zip/index.js -g -p /Volumes/2TB/comics/**/*.*r -s cbr
node node_modules/rar-to-zip/index.js -g -p test/**/*.??r -t out -Z "7za.exe a -r -tzip -mx0 \"%s\" \"%s\""