Skip to content

Commit a52d758

Browse files
committedJan 5, 2021
lint
1 parent e688254 commit a52d758

39 files changed

+3632
-1120
lines changed
 

‎lib/create.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
const hlo = require('./high-level-opt.js')
55

66
const Pack = require('./pack.js')
7-
const fs = require('fs')
87
const fsm = require('fs-minipass')
98
const t = require('./list.js')
109
const path = require('path')
1110

12-
const c = module.exports = (opt_, files, cb) => {
11+
module.exports = (opt_, files, cb) => {
1312
if (typeof files === 'function')
1413
cb = files
1514

@@ -38,7 +37,7 @@ const c = module.exports = (opt_, files, cb) => {
3837
const createFileSync = (opt, files) => {
3938
const p = new Pack.Sync(opt)
4039
const stream = new fsm.WriteStreamSync(opt.file, {
41-
mode: opt.mode || 0o666
40+
mode: opt.mode || 0o666,
4241
})
4342
p.pipe(stream)
4443
addFilesSync(p, files)
@@ -47,7 +46,7 @@ const createFileSync = (opt, files) => {
4746
const createFile = (opt, files, cb) => {
4847
const p = new Pack(opt)
4948
const stream = new fsm.WriteStream(opt.file, {
50-
mode: opt.mode || 0o666
49+
mode: opt.mode || 0o666,
5150
})
5251
p.pipe(stream)
5352

@@ -64,14 +63,14 @@ const createFile = (opt, files, cb) => {
6463

6564
const addFilesSync = (p, files) => {
6665
files.forEach(file => {
67-
if (file.charAt(0) === '@')
66+
if (file.charAt(0) === '@') {
6867
t({
6968
file: path.resolve(p.cwd, file.substr(1)),
7069
sync: true,
7170
noResume: true,
72-
onentry: entry => p.add(entry)
71+
onentry: entry => p.add(entry),
7372
})
74-
else
73+
} else
7574
p.add(file)
7675
})
7776
p.end()
@@ -80,13 +79,13 @@ const addFilesSync = (p, files) => {
8079
const addFilesAsync = (p, files) => {
8180
while (files.length) {
8281
const file = files.shift()
83-
if (file.charAt(0) === '@')
82+
if (file.charAt(0) === '@') {
8483
return t({
8584
file: path.resolve(p.cwd, file.substr(1)),
8685
noResume: true,
87-
onentry: entry => p.add(entry)
86+
onentry: entry => p.add(entry),
8887
}).then(_ => addFilesAsync(p, files))
89-
else
88+
} else
9089
p.add(file)
9190
}
9291
p.end()

‎lib/extract.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fs = require('fs')
77
const fsm = require('fs-minipass')
88
const path = require('path')
99

10-
const x = module.exports = (opt_, files, cb) => {
10+
module.exports = (opt_, files, cb) => {
1111
if (typeof opt_ === 'function')
1212
cb = opt_, files = null, opt_ = {}
1313
else if (Array.isArray(opt_))
@@ -63,22 +63,20 @@ const extractFileSync = opt => {
6363
const u = new Unpack.Sync(opt)
6464

6565
const file = opt.file
66-
let threw = true
67-
let fd
6866
const stat = fs.statSync(file)
6967
// This trades a zero-byte read() syscall for a stat
7068
// However, it will usually result in less memory allocation
71-
const readSize = opt.maxReadSize || 16*1024*1024
69+
const readSize = opt.maxReadSize || 16 * 1024 * 1024
7270
const stream = new fsm.ReadStreamSync(file, {
7371
readSize: readSize,
74-
size: stat.size
72+
size: stat.size,
7573
})
7674
stream.pipe(u)
7775
}
7876

7977
const extractFile = (opt, cb) => {
8078
const u = new Unpack(opt)
81-
const readSize = opt.maxReadSize || 16*1024*1024
79+
const readSize = opt.maxReadSize || 16 * 1024 * 1024
8280

8381
const file = opt.file
8482
const p = new Promise((resolve, reject) => {
@@ -93,7 +91,7 @@ const extractFile = (opt, cb) => {
9391
else {
9492
const stream = new fsm.ReadStream(file, {
9593
readSize: readSize,
96-
size: stat.size
94+
size: stat.size,
9795
})
9896
stream.on('error', reject)
9997
stream.pipe(u)
@@ -103,10 +101,6 @@ const extractFile = (opt, cb) => {
103101
return cb ? p.then(cb, cb) : p
104102
}
105103

106-
const extractSync = opt => {
107-
return new Unpack.Sync(opt)
108-
}
104+
const extractSync = opt => new Unpack.Sync(opt)
109105

110-
const extract = opt => {
111-
return new Unpack(opt)
112-
}
106+
const extract = opt => new Unpack(opt)

‎lib/header.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ class Header {
9595
}
9696

9797
let sum = 8 * 0x20
98-
for (let i = off; i < off + 148; i++) {
98+
for (let i = off; i < off + 148; i++)
9999
sum += buf[i]
100-
}
101-
for (let i = off + 156; i < off + 512; i++) {
100+
101+
for (let i = off + 156; i < off + 512; i++)
102102
sum += buf[i]
103-
}
103+
104104
this.cksumValid = sum === this.cksum
105105
if (this.cksum === null && sum === 8 * 0x20)
106106
this.nullBlock = true
107107
}
108108

109109
[SLURP] (ex, global) {
110-
for (let k in ex) {
110+
for (const k in ex) {
111111
// we slurp in everything except for the path attribute in
112112
// a global extended header, because that's weird.
113113
if (ex[k] !== null && ex[k] !== undefined &&
@@ -157,12 +157,12 @@ class Header {
157157
}
158158

159159
let sum = 8 * 0x20
160-
for (let i = off; i < off + 148; i++) {
160+
for (let i = off; i < off + 148; i++)
161161
sum += buf[i]
162-
}
163-
for (let i = off + 156; i < off + 512; i++) {
162+
163+
for (let i = off + 156; i < off + 512; i++)
164164
sum += buf[i]
165-
}
165+
166166
this.cksum = sum
167167
encNumber(buf, off + 148, 8, this.cksum)
168168
this.cksumValid = true
@@ -171,7 +171,7 @@ class Header {
171171
}
172172

173173
set (data) {
174-
for (let i in data) {
174+
for (const i in data) {
175175
if (data[i] !== null && data[i] !== undefined)
176176
this[i] = data[i]
177177
}
@@ -242,7 +242,7 @@ const numToDate = num => num === null ? null : new Date(num * 1000)
242242

243243
const decNumber = (buf, off, size) =>
244244
buf[off] & 0x80 ? large.parse(buf.slice(off, off + size))
245-
: decSmallNumber(buf, off, size)
245+
: decSmallNumber(buf, off, size)
246246

247247
const nanNull = value => isNaN(value) ? null : value
248248

@@ -254,7 +254,7 @@ const decSmallNumber = (buf, off, size) =>
254254
// the maximum encodable as a null-terminated octal, by field size
255255
const MAXNUM = {
256256
12: 0o77777777777,
257-
8 : 0o7777777
257+
8: 0o7777777,
258258
}
259259

260260
const encNumber = (buf, off, size, number) =>
@@ -283,6 +283,6 @@ const NULLS = new Array(156).join('\0')
283283
const encString = (buf, off, size, string) =>
284284
string === null ? false :
285285
(buf.write(string + NULLS, off, size, 'utf8'),
286-
string.length !== Buffer.byteLength(string) || string.length > size)
286+
string.length !== Buffer.byteLength(string) || string.length > size)
287287

288288
module.exports = Header

‎lib/high-level-opt.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const argmap = new Map([
2121
['no-mtime', 'noMtime'],
2222
['p', 'preserveOwner'],
2323
['L', 'follow'],
24-
['h', 'follow']
24+
['h', 'follow'],
2525
])
2626

27-
const parse = module.exports = opt => opt ? Object.keys(opt).map(k => [
28-
argmap.has(k) ? argmap.get(k) : k, opt[k]
27+
module.exports = opt => opt ? Object.keys(opt).map(k => [
28+
argmap.has(k) ? argmap.get(k) : k, opt[k],
2929
]).reduce((set, kv) => (set[kv[0]] = kv[1], set), Object.create(null)) : {}

‎lib/large-numbers.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Tar can encode large and negative numbers using a leading byte of
33
// 0xff for negative, and 0x80 for positive.
44

5-
const encode = exports.encode = (num, buf) => {
5+
const encode = (num, buf) => {
66
if (!Number.isSafeInteger(num))
77
// The number is so large that javascript cannot represent it with integer
88
// precision.
@@ -18,7 +18,7 @@ const encodePositive = (num, buf) => {
1818
buf[0] = 0x80
1919

2020
for (var i = buf.length; i > 1; i--) {
21-
buf[i-1] = num & 0xff
21+
buf[i - 1] = num & 0xff
2222
num = Math.floor(num / 0x100)
2323
}
2424
}
@@ -31,25 +31,22 @@ const encodeNegative = (num, buf) => {
3131
var byte = num & 0xff
3232
num = Math.floor(num / 0x100)
3333
if (flipped)
34-
buf[i-1] = onesComp(byte)
34+
buf[i - 1] = onesComp(byte)
3535
else if (byte === 0)
36-
buf[i-1] = 0
36+
buf[i - 1] = 0
3737
else {
3838
flipped = true
39-
buf[i-1] = twosComp(byte)
39+
buf[i - 1] = twosComp(byte)
4040
}
4141
}
4242
}
4343

44-
const parse = exports.parse = (buf) => {
45-
var post = buf[buf.length - 1]
46-
var pre = buf[0]
47-
var value;
48-
if (pre === 0x80)
49-
value = pos(buf.slice(1, buf.length))
50-
else if (pre === 0xff)
51-
value = twos(buf)
52-
else
44+
const parse = (buf) => {
45+
const pre = buf[0]
46+
const value = pre === 0x80 ? pos(buf.slice(1, buf.length))
47+
: pre === 0xff ? twos(buf)
48+
: null
49+
if (value === null)
5350
throw Error('invalid base256 encoding')
5451

5552
if (!Number.isSafeInteger(value))
@@ -95,3 +92,8 @@ const pos = (buf) => {
9592
const onesComp = byte => (0xff ^ byte) & 0xff
9693

9794
const twosComp = byte => ((0xff ^ byte) + 1) & 0xff
95+
96+
module.exports = {
97+
encode,
98+
parse,
99+
}

‎lib/list.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const fs = require('fs')
1010
const fsm = require('fs-minipass')
1111
const path = require('path')
1212

13-
const t = module.exports = (opt_, files, cb) => {
13+
module.exports = (opt_, files, cb) => {
1414
if (typeof opt_ === 'function')
1515
cb = opt_, files = null, opt_ = {}
1616
else if (Array.isArray(opt_))
@@ -79,30 +79,33 @@ const listFileSync = opt => {
7979
let fd
8080
try {
8181
const stat = fs.statSync(file)
82-
const readSize = opt.maxReadSize || 16*1024*1024
83-
if (stat.size < readSize) {
82+
const readSize = opt.maxReadSize || 16 * 1024 * 1024
83+
if (stat.size < readSize)
8484
p.end(fs.readFileSync(file))
85-
} else {
85+
else {
8686
let pos = 0
8787
const buf = Buffer.allocUnsafe(readSize)
8888
fd = fs.openSync(file, 'r')
8989
while (pos < stat.size) {
90-
let bytesRead = fs.readSync(fd, buf, 0, readSize, pos)
90+
const bytesRead = fs.readSync(fd, buf, 0, readSize, pos)
9191
pos += bytesRead
9292
p.write(buf.slice(0, bytesRead))
9393
}
9494
p.end()
9595
}
9696
threw = false
9797
} finally {
98-
if (threw && fd)
99-
try { fs.closeSync(fd) } catch (er) {}
98+
if (threw && fd) {
99+
try {
100+
fs.closeSync(fd)
101+
} catch (er) {}
102+
}
100103
}
101104
}
102105

103106
const listFile = (opt, cb) => {
104107
const parse = new Parser(opt)
105-
const readSize = opt.maxReadSize || 16*1024*1024
108+
const readSize = opt.maxReadSize || 16 * 1024 * 1024
106109

107110
const file = opt.file
108111
const p = new Promise((resolve, reject) => {
@@ -115,7 +118,7 @@ const listFile = (opt, cb) => {
115118
else {
116119
const stream = new fsm.ReadStream(file, {
117120
readSize: readSize,
118-
size: stat.size
121+
size: stat.size,
119122
})
120123
stream.on('error', reject)
121124
stream.pipe(parse)

0 commit comments

Comments
 (0)
Please sign in to comment.