tar 4.2.0 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/lib/header.js +2 -2
- package/lib/mkdir.js +0 -1
- package/lib/unpack.js +67 -19
- package/package.json +1 -1
- package/lib/.parse.js.swp +0 -0
package/README.md
CHANGED
|
@@ -316,6 +316,14 @@ The following options are supported:
|
|
|
316
316
|
`uid` option.
|
|
317
317
|
- `noMtime` Set to true to omit writing `mtime` value for extracted
|
|
318
318
|
entries. [Alias: `m`, `no-mtime`]
|
|
319
|
+
- `transform` Provide a function that takes an `entry` object, and
|
|
320
|
+
returns a stream, or any falsey value. If a stream is provided,
|
|
321
|
+
then that stream's data will be written instead of the contents of
|
|
322
|
+
the archive entry. If a falsey value is provided, then the entry is
|
|
323
|
+
written to disk as normal. (To exclude items from extraction, use
|
|
324
|
+
the `filter` option described above.)
|
|
325
|
+
- `onentry` A function that gets called with `(entry)` for each entry
|
|
326
|
+
that passes the filter.
|
|
319
327
|
|
|
320
328
|
The following options are mostly internal, but can be modified in some
|
|
321
329
|
advanced use cases, such as re-using caches between runs.
|
|
@@ -329,6 +337,11 @@ advanced use cases, such as re-using caches between runs.
|
|
|
329
337
|
- `maxMetaEntrySize` The maximum size of meta entries that is
|
|
330
338
|
supported. Defaults to 1 MB.
|
|
331
339
|
|
|
340
|
+
Note that using an asynchronous stream type with the `transform`
|
|
341
|
+
option will cause undefined behavior in sync extractions.
|
|
342
|
+
[MiniPass](http://npm.im/minipass)-based streams are designed for this
|
|
343
|
+
use case.
|
|
344
|
+
|
|
332
345
|
### tar.t(options, fileList, callback) [alias: tar.list]
|
|
333
346
|
|
|
334
347
|
List the contents of a tarball archive.
|
|
@@ -604,11 +617,27 @@ Most unpack errors will cause a `warn` event to be emitted. If the
|
|
|
604
617
|
`uid` option.
|
|
605
618
|
- `noMtime` Set to true to omit writing `mtime` value for extracted
|
|
606
619
|
entries.
|
|
620
|
+
- `transform` Provide a function that takes an `entry` object, and
|
|
621
|
+
returns a stream, or any falsey value. If a stream is provided,
|
|
622
|
+
then that stream's data will be written instead of the contents of
|
|
623
|
+
the archive entry. If a falsey value is provided, then the entry is
|
|
624
|
+
written to disk as normal. (To exclude items from extraction, use
|
|
625
|
+
the `filter` option described above.)
|
|
626
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
627
|
+
- `onentry` A function that gets called with `(entry)` for each entry
|
|
628
|
+
that passes the filter.
|
|
629
|
+
- `onwarn` A function that will get called with `(message, data)` for
|
|
630
|
+
any warnings encountered.
|
|
607
631
|
|
|
608
632
|
### class tar.Unpack.Sync
|
|
609
633
|
|
|
610
634
|
Synchronous version of `tar.Unpack`.
|
|
611
635
|
|
|
636
|
+
Note that using an asynchronous stream type with the `transform`
|
|
637
|
+
option will cause undefined behavior in sync unpack streams.
|
|
638
|
+
[MiniPass](http://npm.im/minipass)-based streams are designed for this
|
|
639
|
+
use case.
|
|
640
|
+
|
|
612
641
|
### class tar.Parse
|
|
613
642
|
|
|
614
643
|
A writable stream that parses a tar archive stream. All the standard
|
package/lib/header.js
CHANGED
package/lib/mkdir.js
CHANGED
package/lib/unpack.js
CHANGED
|
@@ -51,6 +51,8 @@ class Unpack extends Parser {
|
|
|
51
51
|
|
|
52
52
|
super(opt)
|
|
53
53
|
|
|
54
|
+
this.transform = typeof opt.transform === 'function' ? opt.transform : null
|
|
55
|
+
|
|
54
56
|
this.writable = true
|
|
55
57
|
this.readable = false
|
|
56
58
|
|
|
@@ -86,6 +88,10 @@ class Unpack extends Parser {
|
|
|
86
88
|
this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ?
|
|
87
89
|
process.getgid() : null
|
|
88
90
|
|
|
91
|
+
// mostly just for testing, but useful in some cases.
|
|
92
|
+
// Forcibly trigger a chown on every entry, no matter what
|
|
93
|
+
this.forceChown = opt.forceChown === true
|
|
94
|
+
|
|
89
95
|
// turn ><?| in filenames into 0xf000-higher encoded forms
|
|
90
96
|
this.win32 = !!opt.win32 || process.platform === 'win32'
|
|
91
97
|
|
|
@@ -222,7 +228,8 @@ class Unpack extends Parser {
|
|
|
222
228
|
[DOCHOWN] (entry) {
|
|
223
229
|
// in preserve owner mode, chown if the entry doesn't match process
|
|
224
230
|
// in set owner mode, chown if setting doesn't match process
|
|
225
|
-
return this.
|
|
231
|
+
return this.forceChown ||
|
|
232
|
+
this.preserveOwner &&
|
|
226
233
|
( typeof entry.uid === 'number' && entry.uid !== this.processUid ||
|
|
227
234
|
typeof entry.gid === 'number' && entry.gid !== this.processGid )
|
|
228
235
|
||
|
|
@@ -248,30 +255,45 @@ class Unpack extends Parser {
|
|
|
248
255
|
|
|
249
256
|
let actions = 1
|
|
250
257
|
const done = er => {
|
|
251
|
-
if (er)
|
|
252
|
-
this[ONERROR](er, entry)
|
|
253
|
-
actions = 1
|
|
254
|
-
}
|
|
258
|
+
if (er)
|
|
259
|
+
return this[ONERROR](er, entry)
|
|
255
260
|
|
|
256
261
|
if (--actions === 0)
|
|
257
262
|
fs.close(stream.fd, _ => this[UNPEND]())
|
|
258
263
|
}
|
|
259
264
|
|
|
260
265
|
stream.on('finish', _ => {
|
|
266
|
+
// if futimes fails, try utimes
|
|
267
|
+
// if utimes fails, fail with the original error
|
|
268
|
+
// same for fchown/chown
|
|
269
|
+
const abs = entry.absolute
|
|
270
|
+
const fd = stream.fd
|
|
271
|
+
|
|
261
272
|
if (entry.mtime && !this.noMtime) {
|
|
262
273
|
actions++
|
|
263
|
-
|
|
274
|
+
const atime = entry.atime || new Date()
|
|
275
|
+
const mtime = entry.mtime
|
|
276
|
+
fs.futimes(fd, atime, mtime, er =>
|
|
277
|
+
er ? fs.utimes(abs, atime, mtime, er2 => done(er2 && er))
|
|
278
|
+
: done())
|
|
264
279
|
}
|
|
265
280
|
|
|
266
281
|
if (this[DOCHOWN](entry)) {
|
|
267
282
|
actions++
|
|
268
|
-
|
|
283
|
+
const uid = this[UID](entry)
|
|
284
|
+
const gid = this[GID](entry)
|
|
285
|
+
fs.fchown(fd, uid, gid, er =>
|
|
286
|
+
er ? fs.chown(abs, uid, gid, er2 => done(er2 && er))
|
|
287
|
+
: done())
|
|
269
288
|
}
|
|
270
289
|
|
|
271
290
|
done()
|
|
272
291
|
})
|
|
273
292
|
|
|
274
|
-
|
|
293
|
+
const tx = this.transform ? this.transform(entry) || entry : entry
|
|
294
|
+
if (tx !== entry)
|
|
295
|
+
entry.pipe(tx)
|
|
296
|
+
tx.pipe(stream)
|
|
275
297
|
}
|
|
276
298
|
|
|
277
299
|
[DIRECTORY] (entry) {
|
|
@@ -427,7 +449,8 @@ class UnpackSync extends Unpack {
|
|
|
427
449
|
|
|
428
450
|
const oner = er => {
|
|
429
451
|
try { fs.closeSync(fd) } catch (_) {}
|
|
430
|
-
|
|
452
|
+
if (er)
|
|
453
|
+
this[ONERROR](er, entry)
|
|
431
454
|
}
|
|
432
455
|
|
|
433
456
|
let stream
|
|
@@ -437,8 +460,11 @@ class UnpackSync extends Unpack {
|
|
|
437
460
|
} catch (er) {
|
|
438
461
|
return oner(er)
|
|
439
462
|
}
|
|
463
|
+
const tx = this.transform ? this.transform(entry) || entry : entry
|
|
464
|
+
if (tx !== entry)
|
|
465
|
+
entry.pipe(tx)
|
|
440
466
|
|
|
441
|
-
|
|
467
|
+
tx.on('data', chunk => {
|
|
442
468
|
try {
|
|
443
469
|
fs.writeSync(fd, chunk, 0, chunk.length)
|
|
444
470
|
} catch (er) {
|
|
@@ -446,18 +472,40 @@ class UnpackSync extends Unpack {
|
|
|
446
472
|
}
|
|
447
473
|
})
|
|
448
474
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
475
|
+
tx.on('end', _ => {
|
|
476
|
+
let er = null
|
|
477
|
+
// try both, falling futimes back to utimes
|
|
478
|
+
// if either fails, handle the first error
|
|
479
|
+
if (entry.mtime && !this.noMtime) {
|
|
480
|
+
const atime = entry.atime || new Date()
|
|
481
|
+
const mtime = entry.mtime
|
|
482
|
+
try {
|
|
483
|
+
fs.futimesSync(fd, atime, mtime)
|
|
484
|
+
} catch (futimeser) {
|
|
485
|
+
try {
|
|
486
|
+
fs.utimesSync(entry.absolute, atime, mtime)
|
|
487
|
+
} catch (utimeser) {
|
|
488
|
+
er = futimeser
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
453
492
|
|
|
454
|
-
|
|
455
|
-
|
|
493
|
+
if (this[DOCHOWN](entry)) {
|
|
494
|
+
const uid = this[UID](entry)
|
|
495
|
+
const gid = this[GID](entry)
|
|
456
496
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
497
|
+
try {
|
|
498
|
+
fs.fchownSync(fd, uid, gid)
|
|
499
|
+
} catch (fchowner) {
|
|
500
|
+
try {
|
|
501
|
+
fs.chownSync(entry.absolute, uid, gid)
|
|
502
|
+
} catch (chowner) {
|
|
503
|
+
er = er || fchowner
|
|
504
|
+
}
|
|
505
|
+
}
|
|
460
506
|
}
|
|
507
|
+
|
|
508
|
+
oner(er)
|
|
461
509
|
})
|
|
462
510
|
}
|
|
463
511
|
|
package/package.json
CHANGED
package/lib/.parse.js.swp
DELETED
|
Binary file
|