Giter VIP home page Giter VIP logo

node-tar.gz's Introduction

tar.gz

Coverage Status Travis Dependencies

Pure gzip tarball tools and sugar for Node.js

API

  • createReadStream reads a directory and returns a readable stream containing a gzipped tarball.
var fs = require('fs');
var targz = require('tar.gz');

// Create all streams that we need
var read = targz().createReadStream('/some/directory');
var write = fs.createWriteStream('compressed.tar.gz');

// Let the magic happen
read.pipe(write);
  • createWriteStream writes the content from a tarball stream into some directory.
var request = require('request');
var targz = require('tar.gz');

// Streams
var read = request.get('https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz');
var write = targz().createWriteStream('/some/directory');

read.pipe(write);
  • createParseStream reads a tarball stream and emits entry for every entry parsed .
var request = require('request');
var targz = require('tar.gz');

// Streams
var read = request.get('https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz');
var parse = targz().createParseStream();

parse.on('entry', function(entry){
  console.log(entry.path);
});

read.pipe(parse);
  • compress compress one directory and saves the result to a tarball.
// Using callbacks
targz().compress('/home/myuser', '/bkp/backup.tar.gz', function(err){
  if(err)
    console.log('Something is wrong ', err.stack);

  console.log('Job done!');
});

// Using promises
targz().compress('/home/myuser', '/bkp/backup.tar.gz')
  .then(function(){
    console.log('Job done!');
  })
  .catch(function(err){
    console.log('Something is wrong ', err.stack);
  });
  • extract extracts a tarball into a directory.
// Using callbacks
targz().extract('/bkp/backup.tar.gz', '/home/myuser', function(err){
  if(err)
    console.log('Something is wrong ', err.stack);

  console.log('Job done!');
});

// Using promises
targz().extract('/bkp/backup.tar.gz', '/home/myuser')
  .then(function(){
    console.log('Job done!');
  })
  .catch(function(err){
    console.log('Something is wrong ', err.stack);
  });

Gzip options

You can pass any zlib.createGzip options to tar.gz constructor, like so:

var tarball = new TarGz({
  level: 9, // Maximum compression
  memLevel: 9
});

Tar options

You can pass any tar properties to tar.gz constructor in the second argument, like so:

var tarball = new TarGz({}, {
  fromBase: true // do not include top level directory
});

Command line

It's also possible to use tar.gz as a command line utility, you just need to install it globally with npm install -g tar.gz. Here is the help command output.

Usage: targz [options] [command]

Commands:

  extract|e <source> <target>             Extracts the source tarball into the target directory
  compress|c [options] <source> <target>  Compress the source directory into the target tarball
  list|l <source>                         List all paths inside the source tarball

Options:

  -h, --help     output usage information
  -V, --version  output the version number

Testing

git clone [email protected]:alanhoff/node-tar.gz.git
cd node-tar.gz
npm install && npm test

License (ISC)

Copyright (c) 2015-2016, Alan Hoffmeister <[email protected]>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

node-tar.gz's People

Contributors

alanhoff avatar fjmilens3 avatar germanbluefox avatar flockonus avatar kribblo avatar pdpi avatar iamwilhelm avatar kfurmann avatar

Watchers

Joris avatar James Cloos avatar

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.