tar 6.1.3 → 6.1.4

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/lib/extract.js CHANGED
@@ -6,6 +6,7 @@ const Unpack = require('./unpack.js')
6
6
  const fs = require('fs')
7
7
  const fsm = require('fs-minipass')
8
8
  const path = require('path')
9
+ const stripSlash = require('./strip-trailing-slashes.js')
9
10
 
10
11
  module.exports = (opt_, files, cb) => {
11
12
  if (typeof opt_ === 'function')
@@ -41,7 +42,7 @@ module.exports = (opt_, files, cb) => {
41
42
  // construct a filter that limits the file entries listed
42
43
  // include child entries if a dir is included
43
44
  const filesFilter = (opt, files) => {
44
- const map = new Map(files.map(f => [f.replace(/\/+$/, ''), true]))
45
+ const map = new Map(files.map(f => [stripSlash(f), true]))
45
46
  const filter = opt.filter
46
47
 
47
48
  const mapHas = (file, r) => {
@@ -55,8 +56,8 @@ const filesFilter = (opt, files) => {
55
56
  }
56
57
 
57
58
  opt.filter = filter
58
- ? (file, entry) => filter(file, entry) && mapHas(file.replace(/\/+$/, ''))
59
- : file => mapHas(file.replace(/\/+$/, ''))
59
+ ? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
60
+ : file => mapHas(stripSlash(file))
60
61
  }
61
62
 
62
63
  const extractFileSync = opt => {
package/lib/list.js CHANGED
@@ -9,6 +9,7 @@ const Parser = require('./parse.js')
9
9
  const fs = require('fs')
10
10
  const fsm = require('fs-minipass')
11
11
  const path = require('path')
12
+ const stripSlash = require('./strip-trailing-slashes.js')
12
13
 
13
14
  module.exports = (opt_, files, cb) => {
14
15
  if (typeof opt_ === 'function')
@@ -54,7 +55,7 @@ const onentryFunction = opt => {
54
55
  // construct a filter that limits the file entries listed
55
56
  // include child entries if a dir is included
56
57
  const filesFilter = (opt, files) => {
57
- const map = new Map(files.map(f => [f.replace(/\/+$/, ''), true]))
58
+ const map = new Map(files.map(f => [stripSlash(f), true]))
58
59
  const filter = opt.filter
59
60
 
60
61
  const mapHas = (file, r) => {
@@ -68,8 +69,8 @@ const filesFilter = (opt, files) => {
68
69
  }
69
70
 
70
71
  opt.filter = filter
71
- ? (file, entry) => filter(file, entry) && mapHas(file.replace(/\/+$/, ''))
72
- : file => mapHas(file.replace(/\/+$/, ''))
72
+ ? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
73
+ : file => mapHas(stripSlash(file))
73
74
  }
74
75
 
75
76
  const listFileSync = opt => {
@@ -0,0 +1,24 @@
1
+ // this is the only approach that was significantly faster than using
2
+ // str.replace(/\/+$/, '') for strings ending with a lot of / chars and
3
+ // containing multiple / chars.
4
+ const batchStrings = [
5
+ '/'.repeat(1024),
6
+ '/'.repeat(512),
7
+ '/'.repeat(256),
8
+ '/'.repeat(128),
9
+ '/'.repeat(64),
10
+ '/'.repeat(32),
11
+ '/'.repeat(16),
12
+ '/'.repeat(8),
13
+ '/'.repeat(4),
14
+ '/'.repeat(2),
15
+ '/',
16
+ ]
17
+
18
+ module.exports = str => {
19
+ for (const s of batchStrings) {
20
+ while (str.length >= s.length && str.slice(-1 * s.length) === s)
21
+ str = str.slice(0, -1 * s.length)
22
+ }
23
+ return str
24
+ }
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": "6.1.3",
5
+ "version": "6.1.4",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/npm/node-tar.git"