tar 6.2.1 → 7.0.1
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 +30 -16
- package/dist/commonjs/create.d.ts +8 -0
- package/dist/commonjs/create.d.ts.map +1 -0
- package/dist/commonjs/create.js +106 -0
- package/dist/commonjs/create.js.map +1 -0
- package/dist/commonjs/cwd-error.d.ts +8 -0
- package/dist/commonjs/cwd-error.d.ts.map +1 -0
- package/dist/commonjs/cwd-error.js +18 -0
- package/dist/commonjs/cwd-error.js.map +1 -0
- package/dist/commonjs/extract.d.ts +8 -0
- package/dist/commonjs/extract.d.ts.map +1 -0
- package/dist/commonjs/extract.js +141 -0
- package/dist/commonjs/extract.js.map +1 -0
- package/dist/commonjs/get-write-flag.d.ts +2 -0
- package/dist/commonjs/get-write-flag.d.ts.map +1 -0
- package/dist/commonjs/get-write-flag.js +29 -0
- package/dist/commonjs/get-write-flag.js.map +1 -0
- package/dist/commonjs/header.d.ts +54 -0
- package/dist/commonjs/header.d.ts.map +1 -0
- package/dist/commonjs/header.js +311 -0
- package/dist/commonjs/header.js.map +1 -0
- package/dist/commonjs/index.d.ts +19 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +54 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/large-numbers.d.ts +4 -0
- package/dist/commonjs/large-numbers.d.ts.map +1 -0
- package/dist/commonjs/large-numbers.js +99 -0
- package/dist/commonjs/large-numbers.js.map +1 -0
- package/dist/commonjs/list.d.ts +8 -0
- package/dist/commonjs/list.d.ts.map +1 -0
- package/dist/commonjs/list.js +167 -0
- package/dist/commonjs/list.js.map +1 -0
- package/dist/commonjs/mkdir.d.ts +27 -0
- package/dist/commonjs/mkdir.d.ts.map +1 -0
- package/dist/commonjs/mkdir.js +209 -0
- package/dist/commonjs/mkdir.js.map +1 -0
- package/dist/commonjs/mode-fix.d.ts +2 -0
- package/dist/commonjs/mode-fix.d.ts.map +1 -0
- package/dist/commonjs/mode-fix.js +29 -0
- package/dist/commonjs/mode-fix.js.map +1 -0
- package/dist/commonjs/normalize-unicode.d.ts +2 -0
- package/dist/commonjs/normalize-unicode.d.ts.map +1 -0
- package/dist/commonjs/normalize-unicode.js +17 -0
- package/dist/commonjs/normalize-unicode.js.map +1 -0
- package/dist/commonjs/normalize-windows-path.d.ts +2 -0
- package/dist/commonjs/normalize-windows-path.d.ts.map +1 -0
- package/dist/commonjs/normalize-windows-path.js +12 -0
- package/dist/commonjs/normalize-windows-path.js.map +1 -0
- package/dist/commonjs/options.d.ts +545 -0
- package/dist/commonjs/options.d.ts.map +1 -0
- package/dist/commonjs/options.js +55 -0
- package/dist/commonjs/options.js.map +1 -0
- package/dist/commonjs/pack.d.ts +98 -0
- package/dist/commonjs/pack.d.ts.map +1 -0
- package/dist/commonjs/pack.js +461 -0
- package/dist/commonjs/pack.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/parse.d.ts +84 -0
- package/dist/commonjs/parse.d.ts.map +1 -0
- package/dist/commonjs/parse.js +571 -0
- package/dist/commonjs/parse.js.map +1 -0
- package/dist/commonjs/path-reservations.d.ts +11 -0
- package/dist/commonjs/path-reservations.d.ts.map +1 -0
- package/dist/commonjs/path-reservations.js +169 -0
- package/dist/commonjs/path-reservations.js.map +1 -0
- package/dist/commonjs/pax.d.ts +27 -0
- package/dist/commonjs/pax.d.ts.map +1 -0
- package/dist/commonjs/pax.js +158 -0
- package/dist/commonjs/pax.js.map +1 -0
- package/dist/commonjs/read-entry.d.ts +37 -0
- package/dist/commonjs/read-entry.d.ts.map +1 -0
- package/dist/commonjs/read-entry.js +139 -0
- package/dist/commonjs/read-entry.js.map +1 -0
- package/dist/commonjs/replace.d.ts +5 -0
- package/dist/commonjs/replace.d.ts.map +1 -0
- package/dist/commonjs/replace.js +223 -0
- package/dist/commonjs/replace.js.map +1 -0
- package/dist/commonjs/strip-absolute-path.d.ts +2 -0
- package/dist/commonjs/strip-absolute-path.d.ts.map +1 -0
- package/dist/commonjs/strip-absolute-path.js +29 -0
- package/dist/commonjs/strip-absolute-path.js.map +1 -0
- package/dist/commonjs/strip-trailing-slashes.d.ts +2 -0
- package/dist/commonjs/strip-trailing-slashes.d.ts.map +1 -0
- package/dist/commonjs/strip-trailing-slashes.js +18 -0
- package/dist/commonjs/strip-trailing-slashes.js.map +1 -0
- package/dist/commonjs/symlink-error.d.ts +9 -0
- package/dist/commonjs/symlink-error.d.ts.map +1 -0
- package/dist/commonjs/symlink-error.js +19 -0
- package/dist/commonjs/symlink-error.js.map +1 -0
- package/dist/commonjs/types.d.ts +7 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +50 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/unpack.d.ts +98 -0
- package/dist/commonjs/unpack.d.ts.map +1 -0
- package/dist/commonjs/unpack.js +921 -0
- package/dist/commonjs/unpack.js.map +1 -0
- package/dist/commonjs/update.d.ts +3 -0
- package/dist/commonjs/update.d.ts.map +1 -0
- package/dist/commonjs/update.js +47 -0
- package/dist/commonjs/update.js.map +1 -0
- package/dist/commonjs/warn-method.d.ts +20 -0
- package/dist/commonjs/warn-method.d.ts.map +1 -0
- package/dist/commonjs/warn-method.js +31 -0
- package/dist/commonjs/warn-method.js.map +1 -0
- package/dist/commonjs/winchars.d.ts +3 -0
- package/dist/commonjs/winchars.d.ts.map +1 -0
- package/dist/commonjs/winchars.js +14 -0
- package/dist/commonjs/winchars.js.map +1 -0
- package/dist/commonjs/write-entry.d.ts +125 -0
- package/dist/commonjs/write-entry.d.ts.map +1 -0
- package/dist/commonjs/write-entry.js +657 -0
- package/dist/commonjs/write-entry.js.map +1 -0
- package/dist/esm/create.d.ts +8 -0
- package/dist/esm/create.d.ts.map +1 -0
- package/dist/esm/create.js +99 -0
- package/dist/esm/create.js.map +1 -0
- package/dist/esm/cwd-error.d.ts +8 -0
- package/dist/esm/cwd-error.d.ts.map +1 -0
- package/dist/esm/cwd-error.js +14 -0
- package/dist/esm/cwd-error.js.map +1 -0
- package/dist/esm/extract.d.ts +8 -0
- package/dist/esm/extract.d.ts.map +1 -0
- package/dist/esm/extract.js +111 -0
- package/dist/esm/extract.js.map +1 -0
- package/dist/esm/get-write-flag.d.ts +2 -0
- package/dist/esm/get-write-flag.d.ts.map +1 -0
- package/dist/esm/get-write-flag.js +23 -0
- package/dist/esm/get-write-flag.js.map +1 -0
- package/dist/esm/header.d.ts +54 -0
- package/dist/esm/header.d.ts.map +1 -0
- package/dist/esm/header.js +284 -0
- package/dist/esm/header.js.map +1 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/large-numbers.d.ts +4 -0
- package/dist/esm/large-numbers.d.ts.map +1 -0
- package/dist/esm/large-numbers.js +94 -0
- package/dist/esm/large-numbers.js.map +1 -0
- package/dist/esm/list.d.ts +8 -0
- package/dist/esm/list.d.ts.map +1 -0
- package/dist/esm/list.js +137 -0
- package/dist/esm/list.js.map +1 -0
- package/dist/esm/mkdir.d.ts +27 -0
- package/dist/esm/mkdir.d.ts.map +1 -0
- package/dist/esm/mkdir.js +201 -0
- package/dist/esm/mkdir.js.map +1 -0
- package/dist/esm/mode-fix.d.ts +2 -0
- package/dist/esm/mode-fix.d.ts.map +1 -0
- package/dist/esm/mode-fix.js +25 -0
- package/dist/esm/mode-fix.js.map +1 -0
- package/dist/esm/normalize-unicode.d.ts +2 -0
- package/dist/esm/normalize-unicode.d.ts.map +1 -0
- package/dist/esm/normalize-unicode.js +13 -0
- package/dist/esm/normalize-unicode.js.map +1 -0
- package/dist/esm/normalize-windows-path.d.ts +2 -0
- package/dist/esm/normalize-windows-path.d.ts.map +1 -0
- package/{lib → dist/esm}/normalize-windows-path.js +5 -4
- package/dist/esm/normalize-windows-path.js.map +1 -0
- package/dist/esm/options.d.ts +545 -0
- package/dist/esm/options.d.ts.map +1 -0
- package/dist/esm/options.js +48 -0
- package/dist/esm/options.js.map +1 -0
- package/dist/esm/pack.d.ts +98 -0
- package/dist/esm/pack.d.ts.map +1 -0
- package/dist/esm/pack.js +429 -0
- package/dist/esm/pack.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parse.d.ts +84 -0
- package/dist/esm/parse.d.ts.map +1 -0
- package/dist/esm/parse.js +567 -0
- package/dist/esm/parse.js.map +1 -0
- package/dist/esm/path-reservations.d.ts +11 -0
- package/dist/esm/path-reservations.d.ts.map +1 -0
- package/dist/esm/path-reservations.js +165 -0
- package/dist/esm/path-reservations.js.map +1 -0
- package/dist/esm/pax.d.ts +27 -0
- package/dist/esm/pax.d.ts.map +1 -0
- package/dist/esm/pax.js +154 -0
- package/dist/esm/pax.js.map +1 -0
- package/dist/esm/read-entry.d.ts +37 -0
- package/dist/esm/read-entry.d.ts.map +1 -0
- package/dist/esm/read-entry.js +135 -0
- package/dist/esm/read-entry.js.map +1 -0
- package/dist/esm/replace.d.ts +5 -0
- package/dist/esm/replace.d.ts.map +1 -0
- package/dist/esm/replace.js +216 -0
- package/dist/esm/replace.js.map +1 -0
- package/dist/esm/strip-absolute-path.d.ts +2 -0
- package/dist/esm/strip-absolute-path.d.ts.map +1 -0
- package/dist/esm/strip-absolute-path.js +25 -0
- package/dist/esm/strip-absolute-path.js.map +1 -0
- package/dist/esm/strip-trailing-slashes.d.ts +2 -0
- package/dist/esm/strip-trailing-slashes.d.ts.map +1 -0
- package/dist/esm/strip-trailing-slashes.js +14 -0
- package/dist/esm/strip-trailing-slashes.js.map +1 -0
- package/dist/esm/symlink-error.d.ts +9 -0
- package/dist/esm/symlink-error.d.ts.map +1 -0
- package/dist/esm/symlink-error.js +15 -0
- package/dist/esm/symlink-error.js.map +1 -0
- package/dist/esm/types.d.ts +7 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +45 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/unpack.d.ts +98 -0
- package/dist/esm/unpack.d.ts.map +1 -0
- package/dist/esm/unpack.js +890 -0
- package/dist/esm/unpack.js.map +1 -0
- package/dist/esm/update.d.ts +3 -0
- package/dist/esm/update.d.ts.map +1 -0
- package/dist/esm/update.js +43 -0
- package/dist/esm/update.js.map +1 -0
- package/dist/esm/warn-method.d.ts +20 -0
- package/dist/esm/warn-method.d.ts.map +1 -0
- package/dist/esm/warn-method.js +27 -0
- package/dist/esm/warn-method.js.map +1 -0
- package/dist/esm/winchars.d.ts +3 -0
- package/dist/esm/winchars.d.ts.map +1 -0
- package/dist/esm/winchars.js +9 -0
- package/dist/esm/winchars.js.map +1 -0
- package/dist/esm/write-entry.d.ts +125 -0
- package/dist/esm/write-entry.d.ts.map +1 -0
- package/dist/esm/write-entry.js +625 -0
- package/dist/esm/write-entry.js.map +1 -0
- package/package.json +255 -40
- package/index.js +0 -18
- package/lib/create.js +0 -111
- package/lib/extract.js +0 -113
- package/lib/get-write-flag.js +0 -20
- package/lib/header.js +0 -304
- package/lib/high-level-opt.js +0 -29
- package/lib/large-numbers.js +0 -104
- package/lib/list.js +0 -139
- package/lib/mkdir.js +0 -229
- package/lib/mode-fix.js +0 -27
- package/lib/normalize-unicode.js +0 -12
- package/lib/pack.js +0 -432
- package/lib/parse.js +0 -552
- package/lib/path-reservations.js +0 -156
- package/lib/pax.js +0 -150
- package/lib/read-entry.js +0 -107
- package/lib/replace.js +0 -246
- package/lib/strip-absolute-path.js +0 -24
- package/lib/strip-trailing-slashes.js +0 -13
- package/lib/types.js +0 -44
- package/lib/unpack.js +0 -923
- package/lib/update.js +0 -40
- package/lib/warn-mixin.js +0 -24
- package/lib/winchars.js +0 -23
- package/lib/write-entry.js +0 -546
package/lib/pax.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const Header = require('./header.js')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
|
|
5
|
-
class Pax {
|
|
6
|
-
constructor (obj, global) {
|
|
7
|
-
this.atime = obj.atime || null
|
|
8
|
-
this.charset = obj.charset || null
|
|
9
|
-
this.comment = obj.comment || null
|
|
10
|
-
this.ctime = obj.ctime || null
|
|
11
|
-
this.gid = obj.gid || null
|
|
12
|
-
this.gname = obj.gname || null
|
|
13
|
-
this.linkpath = obj.linkpath || null
|
|
14
|
-
this.mtime = obj.mtime || null
|
|
15
|
-
this.path = obj.path || null
|
|
16
|
-
this.size = obj.size || null
|
|
17
|
-
this.uid = obj.uid || null
|
|
18
|
-
this.uname = obj.uname || null
|
|
19
|
-
this.dev = obj.dev || null
|
|
20
|
-
this.ino = obj.ino || null
|
|
21
|
-
this.nlink = obj.nlink || null
|
|
22
|
-
this.global = global || false
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
encode () {
|
|
26
|
-
const body = this.encodeBody()
|
|
27
|
-
if (body === '') {
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const bodyLen = Buffer.byteLength(body)
|
|
32
|
-
// round up to 512 bytes
|
|
33
|
-
// add 512 for header
|
|
34
|
-
const bufLen = 512 * Math.ceil(1 + bodyLen / 512)
|
|
35
|
-
const buf = Buffer.allocUnsafe(bufLen)
|
|
36
|
-
|
|
37
|
-
// 0-fill the header section, it might not hit every field
|
|
38
|
-
for (let i = 0; i < 512; i++) {
|
|
39
|
-
buf[i] = 0
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
new Header({
|
|
43
|
-
// XXX split the path
|
|
44
|
-
// then the path should be PaxHeader + basename, but less than 99,
|
|
45
|
-
// prepend with the dirname
|
|
46
|
-
path: ('PaxHeader/' + path.basename(this.path)).slice(0, 99),
|
|
47
|
-
mode: this.mode || 0o644,
|
|
48
|
-
uid: this.uid || null,
|
|
49
|
-
gid: this.gid || null,
|
|
50
|
-
size: bodyLen,
|
|
51
|
-
mtime: this.mtime || null,
|
|
52
|
-
type: this.global ? 'GlobalExtendedHeader' : 'ExtendedHeader',
|
|
53
|
-
linkpath: '',
|
|
54
|
-
uname: this.uname || '',
|
|
55
|
-
gname: this.gname || '',
|
|
56
|
-
devmaj: 0,
|
|
57
|
-
devmin: 0,
|
|
58
|
-
atime: this.atime || null,
|
|
59
|
-
ctime: this.ctime || null,
|
|
60
|
-
}).encode(buf)
|
|
61
|
-
|
|
62
|
-
buf.write(body, 512, bodyLen, 'utf8')
|
|
63
|
-
|
|
64
|
-
// null pad after the body
|
|
65
|
-
for (let i = bodyLen + 512; i < buf.length; i++) {
|
|
66
|
-
buf[i] = 0
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return buf
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
encodeBody () {
|
|
73
|
-
return (
|
|
74
|
-
this.encodeField('path') +
|
|
75
|
-
this.encodeField('ctime') +
|
|
76
|
-
this.encodeField('atime') +
|
|
77
|
-
this.encodeField('dev') +
|
|
78
|
-
this.encodeField('ino') +
|
|
79
|
-
this.encodeField('nlink') +
|
|
80
|
-
this.encodeField('charset') +
|
|
81
|
-
this.encodeField('comment') +
|
|
82
|
-
this.encodeField('gid') +
|
|
83
|
-
this.encodeField('gname') +
|
|
84
|
-
this.encodeField('linkpath') +
|
|
85
|
-
this.encodeField('mtime') +
|
|
86
|
-
this.encodeField('size') +
|
|
87
|
-
this.encodeField('uid') +
|
|
88
|
-
this.encodeField('uname')
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
encodeField (field) {
|
|
93
|
-
if (this[field] === null || this[field] === undefined) {
|
|
94
|
-
return ''
|
|
95
|
-
}
|
|
96
|
-
const v = this[field] instanceof Date ? this[field].getTime() / 1000
|
|
97
|
-
: this[field]
|
|
98
|
-
const s = ' ' +
|
|
99
|
-
(field === 'dev' || field === 'ino' || field === 'nlink'
|
|
100
|
-
? 'SCHILY.' : '') +
|
|
101
|
-
field + '=' + v + '\n'
|
|
102
|
-
const byteLen = Buffer.byteLength(s)
|
|
103
|
-
// the digits includes the length of the digits in ascii base-10
|
|
104
|
-
// so if it's 9 characters, then adding 1 for the 9 makes it 10
|
|
105
|
-
// which makes it 11 chars.
|
|
106
|
-
let digits = Math.floor(Math.log(byteLen) / Math.log(10)) + 1
|
|
107
|
-
if (byteLen + digits >= Math.pow(10, digits)) {
|
|
108
|
-
digits += 1
|
|
109
|
-
}
|
|
110
|
-
const len = digits + byteLen
|
|
111
|
-
return len + s
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
Pax.parse = (string, ex, g) => new Pax(merge(parseKV(string), ex), g)
|
|
116
|
-
|
|
117
|
-
const merge = (a, b) =>
|
|
118
|
-
b ? Object.keys(a).reduce((s, k) => (s[k] = a[k], s), b) : a
|
|
119
|
-
|
|
120
|
-
const parseKV = string =>
|
|
121
|
-
string
|
|
122
|
-
.replace(/\n$/, '')
|
|
123
|
-
.split('\n')
|
|
124
|
-
.reduce(parseKVLine, Object.create(null))
|
|
125
|
-
|
|
126
|
-
const parseKVLine = (set, line) => {
|
|
127
|
-
const n = parseInt(line, 10)
|
|
128
|
-
|
|
129
|
-
// XXX Values with \n in them will fail this.
|
|
130
|
-
// Refactor to not be a naive line-by-line parse.
|
|
131
|
-
if (n !== Buffer.byteLength(line) + 1) {
|
|
132
|
-
return set
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
line = line.slice((n + ' ').length)
|
|
136
|
-
const kv = line.split('=')
|
|
137
|
-
const k = kv.shift().replace(/^SCHILY\.(dev|ino|nlink)/, '$1')
|
|
138
|
-
if (!k) {
|
|
139
|
-
return set
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const v = kv.join('=')
|
|
143
|
-
set[k] = /^([A-Z]+\.)?([mac]|birth|creation)time$/.test(k)
|
|
144
|
-
? new Date(v * 1000)
|
|
145
|
-
: /^[0-9]+$/.test(v) ? +v
|
|
146
|
-
: v
|
|
147
|
-
return set
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
module.exports = Pax
|
package/lib/read-entry.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const { Minipass } = require('minipass')
|
|
3
|
-
const normPath = require('./normalize-windows-path.js')
|
|
4
|
-
|
|
5
|
-
const SLURP = Symbol('slurp')
|
|
6
|
-
module.exports = class ReadEntry extends Minipass {
|
|
7
|
-
constructor (header, ex, gex) {
|
|
8
|
-
super()
|
|
9
|
-
// read entries always start life paused. this is to avoid the
|
|
10
|
-
// situation where Minipass's auto-ending empty streams results
|
|
11
|
-
// in an entry ending before we're ready for it.
|
|
12
|
-
this.pause()
|
|
13
|
-
this.extended = ex
|
|
14
|
-
this.globalExtended = gex
|
|
15
|
-
this.header = header
|
|
16
|
-
this.startBlockSize = 512 * Math.ceil(header.size / 512)
|
|
17
|
-
this.blockRemain = this.startBlockSize
|
|
18
|
-
this.remain = header.size
|
|
19
|
-
this.type = header.type
|
|
20
|
-
this.meta = false
|
|
21
|
-
this.ignore = false
|
|
22
|
-
switch (this.type) {
|
|
23
|
-
case 'File':
|
|
24
|
-
case 'OldFile':
|
|
25
|
-
case 'Link':
|
|
26
|
-
case 'SymbolicLink':
|
|
27
|
-
case 'CharacterDevice':
|
|
28
|
-
case 'BlockDevice':
|
|
29
|
-
case 'Directory':
|
|
30
|
-
case 'FIFO':
|
|
31
|
-
case 'ContiguousFile':
|
|
32
|
-
case 'GNUDumpDir':
|
|
33
|
-
break
|
|
34
|
-
|
|
35
|
-
case 'NextFileHasLongLinkpath':
|
|
36
|
-
case 'NextFileHasLongPath':
|
|
37
|
-
case 'OldGnuLongPath':
|
|
38
|
-
case 'GlobalExtendedHeader':
|
|
39
|
-
case 'ExtendedHeader':
|
|
40
|
-
case 'OldExtendedHeader':
|
|
41
|
-
this.meta = true
|
|
42
|
-
break
|
|
43
|
-
|
|
44
|
-
// NOTE: gnutar and bsdtar treat unrecognized types as 'File'
|
|
45
|
-
// it may be worth doing the same, but with a warning.
|
|
46
|
-
default:
|
|
47
|
-
this.ignore = true
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.path = normPath(header.path)
|
|
51
|
-
this.mode = header.mode
|
|
52
|
-
if (this.mode) {
|
|
53
|
-
this.mode = this.mode & 0o7777
|
|
54
|
-
}
|
|
55
|
-
this.uid = header.uid
|
|
56
|
-
this.gid = header.gid
|
|
57
|
-
this.uname = header.uname
|
|
58
|
-
this.gname = header.gname
|
|
59
|
-
this.size = header.size
|
|
60
|
-
this.mtime = header.mtime
|
|
61
|
-
this.atime = header.atime
|
|
62
|
-
this.ctime = header.ctime
|
|
63
|
-
this.linkpath = normPath(header.linkpath)
|
|
64
|
-
this.uname = header.uname
|
|
65
|
-
this.gname = header.gname
|
|
66
|
-
|
|
67
|
-
if (ex) {
|
|
68
|
-
this[SLURP](ex)
|
|
69
|
-
}
|
|
70
|
-
if (gex) {
|
|
71
|
-
this[SLURP](gex, true)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
write (data) {
|
|
76
|
-
const writeLen = data.length
|
|
77
|
-
if (writeLen > this.blockRemain) {
|
|
78
|
-
throw new Error('writing more to entry than is appropriate')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const r = this.remain
|
|
82
|
-
const br = this.blockRemain
|
|
83
|
-
this.remain = Math.max(0, r - writeLen)
|
|
84
|
-
this.blockRemain = Math.max(0, br - writeLen)
|
|
85
|
-
if (this.ignore) {
|
|
86
|
-
return true
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (r >= writeLen) {
|
|
90
|
-
return super.write(data)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// r < writeLen
|
|
94
|
-
return super.write(data.slice(0, r))
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
[SLURP] (ex, global) {
|
|
98
|
-
for (const k in ex) {
|
|
99
|
-
// we slurp in everything except for the path attribute in
|
|
100
|
-
// a global extended header, because that's weird.
|
|
101
|
-
if (ex[k] !== null && ex[k] !== undefined &&
|
|
102
|
-
!(global && k === 'path')) {
|
|
103
|
-
this[k] = k === 'path' || k === 'linkpath' ? normPath(ex[k]) : ex[k]
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
package/lib/replace.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// tar -r
|
|
4
|
-
const hlo = require('./high-level-opt.js')
|
|
5
|
-
const Pack = require('./pack.js')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const fsm = require('fs-minipass')
|
|
8
|
-
const t = require('./list.js')
|
|
9
|
-
const path = require('path')
|
|
10
|
-
|
|
11
|
-
// starting at the head of the file, read a Header
|
|
12
|
-
// If the checksum is invalid, that's our position to start writing
|
|
13
|
-
// If it is, jump forward by the specified size (round up to 512)
|
|
14
|
-
// and try again.
|
|
15
|
-
// Write the new Pack stream starting there.
|
|
16
|
-
|
|
17
|
-
const Header = require('./header.js')
|
|
18
|
-
|
|
19
|
-
module.exports = (opt_, files, cb) => {
|
|
20
|
-
const opt = hlo(opt_)
|
|
21
|
-
|
|
22
|
-
if (!opt.file) {
|
|
23
|
-
throw new TypeError('file is required')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) {
|
|
27
|
-
throw new TypeError('cannot append to compressed archives')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!files || !Array.isArray(files) || !files.length) {
|
|
31
|
-
throw new TypeError('no files or directories specified')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
files = Array.from(files)
|
|
35
|
-
|
|
36
|
-
return opt.sync ? replaceSync(opt, files)
|
|
37
|
-
: replace(opt, files, cb)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const replaceSync = (opt, files) => {
|
|
41
|
-
const p = new Pack.Sync(opt)
|
|
42
|
-
|
|
43
|
-
let threw = true
|
|
44
|
-
let fd
|
|
45
|
-
let position
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
try {
|
|
49
|
-
fd = fs.openSync(opt.file, 'r+')
|
|
50
|
-
} catch (er) {
|
|
51
|
-
if (er.code === 'ENOENT') {
|
|
52
|
-
fd = fs.openSync(opt.file, 'w+')
|
|
53
|
-
} else {
|
|
54
|
-
throw er
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const st = fs.fstatSync(fd)
|
|
59
|
-
const headBuf = Buffer.alloc(512)
|
|
60
|
-
|
|
61
|
-
POSITION: for (position = 0; position < st.size; position += 512) {
|
|
62
|
-
for (let bufPos = 0, bytes = 0; bufPos < 512; bufPos += bytes) {
|
|
63
|
-
bytes = fs.readSync(
|
|
64
|
-
fd, headBuf, bufPos, headBuf.length - bufPos, position + bufPos
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b) {
|
|
68
|
-
throw new Error('cannot append to compressed archives')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!bytes) {
|
|
72
|
-
break POSITION
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const h = new Header(headBuf)
|
|
77
|
-
if (!h.cksumValid) {
|
|
78
|
-
break
|
|
79
|
-
}
|
|
80
|
-
const entryBlockSize = 512 * Math.ceil(h.size / 512)
|
|
81
|
-
if (position + entryBlockSize + 512 > st.size) {
|
|
82
|
-
break
|
|
83
|
-
}
|
|
84
|
-
// the 512 for the header we just parsed will be added as well
|
|
85
|
-
// also jump ahead all the blocks for the body
|
|
86
|
-
position += entryBlockSize
|
|
87
|
-
if (opt.mtimeCache) {
|
|
88
|
-
opt.mtimeCache.set(h.path, h.mtime)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
threw = false
|
|
92
|
-
|
|
93
|
-
streamSync(opt, p, position, fd, files)
|
|
94
|
-
} finally {
|
|
95
|
-
if (threw) {
|
|
96
|
-
try {
|
|
97
|
-
fs.closeSync(fd)
|
|
98
|
-
} catch (er) {}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const streamSync = (opt, p, position, fd, files) => {
|
|
104
|
-
const stream = new fsm.WriteStreamSync(opt.file, {
|
|
105
|
-
fd: fd,
|
|
106
|
-
start: position,
|
|
107
|
-
})
|
|
108
|
-
p.pipe(stream)
|
|
109
|
-
addFilesSync(p, files)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const replace = (opt, files, cb) => {
|
|
113
|
-
files = Array.from(files)
|
|
114
|
-
const p = new Pack(opt)
|
|
115
|
-
|
|
116
|
-
const getPos = (fd, size, cb_) => {
|
|
117
|
-
const cb = (er, pos) => {
|
|
118
|
-
if (er) {
|
|
119
|
-
fs.close(fd, _ => cb_(er))
|
|
120
|
-
} else {
|
|
121
|
-
cb_(null, pos)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let position = 0
|
|
126
|
-
if (size === 0) {
|
|
127
|
-
return cb(null, 0)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
let bufPos = 0
|
|
131
|
-
const headBuf = Buffer.alloc(512)
|
|
132
|
-
const onread = (er, bytes) => {
|
|
133
|
-
if (er) {
|
|
134
|
-
return cb(er)
|
|
135
|
-
}
|
|
136
|
-
bufPos += bytes
|
|
137
|
-
if (bufPos < 512 && bytes) {
|
|
138
|
-
return fs.read(
|
|
139
|
-
fd, headBuf, bufPos, headBuf.length - bufPos,
|
|
140
|
-
position + bufPos, onread
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b) {
|
|
145
|
-
return cb(new Error('cannot append to compressed archives'))
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// truncated header
|
|
149
|
-
if (bufPos < 512) {
|
|
150
|
-
return cb(null, position)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const h = new Header(headBuf)
|
|
154
|
-
if (!h.cksumValid) {
|
|
155
|
-
return cb(null, position)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const entryBlockSize = 512 * Math.ceil(h.size / 512)
|
|
159
|
-
if (position + entryBlockSize + 512 > size) {
|
|
160
|
-
return cb(null, position)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
position += entryBlockSize + 512
|
|
164
|
-
if (position >= size) {
|
|
165
|
-
return cb(null, position)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (opt.mtimeCache) {
|
|
169
|
-
opt.mtimeCache.set(h.path, h.mtime)
|
|
170
|
-
}
|
|
171
|
-
bufPos = 0
|
|
172
|
-
fs.read(fd, headBuf, 0, 512, position, onread)
|
|
173
|
-
}
|
|
174
|
-
fs.read(fd, headBuf, 0, 512, position, onread)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const promise = new Promise((resolve, reject) => {
|
|
178
|
-
p.on('error', reject)
|
|
179
|
-
let flag = 'r+'
|
|
180
|
-
const onopen = (er, fd) => {
|
|
181
|
-
if (er && er.code === 'ENOENT' && flag === 'r+') {
|
|
182
|
-
flag = 'w+'
|
|
183
|
-
return fs.open(opt.file, flag, onopen)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (er) {
|
|
187
|
-
return reject(er)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
fs.fstat(fd, (er, st) => {
|
|
191
|
-
if (er) {
|
|
192
|
-
return fs.close(fd, () => reject(er))
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
getPos(fd, st.size, (er, position) => {
|
|
196
|
-
if (er) {
|
|
197
|
-
return reject(er)
|
|
198
|
-
}
|
|
199
|
-
const stream = new fsm.WriteStream(opt.file, {
|
|
200
|
-
fd: fd,
|
|
201
|
-
start: position,
|
|
202
|
-
})
|
|
203
|
-
p.pipe(stream)
|
|
204
|
-
stream.on('error', reject)
|
|
205
|
-
stream.on('close', resolve)
|
|
206
|
-
addFilesAsync(p, files)
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
}
|
|
210
|
-
fs.open(opt.file, flag, onopen)
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
return cb ? promise.then(cb, cb) : promise
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const addFilesSync = (p, files) => {
|
|
217
|
-
files.forEach(file => {
|
|
218
|
-
if (file.charAt(0) === '@') {
|
|
219
|
-
t({
|
|
220
|
-
file: path.resolve(p.cwd, file.slice(1)),
|
|
221
|
-
sync: true,
|
|
222
|
-
noResume: true,
|
|
223
|
-
onentry: entry => p.add(entry),
|
|
224
|
-
})
|
|
225
|
-
} else {
|
|
226
|
-
p.add(file)
|
|
227
|
-
}
|
|
228
|
-
})
|
|
229
|
-
p.end()
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const addFilesAsync = (p, files) => {
|
|
233
|
-
while (files.length) {
|
|
234
|
-
const file = files.shift()
|
|
235
|
-
if (file.charAt(0) === '@') {
|
|
236
|
-
return t({
|
|
237
|
-
file: path.resolve(p.cwd, file.slice(1)),
|
|
238
|
-
noResume: true,
|
|
239
|
-
onentry: entry => p.add(entry),
|
|
240
|
-
}).then(_ => addFilesAsync(p, files))
|
|
241
|
-
} else {
|
|
242
|
-
p.add(file)
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
p.end()
|
|
246
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// unix absolute paths are also absolute on win32, so we use this for both
|
|
2
|
-
const { isAbsolute, parse } = require('path').win32
|
|
3
|
-
|
|
4
|
-
// returns [root, stripped]
|
|
5
|
-
// Note that windows will think that //x/y/z/a has a "root" of //x/y, and in
|
|
6
|
-
// those cases, we want to sanitize it to x/y/z/a, not z/a, so we strip /
|
|
7
|
-
// explicitly if it's the first character.
|
|
8
|
-
// drive-specific relative paths on Windows get their root stripped off even
|
|
9
|
-
// though they are not absolute, so `c:../foo` becomes ['c:', '../foo']
|
|
10
|
-
module.exports = path => {
|
|
11
|
-
let r = ''
|
|
12
|
-
|
|
13
|
-
let parsed = parse(path)
|
|
14
|
-
while (isAbsolute(path) || parsed.root) {
|
|
15
|
-
// windows will think that //x/y/z has a "root" of //x/y/
|
|
16
|
-
// but strip the //?/C:/ off of //?/C:/path
|
|
17
|
-
const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/'
|
|
18
|
-
: parsed.root
|
|
19
|
-
path = path.slice(root.length)
|
|
20
|
-
r += root
|
|
21
|
-
parsed = parse(path)
|
|
22
|
-
}
|
|
23
|
-
return [r, path]
|
|
24
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// warning: extremely hot code path.
|
|
2
|
-
// This has been meticulously optimized for use
|
|
3
|
-
// within npm install on large package trees.
|
|
4
|
-
// Do not edit without careful benchmarking.
|
|
5
|
-
module.exports = str => {
|
|
6
|
-
let i = str.length - 1
|
|
7
|
-
let slashesStart = -1
|
|
8
|
-
while (i > -1 && str.charAt(i) === '/') {
|
|
9
|
-
slashesStart = i
|
|
10
|
-
i--
|
|
11
|
-
}
|
|
12
|
-
return slashesStart === -1 ? str : str.slice(0, slashesStart)
|
|
13
|
-
}
|
package/lib/types.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
// map types from key to human-friendly name
|
|
3
|
-
exports.name = new Map([
|
|
4
|
-
['0', 'File'],
|
|
5
|
-
// same as File
|
|
6
|
-
['', 'OldFile'],
|
|
7
|
-
['1', 'Link'],
|
|
8
|
-
['2', 'SymbolicLink'],
|
|
9
|
-
// Devices and FIFOs aren't fully supported
|
|
10
|
-
// they are parsed, but skipped when unpacking
|
|
11
|
-
['3', 'CharacterDevice'],
|
|
12
|
-
['4', 'BlockDevice'],
|
|
13
|
-
['5', 'Directory'],
|
|
14
|
-
['6', 'FIFO'],
|
|
15
|
-
// same as File
|
|
16
|
-
['7', 'ContiguousFile'],
|
|
17
|
-
// pax headers
|
|
18
|
-
['g', 'GlobalExtendedHeader'],
|
|
19
|
-
['x', 'ExtendedHeader'],
|
|
20
|
-
// vendor-specific stuff
|
|
21
|
-
// skip
|
|
22
|
-
['A', 'SolarisACL'],
|
|
23
|
-
// like 5, but with data, which should be skipped
|
|
24
|
-
['D', 'GNUDumpDir'],
|
|
25
|
-
// metadata only, skip
|
|
26
|
-
['I', 'Inode'],
|
|
27
|
-
// data = link path of next file
|
|
28
|
-
['K', 'NextFileHasLongLinkpath'],
|
|
29
|
-
// data = path of next file
|
|
30
|
-
['L', 'NextFileHasLongPath'],
|
|
31
|
-
// skip
|
|
32
|
-
['M', 'ContinuationFile'],
|
|
33
|
-
// like L
|
|
34
|
-
['N', 'OldGnuLongPath'],
|
|
35
|
-
// skip
|
|
36
|
-
['S', 'SparseFile'],
|
|
37
|
-
// skip
|
|
38
|
-
['V', 'TapeVolumeHeader'],
|
|
39
|
-
// like x
|
|
40
|
-
['X', 'OldExtendedHeader'],
|
|
41
|
-
])
|
|
42
|
-
|
|
43
|
-
// map the other direction
|
|
44
|
-
exports.code = new Map(Array.from(exports.name).map(kv => [kv[1], kv[0]]))
|