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 install tar
yarn add tar
pnpm add tar
Import
import tar from 'tar';
Quick Example
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
| Package | tar |
| Category | File System |
| Weekly Downloads | 15M+ |
| License | ISC |
| Install | npm install tar |
Related Packages
Archiver is a streaming interface for generating archive files (ZIP, TAR, TAR.GZ) in Node.js. The li…
adm-zip is a pure JavaScript library for reading, creating, and extracting ZIP archives in Node.js w…
fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system …
rimraf is a Node.js implementation of the Unix rm -rf command, providing cross-platform recursive di…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.