📂
File System15M+/wkISC

tar

tar is the official npm package for reading, creating, and extracting tar archives in Node.js, supporting gzip, bzip2, xz, and zstd compression. As the package

Installation

npm
npm install tar
yarn
yarn add tar
pnpm
pnpm add tar

Import

ESM
import tar from 'tar';

Quick Example

usage
import tar from 'tar';

// Create a gzipped tar archive
await tar.create(
  { gzip: true, file: 'archive.tar.gz' },
  ['src/', 'package.json']
);

// Extract
await tar.extract({ file: 'archive.tar.gz', cwd: 'output/' });

// List contents
await tar.list({ file: 'archive.tar.gz', onentry: (e) => console.log(e.path) });

About tar

tar is the official npm package for reading, creating, and extracting tar archives in Node.js, supporting gzip, bzip2, xz, and zstd compression. As the package used by npm itself for packing and unpacking packages, tar is thoroughly tested and handles edge cases across all platforms. The library provides a streaming API where archives are created and extracted through Node.js stream pipelines, enabling memory-efficient processing of large archives. Key operations include tar.create() for creating archives, tar.extract() for extracting archives, tar.list() for listing contents, and tar.replace() for updating specific entries. The streaming design allows piping tar data directly from HTTP responses, through compression/decompression, and to the filesystem without intermediate files. tar handles long file paths (GNU and POSIX extensions), symbolic links, hard links, file permissions, owner/group information, and modification timestamps. The library supports filtering entries during creation or extraction through a filter function, stripping path components for extraction, and cwd for controlling base directory. tar provides both synchronous and asynchronous APIs. The package is essential for tools that work with npm packages, Docker layers, backup systems, and any application that needs to process tar archives.

Quick Facts

Packagetar
CategoryFile System
Weekly Downloads15M+
LicenseISC
Installnpm install tar

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.