tar 6.1.2 → 6.1.6
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 +4 -3
- package/lib/list.js +4 -3
- package/lib/pack.js +3 -14
- package/lib/strip-trailing-slashes.js +24 -0
- package/lib/unpack.js +42 -13
- package/lib/write-entry.js +123 -50
- package/package.json +1 -1
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
|
|
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
|
|
59
|
-
: file => mapHas(file
|
|
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
|
|
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
|
|
72
|
-
: file => mapHas(file
|
|
72
|
+
? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
|
|
73
|
+
: file => mapHas(stripSlash(file))
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
const listFileSync = opt => {
|
package/lib/pack.js
CHANGED
|
@@ -134,9 +134,6 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
134
134
|
|
|
135
135
|
[ADDTARENTRY] (p) {
|
|
136
136
|
const absolute = path.resolve(this.cwd, p.path)
|
|
137
|
-
if (this.prefix)
|
|
138
|
-
p.path = this.prefix + '/' + p.path.replace(/^\.(\/+|$)/, '')
|
|
139
|
-
|
|
140
137
|
// in this case, we don't have to wait for the stat
|
|
141
138
|
if (!this.filter(p.path, p))
|
|
142
139
|
p.resume()
|
|
@@ -153,9 +150,6 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
153
150
|
|
|
154
151
|
[ADDFSENTRY] (p) {
|
|
155
152
|
const absolute = path.resolve(this.cwd, p)
|
|
156
|
-
if (this.prefix)
|
|
157
|
-
p = this.prefix + '/' + p.replace(/^\.(\/+|$)/, '')
|
|
158
|
-
|
|
159
153
|
this[QUEUE].push(new PackJob(p, absolute))
|
|
160
154
|
this[PROCESS]()
|
|
161
155
|
}
|
|
@@ -298,6 +292,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
298
292
|
statCache: this.statCache,
|
|
299
293
|
noMtime: this.noMtime,
|
|
300
294
|
mtime: this.mtime,
|
|
295
|
+
prefix: this.prefix,
|
|
301
296
|
}
|
|
302
297
|
}
|
|
303
298
|
|
|
@@ -323,10 +318,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
323
318
|
|
|
324
319
|
if (job.readdir) {
|
|
325
320
|
job.readdir.forEach(entry => {
|
|
326
|
-
const p =
|
|
327
|
-
job.path.slice(this.prefix.length + 1) || './'
|
|
328
|
-
: job.path
|
|
329
|
-
|
|
321
|
+
const p = job.path
|
|
330
322
|
const base = p === './' ? '' : p.replace(/\/*$/, '/')
|
|
331
323
|
this[ADDFSENTRY](base + entry)
|
|
332
324
|
})
|
|
@@ -381,10 +373,7 @@ class PackSync extends Pack {
|
|
|
381
373
|
|
|
382
374
|
if (job.readdir) {
|
|
383
375
|
job.readdir.forEach(entry => {
|
|
384
|
-
const p =
|
|
385
|
-
job.path.slice(this.prefix.length + 1) || './'
|
|
386
|
-
: job.path
|
|
387
|
-
|
|
376
|
+
const p = job.path
|
|
388
377
|
const base = p === './' ? '' : p.replace(/\/*$/, '/')
|
|
389
378
|
this[ADDFSENTRY](base + entry)
|
|
390
379
|
})
|
|
@@ -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/lib/unpack.js
CHANGED
|
@@ -205,6 +205,8 @@ class Unpack extends Parser {
|
|
|
205
205
|
if (parts.length < this.strip)
|
|
206
206
|
return false
|
|
207
207
|
entry.path = parts.slice(this.strip).join('/')
|
|
208
|
+
if (entry.path === '' && entry.type !== 'Directory' && entry.type !== 'GNUDumpDir')
|
|
209
|
+
return false
|
|
208
210
|
|
|
209
211
|
if (entry.type === 'Link') {
|
|
210
212
|
const linkparts = entry.linkpath.split(/\/|\\/)
|
|
@@ -333,17 +335,35 @@ class Unpack extends Parser {
|
|
|
333
335
|
mode: mode,
|
|
334
336
|
autoClose: false,
|
|
335
337
|
})
|
|
336
|
-
stream.on('error', er =>
|
|
338
|
+
stream.on('error', er => {
|
|
339
|
+
if (stream.fd)
|
|
340
|
+
fs.close(stream.fd, () => {})
|
|
341
|
+
// flush all the data out so that we aren't left hanging
|
|
342
|
+
// if the error wasn't actually fatal. otherwise the parse
|
|
343
|
+
// is blocked, and we never proceed.
|
|
344
|
+
stream.write = () => true
|
|
345
|
+
this[ONERROR](er, entry)
|
|
346
|
+
fullyDone()
|
|
347
|
+
})
|
|
337
348
|
|
|
338
349
|
let actions = 1
|
|
339
350
|
const done = er => {
|
|
340
|
-
if (er)
|
|
341
|
-
|
|
351
|
+
if (er) {
|
|
352
|
+
/* istanbul ignore else - we should always have a fd by now */
|
|
353
|
+
if (stream.fd)
|
|
354
|
+
fs.close(stream.fd, () => {})
|
|
355
|
+
this[ONERROR](er, entry)
|
|
356
|
+
fullyDone()
|
|
357
|
+
return
|
|
358
|
+
}
|
|
342
359
|
|
|
343
360
|
if (--actions === 0) {
|
|
344
361
|
fs.close(stream.fd, er => {
|
|
362
|
+
if (er)
|
|
363
|
+
this[ONERROR](er, entry)
|
|
364
|
+
else
|
|
365
|
+
this[UNPEND]()
|
|
345
366
|
fullyDone()
|
|
346
|
-
er ? this[ONERROR](er, entry) : this[UNPEND]()
|
|
347
367
|
})
|
|
348
368
|
}
|
|
349
369
|
}
|
|
@@ -378,7 +398,10 @@ class Unpack extends Parser {
|
|
|
378
398
|
|
|
379
399
|
const tx = this.transform ? this.transform(entry) || entry : entry
|
|
380
400
|
if (tx !== entry) {
|
|
381
|
-
tx.on('error', er =>
|
|
401
|
+
tx.on('error', er => {
|
|
402
|
+
this[ONERROR](er, entry)
|
|
403
|
+
fullyDone()
|
|
404
|
+
})
|
|
382
405
|
entry.pipe(tx)
|
|
383
406
|
}
|
|
384
407
|
tx.pipe(stream)
|
|
@@ -388,8 +411,9 @@ class Unpack extends Parser {
|
|
|
388
411
|
const mode = entry.mode & 0o7777 || this.dmode
|
|
389
412
|
this[MKDIR](entry.absolute, mode, er => {
|
|
390
413
|
if (er) {
|
|
414
|
+
this[ONERROR](er, entry)
|
|
391
415
|
fullyDone()
|
|
392
|
-
return
|
|
416
|
+
return
|
|
393
417
|
}
|
|
394
418
|
|
|
395
419
|
let actions = 1
|
|
@@ -480,8 +504,9 @@ class Unpack extends Parser {
|
|
|
480
504
|
|
|
481
505
|
this[MKDIR](path.dirname(entry.absolute), this.dmode, er => {
|
|
482
506
|
if (er) {
|
|
507
|
+
this[ONERROR](er, entry)
|
|
483
508
|
done()
|
|
484
|
-
return
|
|
509
|
+
return
|
|
485
510
|
}
|
|
486
511
|
fs.lstat(entry.absolute, (er, st) => {
|
|
487
512
|
if (st && (this.keep || this.newer && st.mtime > entry.mtime)) {
|
|
@@ -489,7 +514,6 @@ class Unpack extends Parser {
|
|
|
489
514
|
done()
|
|
490
515
|
} else if (er || this[ISREUSABLE](entry, st))
|
|
491
516
|
this[MAKEFS](null, entry, done)
|
|
492
|
-
|
|
493
517
|
else if (st.isDirectory()) {
|
|
494
518
|
if (entry.type === 'Directory') {
|
|
495
519
|
if (!this.noChmod && (!entry.mode || (st.mode & 0o7777) === entry.mode))
|
|
@@ -507,8 +531,11 @@ class Unpack extends Parser {
|
|
|
507
531
|
}
|
|
508
532
|
|
|
509
533
|
[MAKEFS] (er, entry, done) {
|
|
510
|
-
if (er)
|
|
511
|
-
|
|
534
|
+
if (er) {
|
|
535
|
+
this[ONERROR](er, entry)
|
|
536
|
+
done()
|
|
537
|
+
return
|
|
538
|
+
}
|
|
512
539
|
|
|
513
540
|
switch (entry.type) {
|
|
514
541
|
case 'File':
|
|
@@ -532,10 +559,12 @@ class Unpack extends Parser {
|
|
|
532
559
|
// XXX: get the type ('file' or 'dir') for windows
|
|
533
560
|
fs[link](linkpath, entry.absolute, er => {
|
|
534
561
|
if (er)
|
|
535
|
-
|
|
562
|
+
this[ONERROR](er, entry)
|
|
563
|
+
else {
|
|
564
|
+
this[UNPEND]()
|
|
565
|
+
entry.resume()
|
|
566
|
+
}
|
|
536
567
|
done()
|
|
537
|
-
this[UNPEND]()
|
|
538
|
-
entry.resume()
|
|
539
568
|
})
|
|
540
569
|
}
|
|
541
570
|
}
|
package/lib/write-entry.js
CHANGED
|
@@ -5,6 +5,13 @@ const Header = require('./header.js')
|
|
|
5
5
|
const fs = require('fs')
|
|
6
6
|
const path = require('path')
|
|
7
7
|
|
|
8
|
+
const prefixPath = (path, prefix) => {
|
|
9
|
+
if (!prefix)
|
|
10
|
+
return path
|
|
11
|
+
path = path.replace(/^\.([/\\]|$)/, '')
|
|
12
|
+
return prefix + '/' + path
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
const maxReadSize = 16 * 1024 * 1024
|
|
9
16
|
const PROCESS = Symbol('process')
|
|
10
17
|
const FILE = Symbol('file')
|
|
@@ -21,6 +28,9 @@ const OPENFILE = Symbol('openfile')
|
|
|
21
28
|
const ONOPENFILE = Symbol('onopenfile')
|
|
22
29
|
const CLOSE = Symbol('close')
|
|
23
30
|
const MODE = Symbol('mode')
|
|
31
|
+
const AWAITDRAIN = Symbol('awaitDrain')
|
|
32
|
+
const ONDRAIN = Symbol('ondrain')
|
|
33
|
+
const PREFIX = Symbol('prefix')
|
|
24
34
|
const warner = require('./warn-mixin.js')
|
|
25
35
|
const winchars = require('./winchars.js')
|
|
26
36
|
const stripAbsolutePath = require('./strip-absolute-path.js')
|
|
@@ -48,6 +58,16 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
48
58
|
this.noPax = !!opt.noPax
|
|
49
59
|
this.noMtime = !!opt.noMtime
|
|
50
60
|
this.mtime = opt.mtime || null
|
|
61
|
+
this.prefix = opt.prefix || null
|
|
62
|
+
|
|
63
|
+
this.fd = null
|
|
64
|
+
this.blockLen = null
|
|
65
|
+
this.blockRemain = null
|
|
66
|
+
this.buf = null
|
|
67
|
+
this.offset = null
|
|
68
|
+
this.length = null
|
|
69
|
+
this.pos = null
|
|
70
|
+
this.remain = null
|
|
51
71
|
|
|
52
72
|
if (typeof opt.onwarn === 'function')
|
|
53
73
|
this.on('warn', opt.onwarn)
|
|
@@ -117,13 +137,19 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
117
137
|
return modeFix(mode, this.type === 'Directory', this.portable)
|
|
118
138
|
}
|
|
119
139
|
|
|
140
|
+
[PREFIX] (path) {
|
|
141
|
+
return prefixPath(path, this.prefix)
|
|
142
|
+
}
|
|
143
|
+
|
|
120
144
|
[HEADER] () {
|
|
121
145
|
if (this.type === 'Directory' && this.portable)
|
|
122
146
|
this.noMtime = true
|
|
123
147
|
|
|
124
148
|
this.header = new Header({
|
|
125
|
-
path: this.path,
|
|
126
|
-
|
|
149
|
+
path: this[PREFIX](this.path),
|
|
150
|
+
// only apply the prefix to hard links.
|
|
151
|
+
linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
|
|
152
|
+
: this.linkpath,
|
|
127
153
|
// only the permissions and setuid/setgid/sticky bitflags
|
|
128
154
|
// not the higher-order bits that specify file type
|
|
129
155
|
mode: this[MODE](this.stat.mode),
|
|
@@ -139,13 +165,14 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
139
165
|
})
|
|
140
166
|
|
|
141
167
|
if (this.header.encode() && !this.noPax) {
|
|
142
|
-
|
|
168
|
+
super.write(new Pax({
|
|
143
169
|
atime: this.portable ? null : this.header.atime,
|
|
144
170
|
ctime: this.portable ? null : this.header.ctime,
|
|
145
171
|
gid: this.portable ? null : this.header.gid,
|
|
146
172
|
mtime: this.noMtime ? null : this.mtime || this.header.mtime,
|
|
147
|
-
path: this.path,
|
|
148
|
-
linkpath: this.linkpath
|
|
173
|
+
path: this[PREFIX](this.path),
|
|
174
|
+
linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
|
|
175
|
+
: this.linkpath,
|
|
149
176
|
size: this.header.size,
|
|
150
177
|
uid: this.portable ? null : this.header.uid,
|
|
151
178
|
uname: this.portable ? null : this.header.uname,
|
|
@@ -154,7 +181,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
154
181
|
nlink: this.portable ? null : this.stat.nlink,
|
|
155
182
|
}).encode())
|
|
156
183
|
}
|
|
157
|
-
|
|
184
|
+
super.write(this.header.block)
|
|
158
185
|
}
|
|
159
186
|
|
|
160
187
|
[DIRECTORY] () {
|
|
@@ -214,74 +241,107 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
214
241
|
}
|
|
215
242
|
|
|
216
243
|
[ONOPENFILE] (fd) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
244
|
+
this.fd = fd
|
|
245
|
+
this.blockLen = 512 * Math.ceil(this.stat.size / 512)
|
|
246
|
+
this.blockRemain = this.blockLen
|
|
247
|
+
const bufLen = Math.min(this.blockLen, this.maxReadSize)
|
|
248
|
+
this.buf = Buffer.allocUnsafe(bufLen)
|
|
249
|
+
this.offset = 0
|
|
250
|
+
this.pos = 0
|
|
251
|
+
this.remain = this.stat.size
|
|
252
|
+
this.length = this.buf.length
|
|
253
|
+
this[READ]()
|
|
221
254
|
}
|
|
222
255
|
|
|
223
|
-
[READ] (
|
|
256
|
+
[READ] () {
|
|
257
|
+
const { fd, buf, offset, length, pos } = this
|
|
224
258
|
fs.read(fd, buf, offset, length, pos, (er, bytesRead) => {
|
|
225
259
|
if (er) {
|
|
226
260
|
// ignoring the error from close(2) is a bad practice, but at
|
|
227
261
|
// this point we already have an error, don't need another one
|
|
228
|
-
return this[CLOSE](
|
|
262
|
+
return this[CLOSE](() => this.emit('error', er))
|
|
229
263
|
}
|
|
230
|
-
this[ONREAD](
|
|
264
|
+
this[ONREAD](bytesRead)
|
|
231
265
|
})
|
|
232
266
|
}
|
|
233
267
|
|
|
234
|
-
[CLOSE] (
|
|
235
|
-
fs.close(fd, cb)
|
|
268
|
+
[CLOSE] (cb) {
|
|
269
|
+
fs.close(this.fd, cb)
|
|
236
270
|
}
|
|
237
271
|
|
|
238
|
-
[ONREAD] (
|
|
239
|
-
if (bytesRead <= 0 && remain > 0) {
|
|
272
|
+
[ONREAD] (bytesRead) {
|
|
273
|
+
if (bytesRead <= 0 && this.remain > 0) {
|
|
240
274
|
const er = new Error('encountered unexpected EOF')
|
|
241
275
|
er.path = this.absolute
|
|
242
276
|
er.syscall = 'read'
|
|
243
277
|
er.code = 'EOF'
|
|
244
|
-
return this[CLOSE](
|
|
278
|
+
return this[CLOSE](() => this.emit('error', er))
|
|
245
279
|
}
|
|
246
280
|
|
|
247
|
-
if (bytesRead > remain) {
|
|
281
|
+
if (bytesRead > this.remain) {
|
|
248
282
|
const er = new Error('did not encounter expected EOF')
|
|
249
283
|
er.path = this.absolute
|
|
250
284
|
er.syscall = 'read'
|
|
251
285
|
er.code = 'EOF'
|
|
252
|
-
return this[CLOSE](
|
|
286
|
+
return this[CLOSE](() => this.emit('error', er))
|
|
253
287
|
}
|
|
254
288
|
|
|
255
289
|
// null out the rest of the buffer, if we could fit the block padding
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
290
|
+
// at the end of this loop, we've incremented bytesRead and this.remain
|
|
291
|
+
// to be incremented up to the blockRemain level, as if we had expected
|
|
292
|
+
// to get a null-padded file, and read it until the end. then we will
|
|
293
|
+
// decrement both remain and blockRemain by bytesRead, and know that we
|
|
294
|
+
// reached the expected EOF, without any null buffer to append.
|
|
295
|
+
if (bytesRead === this.remain) {
|
|
296
|
+
for (let i = bytesRead; i < this.length && bytesRead < this.blockRemain; i++) {
|
|
297
|
+
this.buf[i + this.offset] = 0
|
|
259
298
|
bytesRead++
|
|
260
|
-
remain++
|
|
299
|
+
this.remain++
|
|
261
300
|
}
|
|
262
301
|
}
|
|
263
302
|
|
|
264
|
-
const writeBuf = offset === 0 && bytesRead === buf.length ?
|
|
265
|
-
buf : buf.slice(offset, offset + bytesRead)
|
|
266
|
-
remain -= bytesRead
|
|
267
|
-
blockRemain -= bytesRead
|
|
268
|
-
pos += bytesRead
|
|
269
|
-
offset += bytesRead
|
|
303
|
+
const writeBuf = this.offset === 0 && bytesRead === this.buf.length ?
|
|
304
|
+
this.buf : this.buf.slice(this.offset, this.offset + bytesRead)
|
|
270
305
|
|
|
271
|
-
this.write(writeBuf)
|
|
306
|
+
const flushed = this.write(writeBuf)
|
|
307
|
+
if (!flushed)
|
|
308
|
+
this[AWAITDRAIN](() => this[ONDRAIN]())
|
|
309
|
+
else
|
|
310
|
+
this[ONDRAIN]()
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
[AWAITDRAIN] (cb) {
|
|
314
|
+
this.once('drain', cb)
|
|
315
|
+
}
|
|
272
316
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
317
|
+
write (writeBuf) {
|
|
318
|
+
if (this.blockRemain < writeBuf.length) {
|
|
319
|
+
const er = new Error('writing more data than expected')
|
|
320
|
+
er.path = this.absolute
|
|
321
|
+
return this.emit('error', er)
|
|
277
322
|
}
|
|
323
|
+
this.remain -= writeBuf.length
|
|
324
|
+
this.blockRemain -= writeBuf.length
|
|
325
|
+
this.pos += writeBuf.length
|
|
326
|
+
this.offset += writeBuf.length
|
|
327
|
+
return super.write(writeBuf)
|
|
328
|
+
}
|
|
278
329
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
330
|
+
[ONDRAIN] () {
|
|
331
|
+
if (!this.remain) {
|
|
332
|
+
if (this.blockRemain)
|
|
333
|
+
super.write(Buffer.alloc(this.blockRemain))
|
|
334
|
+
return this[CLOSE](er => er ? this.emit('error', er) : this.end())
|
|
282
335
|
}
|
|
283
|
-
|
|
284
|
-
this
|
|
336
|
+
|
|
337
|
+
if (this.offset >= this.length) {
|
|
338
|
+
// if we only have a smaller bit left to read, alloc a smaller buffer
|
|
339
|
+
// otherwise, keep it the same length it was before.
|
|
340
|
+
this.buf = Buffer.allocUnsafe(Math.min(this.blockRemain, this.buf.length))
|
|
341
|
+
this.offset = 0
|
|
342
|
+
}
|
|
343
|
+
this.length = this.buf.length - this.offset
|
|
344
|
+
this[READ]()
|
|
285
345
|
}
|
|
286
346
|
})
|
|
287
347
|
|
|
@@ -298,25 +358,30 @@ class WriteEntrySync extends WriteEntry {
|
|
|
298
358
|
this[ONOPENFILE](fs.openSync(this.absolute, 'r'))
|
|
299
359
|
}
|
|
300
360
|
|
|
301
|
-
[READ] (
|
|
361
|
+
[READ] () {
|
|
302
362
|
let threw = true
|
|
303
363
|
try {
|
|
364
|
+
const { fd, buf, offset, length, pos } = this
|
|
304
365
|
const bytesRead = fs.readSync(fd, buf, offset, length, pos)
|
|
305
|
-
this[ONREAD](
|
|
366
|
+
this[ONREAD](bytesRead)
|
|
306
367
|
threw = false
|
|
307
368
|
} finally {
|
|
308
369
|
// ignoring the error from close(2) is a bad practice, but at
|
|
309
370
|
// this point we already have an error, don't need another one
|
|
310
371
|
if (threw) {
|
|
311
372
|
try {
|
|
312
|
-
this[CLOSE](
|
|
373
|
+
this[CLOSE](() => {})
|
|
313
374
|
} catch (er) {}
|
|
314
375
|
}
|
|
315
376
|
}
|
|
316
377
|
}
|
|
317
378
|
|
|
318
|
-
[
|
|
319
|
-
|
|
379
|
+
[AWAITDRAIN] (cb) {
|
|
380
|
+
cb()
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
[CLOSE] (cb) {
|
|
384
|
+
fs.closeSync(this.fd)
|
|
320
385
|
cb()
|
|
321
386
|
}
|
|
322
387
|
}
|
|
@@ -336,6 +401,8 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
336
401
|
if (this.type === 'Directory' && this.portable)
|
|
337
402
|
this.noMtime = true
|
|
338
403
|
|
|
404
|
+
this.prefix = opt.prefix || null
|
|
405
|
+
|
|
339
406
|
this.path = readEntry.path
|
|
340
407
|
this.mode = this[MODE](readEntry.mode)
|
|
341
408
|
this.uid = this.portable ? null : readEntry.uid
|
|
@@ -364,8 +431,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
364
431
|
this.blockRemain = readEntry.startBlockSize
|
|
365
432
|
|
|
366
433
|
this.header = new Header({
|
|
367
|
-
path: this.path,
|
|
368
|
-
linkpath: this.linkpath
|
|
434
|
+
path: this[PREFIX](this.path),
|
|
435
|
+
linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
|
|
436
|
+
: this.linkpath,
|
|
369
437
|
// only the permissions and setuid/setgid/sticky bitflags
|
|
370
438
|
// not the higher-order bits that specify file type
|
|
371
439
|
mode: this.mode,
|
|
@@ -392,8 +460,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
392
460
|
ctime: this.portable ? null : this.ctime,
|
|
393
461
|
gid: this.portable ? null : this.gid,
|
|
394
462
|
mtime: this.noMtime ? null : this.mtime,
|
|
395
|
-
path: this.path,
|
|
396
|
-
linkpath: this.linkpath
|
|
463
|
+
path: this[PREFIX](this.path),
|
|
464
|
+
linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
|
|
465
|
+
: this.linkpath,
|
|
397
466
|
size: this.size,
|
|
398
467
|
uid: this.portable ? null : this.uid,
|
|
399
468
|
uname: this.portable ? null : this.uname,
|
|
@@ -407,6 +476,10 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
407
476
|
readEntry.pipe(this)
|
|
408
477
|
}
|
|
409
478
|
|
|
479
|
+
[PREFIX] (path) {
|
|
480
|
+
return prefixPath(path, this.prefix)
|
|
481
|
+
}
|
|
482
|
+
|
|
410
483
|
[MODE] (mode) {
|
|
411
484
|
return modeFix(mode, this.type === 'Directory', this.portable)
|
|
412
485
|
}
|
|
@@ -421,7 +494,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
421
494
|
|
|
422
495
|
end () {
|
|
423
496
|
if (this.blockRemain)
|
|
424
|
-
|
|
497
|
+
super.write(Buffer.alloc(this.blockRemain))
|
|
425
498
|
return super.end()
|
|
426
499
|
}
|
|
427
500
|
})
|
package/package.json
CHANGED