# Changelog ## 8.1 - Add the `bigint` option of `create()`, `replace()`, `update()`, and `Pack`: each stat call has the option `{ bigint: true }`, so the `dev` and `ino` of each path are exact, with no added call. The default is true on Windows, where most `ino` numbers are not safe integers, and false on other systems. - On Windows, this default changes what a custom `fs` and a `filter` get. `lstat`, `stat`, and `stat` of the handle of a `CreateFS` get the option, and `lstat` and `stat` must give all the fields of `CreateBigIntStats`, or ignore the option. A `filter` gets a stat with numbers that is not the object of the file system. A time can be 1 ms less than before. Set `bigint: false` for the behavior of 8.0. - Keep the `mode` of the resulting archive consistent when running `tar.delete()`, when the `DeleteFS` includes a `chmod` method. - With the `unlink` option, extract each entry of a directory that replaces a file or a link. Before, two entries could replace the path at the same time, and one of them failed. - Extract an entry for the extraction directory, such as `./`, before the extraction of each entry after it starts. - With `preservePaths`, two entries that name one path in different forms, such as an absolute path and a relative path, do not run at the same time. ## 8.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 no `file` returns a web `ReadableStream`. `list()` and `extract()` read the `input` option, or a `file`. - Remove the `sync` option. Use `createSync`, `extractSync`, `listSync`, `replaceSync`, and `updateSync`. - Rename `onReadEntry` to `onEntry`, which is awaited. `onReadEntry` and `onentry` are 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, and `noChmod`) work in the commands only. `entries()`, `Pack`, `Unpack`, and `Parser` take only the names of the options. - Remove the options `noResume`, `ondone`, `dirCache`, `linkCache`, `readdirCache`, and `statCache`. - `ReadEntry` and `WriteEntry` are not streams. A `ReadEntry` has the shape of a `Response`: `body`, `bytes()`, `arrayBuffer()`, `text()`, and `blob()`. A `WriteEntry` is metadata and a `body`. - `Parser`, `Pack`, and `Unpack` are not streams. `Parser` is a state machine with `push()` and `next()`. `Pack` is an async iterator of chunks. `Unpack` has an `extract(input)` method. - Remove `WriteEntrySync` and `WriteEntryTar`. - Use `Uint8Array`, not `Buffer`. `Header#block` and the result of `Pax#encode()` are a `Uint8Array`. - `transform` returns a `TransformStream`, or an object with a `readable` and a `writable` web stream. In `extractSync()`, it returns a function that changes a chunk. For a Node.js `Transform` stream, return `codecStream(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 `jobs` or `maxReadSize` option that is not 0, a positive integer, or `Infinity` is a `TypeError`. 0 gives the default. - A `uid` or `gid` option of `extract()` that is not an unsigned 32-bit integer is a `TypeError`. Before, it was ignored, and the owner in the archive was used. - `create()` gives a `TAR_ENTRY_UNSUPPORTED` warning 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. With `strict`, it is an error. - `extract()` with `strip` skips an entry that has no part of its path left, as GNU tar and bsdtar do. Before, a directory entry such as `package/` with `strip: 1` set its mode, owner, and times on the extraction directory. - In `create()`, `replace()`, and `update()`, a path that does not exist is a `TAR_ENTRY_ERROR` warning, as it is for bsdtar. The other paths are added. Before, it was an error that stopped the command. Set `strict` to get the error. - `extract()` and `list()` give a `TAR_ENTRY_ERROR` warning for each path in `files` that no entry of the archive matches. With `strict`, it is an error after the archive is read. - The readers detect the compression format. The `brotli` and `zstd` options are only for `create()`. - Remove the subpath exports (`tar/create`, `tar/extract`, `tar/parse`, and the others). The exports are `tar`, `tar/core`, `tar/raw`, and `tar/core/raw`. - Remove all runtime dependencies: `minipass`, `minizlib`, `@isaacs/fs-minipass`, `chownr`, and `yallist`. ### New features - `delete()` and `deleteSync()` remove entries from an archive file: the paths in a list, the entries that a `filter` accepts, or both. The archive keeps its compression. - Add the `tar/core` entry point, the runtime-neutral core. It runs in a browser, a worker, or another runtime with web streams. It uses no `node:` module, and it needs the `fs` and `cwd` options for work on files. It has no sync commands. - `tar` is the entry point for server-side runtimes: Node.js, and each other runtime that has the `node:` 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/raw` and `tar/core/raw` are the same two entry points as separate modules that are not minified. - Add the `fs` option. All file system work goes through it, so a caller can give another file system. - Add the `input` option, and `entries()` and `entriesSync()`, which read a `Uint8Array`, an `ArrayBuffer`, a `Blob`, a `ReadableStream`, or an iterable of chunks. - Add entries from memory to an archive: the file list of `create()`, `replace()`, and `update()` takes `WriteEntry` objects, `ReadEntry` objects, and iterables of entries. - Add the `Codec` type and the `codecs` option, to add a compression format. `tar` has gzip, brotli, and zstd from `node:zlib`. `tar/core` has gzip. - `create()` writes the names of a directory in sorted order, so the archive is the same on each runtime and file system. - `list()` and `extract()` with a `file` do not read the body of an entry that nothing reads. A listing of an archive of large files reads only the headers. - Add the `compress` option of `create()`. It takes a `Codec`, or `[codec, options]`, and writes the archive with that codec. - The options `platform`, `processUid`, `processGid`, `processUname`, and `processUmask` give the facts of the process to `tar/core`. - In `tar/core`, the `cwd` of `create()` and of `extract()` must be an absolute path. A path that is not absolute is a `TypeError`. The `tar` entry point makes a relative `cwd` absolute 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 `jobs` option). - `replace()` and `update()` read PAX and GNU long name headers when they find the place to append, and refuse an archive in any known compressed format. - Export `CwdError` and `SymlinkError`. - `create()` reads the `dev` and `ino` of a file with more than one link as `bigint` values when the numbers are not safe integers. On Windows, two files can have the same `ino` number. Before, the second file was then written as a hard link to the first, and its content was lost. With `follow`, 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 its `lstat` size names the path and the size in its message. - `extract()` works with a `cwd` that is a root of the file system, such as `/` or `c:\`. ### 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, 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: `maxDepth` applies 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 `lutimes` and `lchown`, and options and the data of a warning cannot come from a changed `Object.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 between `lstat` and `open` or `readdir`, and does not read it through a symbolic link. (GHSA-xj5v-fr6h-vw74) - `create()` and `replace()` 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()` and `update()` 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) - The parser reads the same entries as GNU tar and bsdtar from an archive with a header that it refused before. The link name of an entry that is not a link is ignored, and such an entry has no `linkpath`. A link can have its target only in a PAX header or a GNU long link header. A meta header can have an empty name. After a header that is still refused, the body is skipped, and the next entry does not get the pending PAX fields and long names. (GHSA-qm2x-gh7j-rqqf) - The parser stops with a `TAR_BAD_ARCHIVE` error, also when `strict` is not set, when other tar programs can get a different size or name for an entry: a PAX header or a GNU long name entry that is larger than `maxMetaEntrySize` (it was skipped), a PAX record that is not valid, a PAX `size` that is not only decimal digits, two PAX headers or two GNU long names of the same kind for one entry, a GNU long name entry after a PAX header, a PAX `path` or `linkpath` after a GNU long name of the same kind, a `size`, `path`, or `linkpath` in a global PAX header, a prefix after a magic that starts with `ustar` and is not `ustar` and a NUL or the GNU magic, a size field that is not octal digits or a valid base-256 number, a size that is not 0 for a link, a device, a FIFO, or a volume header, a PAX size that is not 0 for a directory, and a size that is not 0 for an entry with a name that ends with a slash that is not a directory or a GNU dump directory. (GHSA-5mp5-f8vr-fwgg, GHSA-844h-fxvq-x544, GHSA-p4w4-63wp-74wq) - A number field of a header that is not valid base-256 has no value. The header was refused, and its body was read as headers. - A size field with no digits is 0, and `header.size` is 0. - PAX fields apply to an entry of each type that is not a PAX or GNU meta entry. They did not apply to an entry of a type that is not an object of a file system. - An entry of type `N` (`OldGnuLongPath`) is not a long name for the next entry, as in GNU tar and bsdtar. - `Pax.parse()` and `Pax.parseBytes()` throw at a record that is not valid and at a `size` that is not valid. A NUL where a record starts is the end of the records. ### Bug fixes - `create()` finds a file or a directory that is a different object after its `lstat` also when the two objects have the same `ino` number, as they can on Windows. For a directory, it checks the type again after `readdir`. For a file with numbers that are not safe integers, it compares the exact values of the handle and of the path. Before, it compared only the numbers, and it could read a symbolic link that replaced the path. `stat` of the handle and `fstatSync` can get the option `{ bigint: true }`. - The parser uses the prefix, `uname`, `gname`, `devmaj`, and `devmin` of a header with the magic `ustar` and a NUL, for each version. It used them only for the version `00`, and other tar programs do not check the version. (GHSA-8282-h5g3-523j) - An async extraction keeps one object for each part of a path, in place of one string for each parent path. A path with many parts and many characters used about 17 MB for each entry. The Unicode cache no longer keeps a path of more than 256 characters. (GHSA-7c32-79xj-j3jp) - `extract()` checks the parent directories of an entry again after it makes the entry. If another process replaced one of them with a symbolic link, the entry is a `TAR_ENTRY_ERROR` warning, and no content is written to a file. (GHSA-2wgf-wpj6-9qw5) - On Windows, `extract()` with `preservePaths` sets 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 `files` of `list()` and `extract()` 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 a `GNUDumpDir` entry, as it does for a `Directory` entry. ## 7.5 - Added `zstd` compression support. - Consistent TOCTOU behavior in sync t.list - Only read from ustar block if not specified in Pax - Fix sync tar.list when file size reduces while reading - Sanitize absolute linkpaths properly - Prevent writing hardlink entries to the archive ahead of their file target ## 7.4 - Deprecate `onentry` in favor of `onReadEntry` for clarity. ## 7.3 - Add `onWriteEntry` option ## 7.2 - DRY the command definitions into a single `makeCommand` method, and update the type signatures to more appropriately infer the return type from the options and arguments provided. ## 7.1 - Update minipass to v7.1.0 - Update the type definitions of `write()` and `end()` methods on `Unpack` and `Parser` classes to be compatible with the NodeJS.WritableStream type in the latest versions of `@types/node`. ## 7.0 - Drop support for node <18 - Rewrite in TypeScript, provide ESM and CommonJS hybrid interface - Add tree-shake friendly exports, like `import('tar/create')` and `import('tar/read-entry')` to get individual functions or classes. - Add `chmod` option that defaults to false, and deprecate `noChmod`. That is, reverse the default option regarding explicitly setting file system modes to match tar entry settings. - Add `processUmask` option to avoid having to call `process.umask()` when `chmod: true` (or `noChmod: false`) is set. ## 6.2 - Add support for brotli compression - Add `maxDepth` option to prevent extraction into excessively deep folders. ## 6.1 - remove dead link to benchmarks (#313) (@yetzt) - add examples/explanation of using tar.t (@isaacs) - ensure close event is emitted after stream has ended (@webark) - replace deprecated String.prototype.substr() (@CommanderRoot, @lukekarrys) ## 6.0 - Drop support for node 6 and 8 - fix symlinks and hardlinks on windows being packed with `\`-style path targets ## 5.0 - Address unpack race conditions using path reservations - Change large-numbers errors from TypeError to Error - Add `TAR_*` error codes - Raise `TAR_BAD_ARCHIVE` warning/error when there are no valid entries found in an archive - do not treat ignored entries as an invalid archive - drop support for node v4 - unpack: conditionally use a file mapping to write files on Windows - Set more portable 'mode' value in portable mode - Set `portable` gzip option in portable mode ## 4.4 - Add 'mtime' option to tar creation to force mtime - unpack: only reuse file fs entries if nlink = 1 - unpack: rename before unlinking files on Windows - Fix encoding/decoding of base-256 numbers - Use `stat` instead of `lstat` when checking CWD - Always provide a callback to fs.close() ## 4.3 - Add 'transform' unpack option ## 4.2 - Fail when zlib fails ## 4.1 - Add noMtime flag for tar creation ## 4.0 - unpack: raise error if cwd is missing or not a dir - pack: don't drop dots from dotfiles when prefixing ## 3.1 - Support `@file.tar` as an entry argument to copy entries from one tar file to another. - Add `noPax` option - `noResume` option for tar.t - win32: convert `>|