Repository navigation
Conversation
Add an experimental tar reader to node:zlib, ported from fast-tar: listTar(), extractTar(), createTarExtractStream(), tarEntries(), their synchronous variants, and the TarParser they are built on. Signed-off-by: Matteo Collina <hello@matteocollina.com>
Add TarEntry.create(), createStream(), createSymlink() and createLink(), and createTarArchive(), createTarArchiveSync() and tarFiles() to write them, mirroring the ZIP creation API. Signed-off-by: Matteo Collina <hello@matteocollina.com>
This comment was marked as resolved.
This comment was marked as resolved.
|
Not public, and it does not need to be, sorry for the mistake. |
|
@nodejs/tsc this is a big PR and it needs your approval. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #67975 +/- ##
==========================================
+ Coverage 90.53% 90.63% +0.10%
==========================================
Files 805 817 +12
Lines 285915 292360 +6445
Branches 55213 56855 +1642
==========================================
+ Hits 258841 264981 +6140
- Misses 17186 17459 +273
- Partials 9888 9920 +32
🚀 New features to boost your workflow:
|
|
Have you read https://astral.sh/blog/tar-codec? It's a good overview of some of the pitfalls with tar parsing, and they have tests you could borrow. There's also this other large test suite. It recommends a policy of rejecting ambiguities in tar files that could make implementations extract different files, which I'd love to see node follow. (Alternatively, you could compile tar-codec to wasm and use that, instead of writing and maintaining your own. That approach has much to recommend it.) Edit: also I note that you added support for extracting to disk, which the zip support deliberately omitted. Nothing inherently wrong with that but a little odd for them to be asymmetric, and there's many more pitfalls when extracting rather than merely reading. I like the factoring in tar-codec, where there's a generic interface for archives and then a separate consumer of that interface for extracting; with that factoring you could make both tar and zip extract using the same code. |
Small files are read whole, several at a time, in input order. The compression option writes independent gzip members compressed on the thread pool. Signed-off-by: Matteo Collina <hello@matteocollina.com>
Directories have no body, a file whose path ends with a slash is a directory, numeric fields end at the first invalid byte, the last of a GNU long name and a pax path wins, global headers do not set paths, and entries without a path or with a misplaced link path are dropped. Signed-off-by: Matteo Collina <hello@matteocollina.com>
| @@ -1009,6 +1009,484 @@ changes: | |||
|
|
|||
| Decompress a raw deflate stream. | |||
|
|
|||
| ## Class: `zlib.TarEntry` | |||
There was a problem hiding this comment.
I do wonder if it was a mistake not to go with zlib/zip, zlib/tar, etc
| [`zlib.tarEntries()`][]. The static methods of this class create the entries | ||
| that [`zlib.createTarArchive()`][] writes. | ||
|
|
||
| The v7, ustar, pax and GNU formats are understood. Pax extended headers and GNU |
| string, decoded with `encoding`. **Default:** `'utf8'`. | ||
| * `skip()` Returns: {Promise} Fulfills once the rest of the content has been | ||
| skipped. | ||
| * `done` {boolean} `true` once the content has been read, or skipped, to its |
jasnell
left a comment
There was a problem hiding this comment.
I'm sure there's tons here that can be refined and I haven't gone through everything, but it's a start and as long as there are some good refinement passes before it graduates, LGTM
Adds experimental tar support to
node:zlib, next to the ZIP API: reading (listTar(),extractTar(),createTarExtractStream(),tarEntries(),TarParser) and writing (TarEntry.create*(),createTarArchive(),tarFiles()), with sync variants.tar is the basis of npm: every package is a tarball, so every install unpacks them and every publish creates one. Having it in core benefits the whole ecosystem.
The API is compatible with the one of node-tar: the extraction options (
cwd,strip,filter,preservePaths,preserveOwner,onwarn, ...) and the entry fields and type names are the same.AI generated, reviewed by me