Giter Site home page Giter Site logo

tar-async's Introduction

Intro

Tar-async is an async approach to Tar in node.

Tar-async does not directly use the filesystem at all. This makes it really easy to use for practically anything. All that's required to tar something is a filename and data.

No compression is used, so an external compression library is necessary. This is by design and not likely to be implemented.

Example

Tar:

var Tar = require('tar-async'), // or require('tar-async').Tar or require('tar-async/tar')
	tape = new Tar({output: require('fs').createWriteStream('out.tar')});

tape.append('test.txt', 'Woohoo!! Tar me up Scotty!', function () {
	tape.close();
});

Simple huh? A Tar instance is an EventEmitter, and emits these events: 'end', 'data' (and maybe 'error' in the future)

Untar:

var Untar = require('tar-async/untar'), // or require('tar-async').Untar
	fs = require('fs'),
	untar = new Untar(function (err, header, fileStream) {
		console.log(header.filename);
		fileStream.on('data', function (data) {
			console.log(data.toString());
		});
	});

fs.createReadStream('out.tar').pipe(untar);

Untar is a Writable Stream, so it's pretty easy to asynchronously untar something.

API

Ok, so you want more detail. Here ya go:

Tar

Tar(opts)

Supported options include:

  • recordsPerBlock- number of records in a block, default is 20 (don't change unless you know what you're doing)
  • consolidate- default false; whether to consolidate everything into a single directory
  • normalize- default true; whether to normalize each file's path
  • output- default null; writable stream to stream output to
  • allowPipe- default false; allow Stream.pipe (this will cache the stream to get the size)

Tar.append(filepath, input, opts, callback):

  • filepath- filepath for file when extracted
  • input- string or Buffer
  • opts- optional options
    • mode- permissions on the file (default 777)
    • mtime- last modified time in seconds (default current time)
    • uid- owner id (default 0)
    • gid- group id (default 0)
    • size- size of output (default input.length; changing this could lead to bad results)
  • callback- optional callback; no parameters; called when a record is written

Untar

Untar(opts, callback)

  • opts
    • fileTypes- if not defined, defaults to normal and contiguous files; these are the options (any single one or an array of multiple ones)
      • 'normal'- normal file
      • 'hard-link'- hard link
      • 'symbolic-link'- symbolic link
      • 'character-special'- device files that moves data by characters; this type of file usually has a majorNumber and minorNumber
      • 'block-special'- device files that moves data in blocks; this type of file usually has a majorNumber and minorNumber
      • 'directory'- directory
      • 'fifo'- named pipe; doesn't have data
      • 'contiguous-file'- same as file, but it's allocated contiguously on disk
  • callback- callback each time a record is read; parameters are
    • err- only used when checksums don't match
    • header- header data (see header.js for details
    • fileStream- Readable Stream; chunks will be emitted as Buffer objects

tar-async's People

Contributors

dmcaulay avatar beatgammit avatar dmcaulay-3vr avatar

Watchers

Ben Sparks 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.