node-tar
Tar archive manipulation for Node.js with create, extract and list operations over streams and paths.
Official Documentation ↗node-tar v7.x / Node 18 LTS. Check the official docs for the latest API surface.Installation
npm install tarpnpm add taryarn add tarMethods
No methods match this filter.
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.
- (Note that most of these are disabled if preservePaths: true is set in the options.) - Paths that attempt to walk up outside of the extraction target are ignored, and a warning is raised. (https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md)
- (If sync or no file specified, providing a callback throws a TypeError.) If the command is sync (ie, if options.sync=true), then the callback is not allowed, since the action will be completed immediately. (https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md)
- Warnings and Errors Tar emits warnings and errors for recoverable and unrecoverable situations, respectively. (https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md)
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.
- There is no reasonable way to harden against this category of attack, and security reports about it will be closed. (https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md)
- Link files are historically the root of nearly every file extraction vulnerability. (https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md)
- If you find a security vulnerability in node-tar, where it is not properly enforcing the intended security protections, then please report it using the GitHub Security Advisories system, where it will be triaged and corrected if possible. (https://cdn.jsdelivr.net/gh/isaacs/node-tar@latest/README.md)
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.