npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rar-to-zip

v0.0.1

Published

Converts rar (cbr) to zip (cbz), batch mode and CLI

Downloads

10

Readme

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:

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

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

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.

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