# tar-pack

> Package and un-package modules of some sort (in tar/gz bundles).

Latest version **3.4.1** (published 2017-10-24) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install tar-pack
pnpm add tar-pack
yarn add tar-pack
bun add tar-pack
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.4.1 |
| Published | 2017-10-24 |
| First published | 2013-04-27 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+15 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 37 |
| Maintainers | es128, forbeslindesay, shinnn |

## Links

- npm: https://www.npmjs.com/package/tar-pack
- Repository: https://github.com/ForbesLindesay/tar-pack
- Homepage: https://github.com/ForbesLindesay/tar-pack#readme
- Issues: https://github.com/ForbesLindesay/tar-pack/issues
- npm.io page: https://npm.io/package/tar-pack

## Dependencies (8)

- [tar](https://npm.io/package/tar.md) ^2.2.1
- [once](https://npm.io/package/once.md) ^1.3.3
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [rimraf](https://npm.io/package/rimraf.md) ^2.5.1
- [fstream](https://npm.io/package/fstream.md) ^1.0.10
- [uid-number](https://npm.io/package/uid-number.md) ^0.0.6
- [fstream-ignore](https://npm.io/package/fstream-ignore.md) ^1.0.5
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.1.4

## Recent versions

- 3.4.1 (latest) — 2017-10-24
- 3.4.0 — 2016-12-14
- 3.3.0 — 2016-10-17
- 3.2.0 — 2016-10-17
- 3.1.4 — 2016-06-28
- 3.1.3 — 2016-02-08
- 3.1.2 — 2015-12-09
- 3.1.1 — 2015-12-06
- 3.1.0 — 2015-11-04
- 3.0.0 — 2015-11-04
- 2.0.1 — 2015-10-08
- 2.0.0 — 2013-06-21
- 1.0.0 — 2013-04-27

## README

# Tar Pack

Package and un-package modules of some sort (in tar/gz bundles).  This is mostly useful for package managers.  Note that it doesn't check for or touch `package.json` so it can be used even if that's not the way you store your package info.

[![Build Status](https://img.shields.io/travis/ForbesLindesay/tar-pack/master.svg)](https://travis-ci.org/ForbesLindesay/tar-pack)
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/tar-pack.svg)](https://david-dm.org/ForbesLindesay/tar-pack)
[![NPM version](https://img.shields.io/npm/v/tar-pack.svg)](https://www.npmjs.com/package/tar-pack)

## Installation

    $ npm install tar-pack

## API

### pack(folder|packer, [options])

Pack the folder at `folder` into a gzipped tarball and return the tgz as a stream.  Files ignored by `.gitignore` will not be in the package.

You can optionally pass a `fstream.DirReader` directly, instead of folder.  For example, to create an npm package, do:

```js
pack(require("fstream-npm")(folder), [options])
```

Options:

 - `noProprietary` (defaults to `false`) Set this to `true` to prevent any proprietary attributes being added to the tarball.  These attributes are allowed by the spec, but may trip up some poorly written tarball parsers.
 - `fromBase` (defaults to `false`) Set this to `true` to make sure your tarballs root is the directory you pass in.
 - `ignoreFiles` (defaults to `['.gitignore']`) These files can specify files to be excluded from the package using the syntax of `.gitignore`.  This option is ignored if you parse a `fstream.DirReader` instead of a string for folder.
 - `filter` (defaults to `entry => true`) A function that takes an entry and returns `true` if it should be included in the package and `false` if it should not.  Entryies are of the form `{path, basename, dirname, type}` where (type is "Directory" or "File").  This function is ignored if you parse a `fstream.DirReader` instead of a string for folder.

Example:

```js
var write = require('fs').createWriteStream
var pack = require('tar-pack').pack
pack(process.cwd())
  .pipe(write(__dirname + '/package.tar.gz'))
  .on('error', function (err) {
    console.error(err.stack)
  })
  .on('close', function () {
    console.log('done')
  })
```

### unpack(folder, [options,] cb)

Return a stream that unpacks a tarball into a folder at `folder`.  N.B. the output folder will be removed first if it already exists.

The callback is called with an optional error and, as its second argument, a string which is one of:

 - `'directory'`, indicating that the extracted package was a directory (either `.tar.gz` or `.tar`)
 - `'file'`, incating that the extracted package was just a single file (extracted to `defaultName`, see options)

Basic Options:

 - `defaultName` (defaults to `index.js`) If the package is a single file, rather than a tarball, it will be "extracted" to this file name, set to `false` to disable.

Advanced Options (you probably don't need any of these):

 - `gid` - (defaults to `null`) the `gid` to use when writing files
 - `uid` - (defaults to `null`) the `uid` to use when writing files
 - `dmode` - (defaults to `0777`) The mode to use when creating directories
 - `fmode` - (defaults to `0666`) The mode to use when creating files
 - `unsafe` - (defaults to `false`) (on non win32 OSes it overrides `gid` and `uid` with the current processes IDs)
 - `strip` - (defaults to `1`) Number of path segments to strip from the root when extracting
 - `keepFiles` - (defaults to `false`) Set this to `true` to prevent target directory to be removed. Extracted files overwrite existing files.

Example:

```js
var read = require('fs').createReadStream
var unpack = require('tar-pack').unpack
read(process.cwd() + '/package.tar.gz')
  .pipe(unpack(__dirname + '/package/', function (err) {
    if (err) console.error(err.stack)
    else console.log('done')
  }))
```

## License

  BSD

---
_Source: https://npm.io/package/tar-pack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
