tar 4.3.2 → 4.4.2

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 CHANGED
@@ -322,6 +322,8 @@ The following options are supported:
322
322
  the archive entry. If a falsey value is provided, then the entry is
323
323
  written to disk as normal. (To exclude items from extraction, use
324
324
  the `filter` option described above.)
325
+ - `onentry` A function that gets called with `(entry)` for each entry
326
+ that passes the filter.
325
327
 
326
328
  The following options are mostly internal, but can be modified in some
327
329
  advanced use cases, such as re-using caches between runs.
@@ -426,6 +428,8 @@ The following options are supported:
426
428
  Note that this prevents using other mtime-based features like
427
429
  `tar.update` or the `keepNewer` option with the resulting tar archive.
428
430
  [Alias: `m`, `no-mtime`]
431
+ - `mtime` Set to a `Date` object to force a specific `mtime` for
432
+ everything added to the archive. Overridden by `noMtime`.
429
433
 
430
434
  ### tar.r(options, fileList, callback) [alias: tar.replace]
431
435
 
@@ -475,6 +479,8 @@ The following options are supported:
475
479
  Note that this prevents using other mtime-based features like
476
480
  `tar.update` or the `keepNewer` option with the resulting tar archive.
477
481
  [Alias: `m`, `no-mtime`]
482
+ - `mtime` Set to a `Date` object to force a specific `mtime` for
483
+ everything added to the archive. Overridden by `noMtime`.
478
484
 
479
485
 
480
486
  ## Low-Level API
@@ -525,6 +531,8 @@ The following options are supported:
525
531
  - `noMtime` Set to true to omit writing `mtime` values for entries.
526
532
  Note that this prevents using other mtime-based features like
527
533
  `tar.update` or the `keepNewer` option with the resulting tar archive.
534
+ - `mtime` Set to a `Date` object to force a specific `mtime` for
535
+ everything added to the archive. Overridden by `noMtime`.
528
536
 
529
537
 
530
538
  #### add(path)
@@ -621,6 +629,11 @@ Most unpack errors will cause a `warn` event to be emitted. If the
621
629
  the archive entry. If a falsey value is provided, then the entry is
622
630
  written to disk as normal. (To exclude items from extraction, use
623
631
  the `filter` option described above.)
632
+ - `strict` Treat warnings as crash-worthy errors. Default false.
633
+ - `onentry` A function that gets called with `(entry)` for each entry
634
+ that passes the filter.
635
+ - `onwarn` A function that will get called with `(message, data)` for
636
+ any warnings encountered.
624
637
 
625
638
  ### class tar.Unpack.Sync
626
639
 
package/lib/buffer.js ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ // Buffer in node 4.x < 4.5.0 doesn't have working Buffer.from
4
+ // or Buffer.alloc, and Buffer in node 10 deprecated the ctor.
5
+ // .M, this is fine .\^/M..
6
+ let B = Buffer
7
+ /* istanbul ignore next */
8
+ if (!B.alloc) {
9
+ B = require('safe-buffer').Buffer
10
+ }
11
+ module.exports = B
package/lib/header.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // the data could not be faithfully encoded in a simple header.
5
5
  // (Also, check header.needPax to see if it needs a pax header.)
6
6
 
7
+ const Buffer = require('./buffer.js')
7
8
  const types = require('./types.js')
8
9
  const pathModule = require('path')
9
10
  const large = require('./large-numbers.js')
package/lib/list.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const Buffer = require('./buffer.js')
4
+
3
5
  // XXX: This shares a lot in common with extract.js
4
6
  // maybe some DRY opportunity here?
5
7
 
package/lib/pack.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const Buffer = require('./buffer.js')
4
+
3
5
  // A readable tar stream creator
4
6
  // Technically, this is a transform stream that you write paths into,
5
7
  // and tar format comes out of.
@@ -89,6 +91,7 @@ const Pack = warner(class Pack extends MiniPass {
89
91
  this.noDirRecurse = !!opt.noDirRecurse
90
92
  this.follow = !!opt.follow
91
93
  this.noMtime = !!opt.noMtime
94
+ this.mtime = opt.mtime || null
92
95
 
93
96
  this.filter = typeof opt.filter === 'function' ? opt.filter : _ => true
94
97
 
@@ -293,7 +296,8 @@ const Pack = warner(class Pack extends MiniPass {
293
296
  portable: this.portable,
294
297
  linkCache: this.linkCache,
295
298
  statCache: this.statCache,
296
- noMtime: this.noMtime
299
+ noMtime: this.noMtime,
300
+ mtime: this.mtime
297
301
  }
298
302
  }
299
303
 
package/lib/parse.js CHANGED
@@ -30,7 +30,7 @@ const Entry = require('./read-entry.js')
30
30
  const Pax = require('./pax.js')
31
31
  const zlib = require('minizlib')
32
32
 
33
- const gzipHeader = new Buffer([0x1f, 0x8b])
33
+ const gzipHeader = Buffer.from([0x1f, 0x8b])
34
34
  const STATE = Symbol('state')
35
35
  const WRITEENTRY = Symbol('writeEntry')
36
36
  const READENTRY = Symbol('readEntry')
package/lib/pax.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const Buffer = require('./buffer.js')
2
3
  const Header = require('./header.js')
3
4
  const path = require('path')
4
5
 
package/lib/replace.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const Buffer = require('./buffer.js')
2
3
 
3
4
  // tar -r
4
5
  const hlo = require('./high-level-opt.js')
package/lib/unpack.js CHANGED
@@ -12,6 +12,7 @@ const wc = require('./winchars.js')
12
12
 
13
13
  const ONENTRY = Symbol('onEntry')
14
14
  const CHECKFS = Symbol('checkFs')
15
+ const ISREUSABLE = Symbol('isReusable')
15
16
  const MAKEFS = Symbol('makeFs')
16
17
  const FILE = Symbol('file')
17
18
  const DIRECTORY = Symbol('directory')
@@ -49,8 +50,6 @@ class Unpack extends Parser {
49
50
  this[MAYBECLOSE]()
50
51
  }
51
52
 
52
- opt.onentry = entry => this[ONENTRY](entry)
53
-
54
53
  super(opt)
55
54
 
56
55
  this.transform = typeof opt.transform === 'function' ? opt.transform : null
@@ -122,6 +121,7 @@ class Unpack extends Parser {
122
121
  // default mode for dirs created as parents
123
122
  this.dmode = opt.dmode || (0o0777 & (~this.umask))
124
123
  this.fmode = opt.fmode || (0o0666 & (~this.umask))
124
+ this.on('entry', entry => this[ONENTRY](entry))
125
125
  }
126
126
 
127
127
  [MAYBECLOSE] () {
@@ -352,6 +352,17 @@ class Unpack extends Parser {
352
352
  entry.resume()
353
353
  }
354
354
 
355
+ // Check if we can reuse an existing filesystem entry safely and
356
+ // overwrite it, rather than unlinking and recreating
357
+ // Windows doesn't report a useful nlink, so we just never reuse entries
358
+ [ISREUSABLE] (entry, st) {
359
+ return entry.type === 'File' &&
360
+ !this.unlink &&
361
+ st.isFile() &&
362
+ st.nlink <= 1 &&
363
+ process.platform !== 'win32'
364
+ }
365
+
355
366
  // check if a thing is there, and if so, try to clobber it
356
367
  [CHECKFS] (entry) {
357
368
  this[PEND]()
@@ -361,7 +372,7 @@ class Unpack extends Parser {
361
372
  fs.lstat(entry.absolute, (er, st) => {
362
373
  if (st && (this.keep || this.newer && st.mtime > entry.mtime))
363
374
  this[SKIP](entry)
364
- else if (er || (entry.type === 'File' && !this.unlink && st.isFile()))
375
+ else if (er || this[ISREUSABLE](entry, st))
365
376
  this[MAKEFS](null, entry)
366
377
  else if (st.isDirectory()) {
367
378
  if (entry.type === 'Directory') {
@@ -423,7 +434,7 @@ class UnpackSync extends Unpack {
423
434
  const st = fs.lstatSync(entry.absolute)
424
435
  if (this.keep || this.newer && st.mtime > entry.mtime)
425
436
  return this[SKIP](entry)
426
- else if (entry.type === 'File' && !this.unlink && st.isFile())
437
+ else if (this[ISREUSABLE](entry, st))
427
438
  return this[MAKEFS](null, entry)
428
439
  else {
429
440
  try {
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const Buffer = require('./buffer.js')
2
3
  const MiniPass = require('minipass')
3
4
  const Pax = require('./pax.js')
4
5
  const Header = require('./header.js')
@@ -45,6 +46,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
45
46
  this.strict = !!opt.strict
46
47
  this.noPax = !!opt.noPax
47
48
  this.noMtime = !!opt.noMtime
49
+ this.mtime = opt.mtime || null
48
50
 
49
51
  if (typeof opt.onwarn === 'function')
50
52
  this.on('warn', opt.onwarn)
@@ -115,7 +117,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
115
117
  uid: this.portable ? null : this.stat.uid,
116
118
  gid: this.portable ? null : this.stat.gid,
117
119
  size: this.stat.size,
118
- mtime: this.noMtime ? null : this.stat.mtime,
120
+ mtime: this.noMtime ? null : this.mtime || this.stat.mtime,
119
121
  type: this.type,
120
122
  uname: this.portable ? null :
121
123
  this.stat.uid === this.myuid ? this.myuser : '',
@@ -128,7 +130,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
128
130
  atime: this.portable ? null : this.header.atime,
129
131
  ctime: this.portable ? null : this.header.ctime,
130
132
  gid: this.portable ? null : this.header.gid,
131
- mtime: this.noMtime ? null : this.header.mtime,
133
+ mtime: this.noMtime ? null : this.mtime || this.header.mtime,
132
134
  path: this.path,
133
135
  linkpath: this.linkpath,
134
136
  size: this.header.size,
@@ -318,7 +320,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
318
320
  this.uname = this.portable ? null : readEntry.uname
319
321
  this.gname = this.portable ? null : readEntry.gname
320
322
  this.size = readEntry.size
321
- this.mtime = this.noMtime ? null : readEntry.mtime
323
+ this.mtime = this.noMtime ? null : opt.mtime || readEntry.mtime
322
324
  this.atime = this.portable ? null : readEntry.atime
323
325
  this.ctime = this.portable ? null : readEntry.ctime
324
326
  this.linkpath = readEntry.linkpath
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
3
3
  "name": "tar",
4
4
  "description": "tar for node",
5
- "version": "4.3.2",
5
+ "version": "4.4.2",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/npm/node-tar.git"
@@ -17,21 +17,22 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "chownr": "^1.0.1",
20
- "fs-minipass": "^1.2.3",
21
- "minipass": "^2.2.1",
20
+ "fs-minipass": "^1.2.5",
21
+ "minipass": "^2.2.4",
22
22
  "minizlib": "^1.1.0",
23
23
  "mkdirp": "^0.5.0",
24
+ "safe-buffer": "^5.1.2",
24
25
  "yallist": "^3.0.2"
25
26
  },
26
27
  "devDependencies": {
27
28
  "chmodr": "^1.0.2",
28
- "end-of-stream": "^1.4.0",
29
+ "end-of-stream": "^1.4.1",
29
30
  "events-to-array": "^1.1.2",
30
31
  "mutate-fs": "^2.1.1",
31
32
  "rimraf": "^2.6.2",
32
- "tap": "^11.0.0-rc.3",
33
- "tar-fs": "^1.16.0",
34
- "tar-stream": "^1.5.2"
33
+ "tap": "^11.1.4",
34
+ "tar-fs": "^1.16.2",
35
+ "tar-stream": "^1.6.0"
35
36
  },
36
37
  "license": "ISC",
37
38
  "engines": {
Binary file