0.0.1 • Published 9 years ago

rar-to-zip v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

rar-to-zip

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).

Preparation / installation

You system mut have an unrar and a zip utility. Here you will find the nessesary information for an installation:

SystemToolComment
WindowsUnrarUnRAR for Windows: Command line freeware Windows UnRAR.
WindowsZip7za.exe: 7-Zip für 32-bit Windows (See also 7-Zip command line examples)
Mac OS XUnrarSee Install command line RAR and UnRAR tools on Mac OS X
Mac OS XZipZip is already preinstalled on Mac OS X, since OSX based on Unix. See zip manual page

Usage as script

Single Mode

var r2z = require('rar-to-zip'); 
r2z.convert(rarFile, options, callback);

Single Mode Example

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);

Glob Mode

var r2z = require('rar-to-zip'); 
r2z.convertByGlob(pattern, options, callback);

Glob Mode Example

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.

Options

KeyPossible valuesComment
silenttrue / false (default)true will skip logging (except errors)
tmpDir\ path to tmp dirif null, tmp dir will created automatically
execUnrarTemplate\Template for exec command. Depends of used unrar util. Sample: 'UnRAR x "%s" "%s" ' (Windows) or 'unrar x "%s" "%s" ' (Mac)
unrarEscapeSpaceInFileNametrue / 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\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)
zipEscapeSpaceInFileNametrue / false (default)default: Mac or Linux (true), windows (false)
zipSuffix\Suffix of the target file: "cbz" : "abc.cbr" -> "abc.cbz"
beforeCleanup\will be called before the temp directory is cleaned. function(sourceFile, targetFile, tempDir){}
skipIfZipAlreadyExiststrue / false (defaultIf true, an existing file will not be overwritten.

Usage as CLI

// 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\""