Giter Site home page Giter Site logo

node-tar-to-zip's Introduction

tar-to-zip License NPM version Dependency Status Build Status Coverage Status

Convert tar and tar.gz archives to zip.

Global

tar-to-zip could be installed globally and used as tar-to-zip or tar2zip:

npm i tar-to-zip -g

Usage

Convert all tar.gz archives to zip in same directory:

tar2zip *.tar.gz

Make every program a filter

(c) Mike Gancarz: The UNIX Philosophy

Convert tar data from stdin and pipe it to stdout.

cat arc.tar | tar2zip > arc.zip

Local

tar-to-zip could be used localy. It will emit event on every file from converted archive.

Install

npm i tar-to-zip --save

API

tar-to-zip can work with filename and ReadableStream. When filename used tar-to-zip can emit progress of coverting (with options: {progress: true}).

tarToZip(filename, options)

  • filename - string name of the file
  • options - object with properties:
    • progress - whether emit progress event.
const tarToZip = require('tar-to-zip');
const fs = require('fs');
const {stdout} = process;
const onProgress = (n) => {
    stdout.write(`\r${n}`);
};

const onFinish = (e) => {
    stdout.write('\n');
};

const onError = ({message}) => {
    console.error(message)
};

const zip = fs.createWriteStream('file.zip');
const progress = true;

tarToZip('file.tar.gz', {progress})
    .on('progress', onProgress)
    .on('file', console.log)
    .on('error', onError);
    .getStream()
    .pipe(zip)
    .on('finish', onFinish);

tarToZip(stream)

  • stream - ReadableStream with tar data.
const tarToZip = require('tar-to-zip');
const fs = require('fs');
const {stdout} = process;
const onProgress = (n) => {
    stdout.write(`\r${n}`);
};
const onFinish = (e) => {
    stdout.write('\n');
};

const onError = ({message}) => {
    console.error(message)
};

const tar = fs.createReadStream('file.tar.gz');
const zip = fs.createWriteStream('file.zip');
const progress = true;

tarToZip(tar, {progress})
    .on('file', console.log)
    .on('error', onError);
    .getStream()
    .pipe(zip)
    .on('finish', onFinish);

Environments

In old node.js environments that not fully supports es2015, tar-to-zip could be used with:

var tarToZip = require('tar-to-zip/legacy');

Related

  • Jag - Pack files and folders with tar and gzip.
  • Jaguar - Pack and extract .tar.gz archives with emitter.
  • OneZip - Pack and extract zip archives with emitter.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.