Repository navigation
v8.0.0
A new API. See "Migration from version 7" in the README.
Breaking changes
- Drop support for node <22
- Remove callbacks and Node.js streams. Each command returns a promise.
create()with nofilereturns a webReadableStream.list()andextract()read theinputoption, or afile. - Remove the
syncoption. UsecreateSync,extractSync,listSync,replaceSync, andupdateSync. - Rename
onReadEntrytoonEntry, which is awaited.onReadEntryandonentryare aliases of it. - The option aliases (
C,f,z,P,U,k,m,p,L,h,strip-components,keep-newer,keep-existing,no-mtime, their camelCase forms, andnoChmod) work in the commands only.entries(),Pack,Unpack, andParsertake only the names of the options. - Remove the options
noResume,ondone,dirCache,linkCache,readdirCache, andstatCache. ReadEntryandWriteEntryare not streams. AReadEntryhas the shape of aResponse:body,bytes(),arrayBuffer(),text(), andblob(). AWriteEntryis metadata and abody.Parser,Pack, andUnpackare not streams.Parseris a state machine withpush()andnext().Packis an async iterator of chunks.Unpackhas anextract(input)method.- Remove
WriteEntrySyncandWriteEntryTar. - Use
Uint8Array, notBuffer.Header#blockand the result ofPax#encode()are aUint8Array. transformreturns aTransformStream, or an object with areadableand awritableweb stream. InextractSync(), it returns a function that changes a chunk. For a Node.jsTransformstream, returncodecStream(stream).- In strict mode, extraction stops at the first error.
- The first null block is the end of the archive, as it is for bsdtar. Data after it is dropped with no warning, also when no second null block comes after it. Version 7 read the entries after a single null block, so it read archives that were joined end to end. Split such a file into its archives before you read it.
update()adds a file only if it is newer than the entry of the same path. It does not add a file that has the same time as the entry, or a time that differs only by a part of a second.- A
jobsormaxReadSizeoption that is not 0, a positive integer, orInfinityis aTypeError. 0 gives the default. - A
uidorgidoption ofextract()that is not an unsigned 32-bit integer is aTypeError. Before, it was ignored, and the owner in the archive was used. create()gives aTAR_ENTRY_UNSUPPORTEDwarning for a path that is not a file, a directory, or a symbolic link, such as a socket, a FIFO, or a device. Before, it skipped the path with no warning. Withstrict, it is an error.extract()withstripskips an entry that has no part of its path left, as GNU tar and bsdtar do. Before, a directory entry such aspackage/withstrip: 1set its mode, owner, and times on the extraction directory.- In
create(),replace(), andupdate(), a path that does not exist is aTAR_ENTRY_ERRORwarning, as it is for bsdtar. The other paths are added. Before, it was an error that stopped the command. Setstrictto get the error. extract()andlist()give aTAR_ENTRY_ERRORwarning for each path infilesthat no entry of the archive matches. Withstrict, it is an error after the archive is read.- The readers detect the compression format. The
brotliandzstdoptions are only forcreate(). - Remove the subpath exports (
tar/create,tar/extract,tar/parse, and the others). The exports aretar,tar/core,tar/raw, andtar/core/raw. - Remove all runtime dependencies:
minipass,minizlib,@isaacs/fs-minipass,chownr, andyallist.
New features
delete()anddeleteSync()remove entries from an archive file: the paths in a list, the entries that afilteraccepts, or both. The archive keeps its compression.- Add the
tar/coreentry point, the runtime-neutral core. It runs in a browser, a worker, or another runtime with web streams. It uses nonode:module, and it needs thefsandcwdoptions for work on files. It has no sync commands. taris the entry point for server-side runtimes: Node.js, and each other runtime that has thenode:modules. It has all of the core, the sync commands, and the defaults (node:fs,node:zlib, the working directory, the platform, and the user of the process).tar/rawandtar/core/raware the same two entry points as separate modules that are not minified.- Add the
fsoption. All file system work goes through it, so a caller can give another file system. - Add the
inputoption, andentries()andentriesSync(), which read aUint8Array, anArrayBuffer, aBlob, aReadableStream, or an iterable of chunks. - Add entries from memory to an archive: the file list of
create(),replace(), andupdate()takesWriteEntryobjects,ReadEntryobjects, and iterables of entries. - Add the
Codectype and thecodecsoption, to add a compression format.tarhas gzip, brotli, and zstd fromnode:zlib.tar/corehas gzip. create()writes the names of a directory in sorted order, so the archive is the same on each runtime and file system.list()andextract()with afiledo not read the body of an entry that nothing reads. A listing of an archive of large files reads only the headers.- Add the
compressoption ofcreate(). It takes aCodec, or[codec, options], and writes the archive with that codec. - The options
platform,processUid,processGid,processUname, andprocessUmaskgive the facts of the process totar/core. - In
tar/core, thecwdofcreate()and ofextract()must be an absolute path. A path that is not absolute is aTypeError. Thetarentry point makes a relativecwdabsolute first. - Nothing is read before the consumer asks for it: the readers read input, and
create()reads files, only on demand. - The async extraction writes up to 16 entries at one time (the
jobsoption). replace()andupdate()read PAX and GNU long name headers when they find the place to append, and refuse an archive in any known compressed format.- Export
CwdErrorandSymlinkError. create()reads thedevandinoof a file with more than one link asbigintvalues when the numbers are not safe integers. On Windows, two files can have the sameinonumber. Before, the second file was then written as a hard link to the first, and its content was lost. Withfollow, a directory gets the same exact values for the check that it is not in itself.- The error of
create()for a file that has fewer or more bytes than itslstatsize names the path and the size in its message. extract()works with acwdthat is a root of the file system, such as/orc:\.
Security fixes
- Refuse symbolic link targets that can resolve outside of the extraction directory: a
..after a named part, an entry path that ends in/., and a backslash in a directory name. (GHSA-3wwj-8j6r-q339, GHSA-mhqm-9wj8-w7r4, GHSA-6wwr-g865-f46r, GHSA-276f-qhr9-5cp8, GHSA-4pf9-5fpx-xmr6, GHSA-gvrf-jx37-rjv5, GHSA-7p36-m9mf-cxv7, GHSA-jmj2-9c5q-vw73, GHSA-wq85-w9p7-pgrm, GHSA-hqgx-p3r3-2cfg) - Read archives in the same way as other tar programs: PAX records are read by their length, PAX fields are applied one time and only to the entry that they describe, PAX numbers must be decimal safe integers, a PAX path wins over a GNU long name, and a NUL ends a name. (GHSA-jc4p-66g7-qw5h, GHSA-p96f-8xj2-g85p, GHSA-gfqm-vh67-375f, GHSA-5x5g-4v8m-wwwm, GHSA-xgqw-r6hj-48hf, GHSA-qv2w-fc3h-pm27, GHSA-ffhw-4r4q-5cwv, GHSA-rgjp-p5j7-w36x, GHSA-mpg7-vg3p-wc3m, GHSA-xv7h-rgq8-7m7v, GHSA-wpwg-r92p-fjjh, GHSA-wcpc-xj6c-qvf9, GHSA-vw2x-rj6h-gpcw, GHSA-345f-p9f6-2h8c)
- Remove the setuid, setgid, and sticky bits from the mode of each extracted entry, also with
chmod: true. (GHSA-3482-qrvx-gvgq, GHSA-m6rr-3gqh-4f88) - Limit the work that a small archive can cause:
maxDepthapplies to link targets, a path or link target of more than 32768 characters is refused, a link whose target is a parent or child of its path does not block the extraction, and data after the end of the archive is dropped. (GHSA-343g-5v7x-x325, GHSA-5qxq-cgm8-6j7r, GHSA-xm6h-2993-3ch9, GHSA-7c32-79xj-j3jp, GHSA-98v3-7xjr-fg83, GHSA-25mm-r35j-6hgm, GHSA-72fp-85cc-g945, GHSA-9239-v992-p74f) - Harden extraction against local races and bad state: a file descriptor is not used after it is closed, the times and the owner of a directory are set with
lutimesandlchown, and options and the data of a warning cannot come from a changedObject.prototype, in the commands and in each class. (GHSA-m6rr-3gqh-4f88, GHSA-5x73-x9rx-m7x2, GHSA-qf42-f7hw-qxrq) create()skips a file or directory that changes betweenlstatandopenorreaddir, and does not read it through a symbolic link. (GHSA-xj5v-fr6h-vw74)create()andreplace()report each error to the caller and close the archive file. (GHSA-8h4g-6p7x-m3c9)- The decompression ratio limit stops after about the permitted number of bytes, for each codec, and
replace()andupdate()skip an entry by its PAX size and ignore a PAX or GNU header that has no entry after it. (GHSA-p7rf-cx2m-qgrr, GHSA-9239-v992-p74f, GHSA-9hmx-4f52-v64x, GHSA-8h4g-6p7x-m3c9)
Bug fixes
- On Windows,
extract()withpreservePathssets the owner of each directory that it makes, not only of the last one. update()checks the paths in a directory also when the time of the directory did not change. A directory is always added again.- A path in the
filesoflist()andextract()matches an entry at each depth in that directory, not only 100 levels. create()does not write a file that has more than one link as a hard link to itself when its path is added two times.extract()keeps an existing directory for aGNUDumpDirentry, as it does for aDirectoryentry.- With two GNU long name headers before one entry, the readers use the last one, as GNU tar does.