Scan your whole stack
Are you using tar?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v8.0.4
tar was last scanned on 30 Nov 2026 at version 8.0.4. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 8.0.4 LATEST | 30 Nov 2026 | No rules fired |
| 8.0.3 | 30 Nov 2026 | No rules fired |
| 8.0.2 | 28 Nov 2026 | No rules fired |
| 8.0.1 | 28 Nov 2026 | Not shown |
| 8.0.0 | 28 Nov 2026 | Not shown |
Findings for v8.0.4. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 8.0.4; other versions have their own rules, not their own score.
1 CRITICAL 15 HIGH 5 MEDIUM 0 LOW
Seal Security ships a patched build of this package. Its fixed versions:
The publisher’s own README, as collected from the registry.
Tar for JavaScript.
This package reads and writes tar archives. It makes archives from files or from data in memory. It extracts archives to a file system, or gives you the entries one at a time. It reads and writes gzip, and in a server-side runtime also brotli and zstd.
The package has two entry points:
tar is for server-side runtimes: Node.js, and each other runtime
that has the node: modules, such as Bun, Deno, and Cloudflare. It
uses node:fs and node:zlib, and it has sync commands. Most users
want this entry point.tar/core is for browsers and each other runtime. It uses no
node: module. It runs in a browser, in a worker, and in each
runtime that has web streams. It needs the fs option for work on
files.The package has no runtime dependencies. The API uses promises, web
streams, and Uint8Array.
npm install tar
tar needs Node.js 22 or later, or another server-side runtime that
has the node: modules. tar/core also runs in a browser.
The package has ES module and CommonJS builds. You can use import or
require().
These examples use tar, the server-side entry point. A command has two arguments: an options
object, and for most commands a list of files.
import { create } from 'tar'
// A gzip archive of a directory and a file.
await create({ file: 'demo.tgz', gzip: true }, ['src', 'package.json'])
With no file option, create() returns a ReadableStream of the
bytes of the archive.
import { createWriteStream } from 'node:fs'
import { Writable } from 'node:stream'
import { create } from 'tar'
const stream = create({ gzip: true }, ['src', 'package.json'])
await stream.pipeTo(Writable.toWeb(createWriteStream('demo.tgz')))
The directory to extract into must exist. The default is the current working directory.
import { mkdir } from 'node:fs/promises'
import { extract } from 'tar'
await mkdir('out', { recursive: true })
await extract({ file: 'archive.tgz', cwd: 'out' })
// Only some entries, with the first part of each path removed.
await extract({ file: 'archive.tgz', cwd: 'out', strip: 1 }, ['src/lib'])
The input option gives the archive as data. It can be a
Uint8Array, an ArrayBuffer, a Blob, a ReadableStream, or an
iterable of Uint8Array chunks.
import { mkdir } from 'node:fs/promises'
import { extract } from 'tar'
const res = await fetch('https://example.com/archive.tgz')
await mkdir('out', { recursive: true })
await extract({ input: res.body, cwd: 'out' })
import { list } from 'tar'
await list({
file: 'archive.tgz',
onEntry: entry => console.log(entry.type, entry.path, entry.size),
})
To read the content of the entries, use entries(). It is an async
iterator.
import { readFile } from 'node:fs/promises'
import { entries } from 'tar'
for await (const entry of entries(await readFile('archive.tgz'))) {
if (entry.path === 'package.json') {
console.log(JSON.parse(await entry.text()))
}
}
replace() adds entries to the end of an archive that is not
compressed. update() does the same, but it adds a file only if it
is newer than the entry of the same path in the archive.
import { replace, update } from 'tar'
await replace({ file: 'archive.tar' }, ['notes.txt'])
await update({ file: 'archive.tar' }, ['src', 'package.json'])
Each command of tar has a sync form. A sync command returns when
the work is done. tar/core has no sync commands.
import { mkdirSync } from 'node:fs'
import {
createSync,
extractSync,
listSync,
deleteSync,
replaceSync,
updateSync,
} from 'tar'
createSync({ file: 'demo.tar' }, ['src'])
replaceSync({ file: 'demo.tar' }, ['package.json'])
updateSync({ file: 'demo.tar' }, ['README.md'])
deleteSync({ file: 'demo.tar' }, ['package.json'])
listSync({
file: 'demo.tar',
onEntry: entry => console.log(entry.path),
})
mkdirSync('out', { recursive: true })
extractSync({ file: 'demo.tar', cwd: 'out' })
With no file option, createSync() returns an iterator of
Uint8Array chunks.
| Import | Use |
|---|---|
tar |
Server-side runtimes: Node.js, and each other runtime that has the node: modules (Bun, Deno, Cloudflare). All of the core, the defaults below, the sync commands, and the node:zlib codecs. |
tar/core |
Browsers, and each other runtime. The core: no node: module, no process, no Buffer. The async commands and the classes. It needs the fs option for work on files. |
tar/raw, tar/core/raw |
The same two entry points as separate modules that are not minified. |
tar and tar/core are each one minified file.
tarEach command of tar calls the command of the core with these
defaults:
| Option | Default in tar |
|---|---|
fs |
node:fs/promises. node:fs for a sync command. |
cwd |
process.cwd(). A relative cwd is resolved from it. |
platform |
'win32' if process.platform is 'win32'. If not, 'posix'. |
processUid |
process.getuid() |
processGid |
process.getgid() |
processUname |
process.env.USER |
processUmask |
process.umask(), only when chmod is set |
codecs |
Your codecs, then gzip, brotli, and zstd from node:zlib |
list() and entries() write no file. They get only the fs,
platform, and codecs defaults.
tar/core is the core. It does not know the file system, the working
directory, the platform, or the user of the process. You give them as
options.
The core needs these globals: ReadableStream, TransformStream,
Blob, TextEncoder, TextDecoder, and crypto.getRandomValues. It
needs CompressionStream and DecompressionStream for gzip.
A command of the core works with no fs option, if it does not touch
a file:
entries(input) and list({ input }) read archive data.create() with no file option, and with entries from memory,
returns a stream.This example reads an archive from a fetch() response. It stops the
download when it has the entry.
import { entries } from 'tar/core'
const res = await fetch('https://example.com/archive.tgz')
for await (const entry of entries(res.body)) {
if (entry.path === 'package.json') {
console.log(JSON.parse(await entry.text()))
break
}
}
This example makes a gzip archive in memory, and reads it from a
Blob. A File from a file input is also a Blob.
import { create, entries, WriteEntry } from 'tar/core'
const stream = create({ gzip: true }, [
new WriteEntry({ path: 'hello.txt' }, 'hello\n'),
new WriteEntry({ path: 'data.bin' }, new Uint8Array([1, 2, 3])),
])
const blob = await new Response(stream).blob()
for await (const entry of entries(blob)) {
console.log(entry.path, entry.size)
}
input optionlist() and extract() read the archive from input, or from the
path file through fs. entries() takes the input as its first
argument. The input can be:
Uint8Array or an ArrayBufferBlobReadableStream<Uint8Array>Uint8Array chunksA sync command takes a Uint8Array, an ArrayBuffer, or an iterable
of Uint8Array chunks.
The readers do not copy the input. Do not change a chunk after you give it.
When input is set, file is only the name of the archive. Warnings
have it, and the readers use it to find a format by the file name.
fs optionThe fs option is an object with file system functions. Each function
has the signature of the function of the same name in
node:fs/promises. For a sync command, it is the function of
node:fs. A command calls only the functions in its type.
| Type | Commands | Functions |
|---|---|---|
TarFS |
list() and extract() with file, and an @archive operand |
open(path, 'r'). The handle has read, stat, and close. |
ExtractFS |
extract() |
open, stat, lstat, mkdir, chmod, chown, lchown, utimes, lutimes, rmdir, unlink, rename, link, symlink. The handle has write, utimes, chown, and close. constants is optional. |
CreateFS |
create() |
open, lstat, stat, readdir, readlink. The handle has read, write, stat, and close. lstat and stat can get the option { bigint: true }. |
ReplaceFS |
replace(), update() |
The same as CreateFS. open gets the flags 'r+', 'w+', and 'r'. |
DeleteFS |
delete() |
TarFS and CreateFS, and rename and unlink. |
The sync types are TarFSSync, ExtractFSSync, CreateFSSync,
ReplaceFSSync, and DeleteFSSync. They have the functions of node:fs that work on a
file descriptor: openSync, fstatSync, readSync, writeSync,
futimesSync, fchownSync, closeSync, and the sync forms of the
path functions above.
Notes for an ExtractFS:
mkdir must fail if the path exists. lstat and stat must fail
if the path does not exist.fs.constants has O_CREAT, O_TRUNC, O_WRONLY, and
O_NOFOLLOW, then open gets a number as its flag. With
O_NOFOLLOW, open does not follow a symbolic link at the path.
Without constants, the flag is 'w'.chown and lchown are called only when the options set an owner.
chmod is called only with the chmod option. rename is called
only with platform: 'win32'.Notes for a CreateFS:
create() knows a file by the dev and ino numbers of its
stat. Node.js gives the two values as numbers. On Windows, most
ino values are too large for a number, and then two files can
have the same number.follow, a directory is skipped as a directory in itself. Only in
these cases, and only when dev or ino is not a safe integer,
create() calls lstat (stat with follow) one more time with
the option { bigint: true }, and reads the dev and ino of the
result. node:fs gives exact bigint values with this option.follow, never get
that call. The check that a path is the same object after open
and after readdir compares the numbers.create() then uses the numbers. Two files with the same
dev and ino numbers, and more than one link, are then one file
and a hard link to it.This example extracts an archive into a Map.
import { create, extract, WriteEntry } from 'tar/core'
// path -> { type, mode, mtime, chunks, target }
const tree = new Map([
['/out', { type: 'dir', mode: 0o755, mtime: new Date() }],
])
const fail = (code, path) =>
Object.assign(new Error(`${code}: ${path}`), { code })
const get = path => {
const node = tree.get(path)
if (!node) throw fail('ENOENT', path)
return node
}
const stats = node => ({
isDirectory: () => node.type === 'dir',
isFile: () => node.type === 'file',
isSymbolicLink: () => node.type === 'symlink',
nlink: 1,
mode: node.mode,
mtime: node.mtime,
})
const setTime = async (path, atime, mtime) => {
get(path).mtime = mtime
}
const memfs = {
stat: async path => stats(get(path)),
lstat: async path => stats(get(path)),
mkdir: async (path, { mode }) => {
if (tree.has(path)) throw fail('EEXIST', path)
tree.set(path, { type: 'dir', mode, mtime: new Date() })
return undefined
},
open: async (path, flags, mode) => {
const file = { type: 'file', mode, mtime: new Date(), chunks: [] }
tree.set(path, file)
return {
// `data` is a view into the archive data. Keep a copy.
write: async data => file.chunks.push(data.slice()),
utimes: async (atime, mtime) => {
file.mtime = mtime
},
chown: async () => {},
close: async () => {},
}
},
symlink: async (target, path) => {
tree.set(path, { type: 'symlink', mode: 0o777, target })
},
link: async (target, path) => {
tree.set(path, get(target))
},
unlink: async path => {
tree.delete(path)
},
rmdir: async path => {
tree.delete(path)
},
rename: async (from, to) => {
tree.set(to, get(from))
tree.delete(from)
},
chmod: async (path, mode) => {
get(path).mode = mode
},
chown: async () => {},
lchown: async () => {},
utimes: setTime,
lutimes: setTime,
}
const archive = create({}, [
new WriteEntry({ path: 'docs/', type: 'Directory', mode: 0o755 }),
new WriteEntry({ path: 'docs/hello.txt', mode: 0o644 }, 'hello\n'),
new WriteEntry({ path: 'docs/deep/more.txt' }, 'more\n'),
])
await extract({ input: archive, fs: memfs, cwd: '/out' })
for (const [path, node] of tree) console.log(node.type, path)
console.log(await new Blob(tree.get('/out/docs/hello.txt').chunks).text())
asar filesIn Electron, the fs module is changed: a file with a name that ends
in .asar is a directory. With that module, extract() does not
write an app.asar entry as a file, and create() reads the paths
in the asar file and not the file. Electron has the module
original-fs, which is node:fs with no change. Give it as the fs
option.
An async command needs the functions that return promises:
originalFs.promises. A sync command needs originalFs.
This example is for the main process of Electron. It is not tested, because the tests of this package do not run in Electron.
import originalFs from 'original-fs'
import { create, extract, extractSync } from 'tar'
await create({ file: 'app.tgz', gzip: true, fs: originalFs.promises }, [
'MyApp.app',
])
await extract({ file: 'app.tgz', cwd: 'out', fs: originalFs.promises })
extractSync({ file: 'app.tgz', cwd: 'out', fs: originalFs })
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.