Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tar-async

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tar-async

Creates tar files asynchronously in chunks

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132
increased by18.92%
Maintainers
0
Weekly downloads
 
Created
Source

Intro

Javascript implementation of the Tar archive utility. The goal is to make tar JavaScript friendly by incorporating such ideals as:

  • Evented IO with a 'data' event
  • Friendly function calls
  • Write to file or write to memory
  • Full JSLint complience and runs in Strict Mode
  • MIT Licensed

The Tar object is actually a NodeJS stream, and each chunk is written to a stream. The Tar object supports the usual events: data, error, end. This module can either be used stricly like the normal tar utility would be by piping the output to standard out, or the chunks can be used as they come.

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

Dependencies

The only external module that Tar uses is futures, and only the forEachAsync method at that. This module will add to the Array prototype, so stay away if that bothers you. This module is used to allow for graceful handling of asynchronous calls in a forEach loop. This module can be installed from npm:

npm install futures

Tar also requires the fs and stream modules.

Examples

To tar all of the files in a directory:

var Tar = require('./tar'),
    overrides = {
		owner: "jameson",
		group: "jameson"
	},
	tape = new Tar();

tape.addFiles("./", overrides, function (err) {
	if (err) {
		throw err;
	}
	tape.close();
});

tape.pipe(process.stdout);

To tar a bunch of random files together:

var Tar = require('./tar'),
	overrides = {
		owner: "jameson",
		group: "jameson"
	},
	tape = new Tar(),
	files;

files = [
	"./test.js",
	"./tar.js",
	"./header.js"
];

tape.addFiles(files, overrides, function (err) {
	if (err) {
		throw err;
	}
	tape.close();
});

tape.pipe(process.stdout);

Note, the "./" is not really necessary, but I do it for clarity. All files that are tarred will preserve the directory structure of the path of each file that was given. The addFiles method requires the full path on the file.

Source structure

header.js

Stores the header format and a method for formatting the header. The header is an array with two properties in each element:

  • field- Corresponds to a property of an object passed in to formatHeader
  • length- Length of this property in bytes

Each field in the header is a string of ASCII characters (one byte each).

tar.js

Exports a Tar object with several public methods:

  • constructor- Inherits from Stream and all arguments are passed to the Stream constructor
  • addFiles- adds a bunch of files to the tar recursively
  • append- Appends a file, nothing too exciting here...
  • addDirectory- adds files to the tar recursively

utils.js

Utilities to make life more convenient:

  • clean- Creates a 'clean' Buffer (zeroed)
  • pad- Stringifies the number and adds ASCII zeroes to the end (up to 12 zeroes) ** num- the number to stringify ** bytes- how long the resulting string should be ** base- default is base-8

Keywords

FAQs

Package last updated on 20 Mar 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc