API Reference

node-tar

Tar archive manipulation for Node.js with create, extract and list operations over streams and paths.

Official Documentation ↗
CompatibilityThis documentation covers version node-tar v7.x / Node 18 LTS. Check the official docs for the latest API surface.

Installation

npmnpm install tar
pnpmpnpm add tar
yarnyarn add tar

Methods

Overview

node-tar creates, extracts and lists tar archives, transparently handling gzip when configured. It works with files or streams and integrates with Node pipelines for backup and deployment tooling.

Core Methods

tar.c builds an archive from paths, tar.x extracts one, and tar.t lists entries. All accept a file path or operate as streams, and options control gzip, filters and working directory.

Usage Notes

Use filters to whitelist paths, keep path sanitization enabled for untrusted input, and stream archives when disk space is limited. Combine gzip with tar for typical .tgz backups.

Common Pitfalls

Extracting untrusted archives without path checks enables traversal writes outside the target directory. Forgetting to await an async tar call leaves partial archives. Mixing file and stream options can silently ignore one.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:52.998Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:52.998Z.

FAQ

How do I filter entries during extraction?
Pass a filter function in the options. It receives the entry path and stats and returns false to skip an entry, which is useful to block unsafe paths.
What about path traversal safety?
Extraction with preservePaths disabled strips leading slashes and parent traversal by default, protecting against zip-slip style attacks. Keep this default when extracting untrusted archives.
Can node-tar stream without writing to disk?
Yes. tar.c returns a stream when no file option is given, and tar.x accepts a readable stream, so you can pipe between a network socket and the archive.