Skip to content

Commit aa6728b

Browse files
committed
deps: tar@6.2.0
1 parent ce9089f commit aa6728b

File tree

8 files changed

+75
-25
lines changed

8 files changed

+75
-25
lines changed

node_modules/tar/lib/pack.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,26 @@ const Pack = warner(class Pack extends Minipass {
7979

8080
this.portable = !!opt.portable
8181
this.zip = null
82-
if (opt.gzip) {
83-
if (typeof opt.gzip !== 'object') {
84-
opt.gzip = {}
82+
83+
if (opt.gzip || opt.brotli) {
84+
if (opt.gzip && opt.brotli) {
85+
throw new TypeError('gzip and brotli are mutually exclusive')
8586
}
86-
if (this.portable) {
87-
opt.gzip.portable = true
87+
if (opt.gzip) {
88+
if (typeof opt.gzip !== 'object') {
89+
opt.gzip = {}
90+
}
91+
if (this.portable) {
92+
opt.gzip.portable = true
93+
}
94+
this.zip = new zlib.Gzip(opt.gzip)
95+
}
96+
if (opt.brotli) {
97+
if (typeof opt.brotli !== 'object') {
98+
opt.brotli = {}
99+
}
100+
this.zip = new zlib.BrotliCompress(opt.brotli)
88101
}
89-
this.zip = new zlib.Gzip(opt.gzip)
90102
this.zip.on('data', chunk => super.write(chunk))
91103
this.zip.on('end', _ => super.end())
92104
this.zip.on('drain', _ => this[ONDRAIN]())

node_modules/tar/lib/parse.js

+46-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ module.exports = warner(class Parser extends EE {
9797
this.strict = !!opt.strict
9898
this.maxMetaEntrySize = opt.maxMetaEntrySize || maxMetaEntrySize
9999
this.filter = typeof opt.filter === 'function' ? opt.filter : noop
100+
// Unlike gzip, brotli doesn't have any magic bytes to identify it
101+
// Users need to explicitly tell us they're extracting a brotli file
102+
// Or we infer from the file extension
103+
const isTBR = (opt.file && (
104+
opt.file.endsWith('.tar.br') || opt.file.endsWith('.tbr')))
105+
// if it's a tbr file it MIGHT be brotli, but we don't know until
106+
// we look at it and verify it's not a valid tar file.
107+
this.brotli = !opt.gzip && opt.brotli !== undefined ? opt.brotli
108+
: isTBR ? undefined
109+
: false
100110

101111
// have to set this so that streams are ok piping into it
102112
this.writable = true
@@ -347,7 +357,9 @@ module.exports = warner(class Parser extends EE {
347357
}
348358

349359
// first write, might be gzipped
350-
if (this[UNZIP] === null && chunk) {
360+
const needSniff = this[UNZIP] === null ||
361+
this.brotli === undefined && this[UNZIP] === false
362+
if (needSniff && chunk) {
351363
if (this[BUFFER]) {
352364
chunk = Buffer.concat([this[BUFFER], chunk])
353365
this[BUFFER] = null
@@ -356,15 +368,45 @@ module.exports = warner(class Parser extends EE {
356368
this[BUFFER] = chunk
357369
return true
358370
}
371+
372+
// look for gzip header
359373
for (let i = 0; this[UNZIP] === null && i < gzipHeader.length; i++) {
360374
if (chunk[i] !== gzipHeader[i]) {
361375
this[UNZIP] = false
362376
}
363377
}
364-
if (this[UNZIP] === null) {
378+
379+
const maybeBrotli = this.brotli === undefined
380+
if (this[UNZIP] === false && maybeBrotli) {
381+
// read the first header to see if it's a valid tar file. If so,
382+
// we can safely assume that it's not actually brotli, despite the
383+
// .tbr or .tar.br file extension.
384+
// if we ended before getting a full chunk, yes, def brotli
385+
if (chunk.length < 512) {
386+
if (this[ENDED]) {
387+
this.brotli = true
388+
} else {
389+
this[BUFFER] = chunk
390+
return true
391+
}
392+
} else {
393+
// if it's tar, it's pretty reliably not brotli, chances of
394+
// that happening are astronomical.
395+
try {
396+
new Header(chunk.slice(0, 512))
397+
this.brotli = false
398+
} catch (_) {
399+
this.brotli = true
400+
}
401+
}
402+
}
403+
404+
if (this[UNZIP] === null || (this[UNZIP] === false && this.brotli)) {
365405
const ended = this[ENDED]
366406
this[ENDED] = false
367-
this[UNZIP] = new zlib.Unzip()
407+
this[UNZIP] = this[UNZIP] === null
408+
? new zlib.Unzip()
409+
: new zlib.BrotliDecompress()
368410
this[UNZIP].on('data', chunk => this[CONSUMECHUNK](chunk))
369411
this[UNZIP].on('error', er => this.abort(er))
370412
this[UNZIP].on('end', _ => {
@@ -502,6 +544,7 @@ module.exports = warner(class Parser extends EE {
502544
this[UNZIP].end(chunk)
503545
} else {
504546
this[ENDED] = true
547+
if (this.brotli === undefined) chunk = chunk || Buffer.alloc(0)
505548
this.write(chunk)
506549
}
507550
}

node_modules/tar/lib/replace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = (opt_, files, cb) => {
2323
throw new TypeError('file is required')
2424
}
2525

26-
if (opt.gzip) {
26+
if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) {
2727
throw new TypeError('cannot append to compressed archives')
2828
}
2929

node_modules/tar/lib/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = (opt_, files, cb) => {
1313
throw new TypeError('file is required')
1414
}
1515

16-
if (opt.gzip) {
16+
if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) {
1717
throw new TypeError('cannot append to compressed archives')
1818
}
1919

node_modules/tar/package.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22
"author": "GitHub Inc.",
33
"name": "tar",
44
"description": "tar for node",
5-
"version": "6.1.15",
5+
"version": "6.2.0",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/isaacs/node-tar.git"
99
},
1010
"scripts": {
1111
"genparse": "node scripts/generate-parse-fixtures.js",
12-
"template-oss-apply": "template-oss-apply --force",
13-
"lint": "eslint \"**/*.js\"",
14-
"postlint": "template-oss-check",
15-
"lintfix": "npm run lint -- --fix",
1612
"snap": "tap",
17-
"test": "tap",
18-
"posttest": "npm run lint"
13+
"test": "tap"
1914
},
2015
"dependencies": {
2116
"chownr": "^2.0.0",

package-lock.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
"ssri": "^10.0.5",
154154
"strip-ansi": "^6.0.1",
155155
"supports-color": "^9.4.0",
156-
"tar": "^6.1.15",
156+
"tar": "^6.2.0",
157157
"text-table": "~0.2.0",
158158
"tiny-relative-date": "^1.3.0",
159159
"treeverse": "^3.0.0",
@@ -15648,9 +15648,9 @@
1564815648
}
1564915649
},
1565015650
"node_modules/tar": {
15651-
"version": "6.1.15",
15652-
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.15.tgz",
15653-
"integrity": "sha512-/zKt9UyngnxIT/EAGYuxaMYgOIJiP81ab9ZfkILq4oNLPFX50qyYmu7jRj9qeXoxmJHjGlbH0+cm2uy1WCs10A==",
15651+
"version": "6.2.0",
15652+
"resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz",
15653+
"integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==",
1565415654
"inBundle": true,
1565515655
"dependencies": {
1565615656
"chownr": "^2.0.0",
@@ -17106,7 +17106,7 @@
1710617106
"minimatch": "^9.0.0",
1710717107
"npm-package-arg": "^11.0.1",
1710817108
"pacote": "^17.0.4",
17109-
"tar": "^6.1.13"
17109+
"tar": "^6.2.0"
1711017110
},
1711117111
"devDependencies": {
1711217112
"@npmcli/eslint-config": "^4.0.0",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"ssri": "^10.0.5",
116116
"strip-ansi": "^6.0.1",
117117
"supports-color": "^9.4.0",
118-
"tar": "^6.1.15",
118+
"tar": "^6.2.0",
119119
"text-table": "~0.2.0",
120120
"tiny-relative-date": "^1.3.0",
121121
"treeverse": "^3.0.0",

workspaces/libnpmdiff/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"minimatch": "^9.0.0",
5555
"npm-package-arg": "^11.0.1",
5656
"pacote": "^17.0.4",
57-
"tar": "^6.1.13"
57+
"tar": "^6.2.0"
5858
},
5959
"templateOSS": {
6060
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",

0 commit comments

Comments
 (0)