Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 037bd03

Browse files
committed
fix style
1 parent 794de32 commit 037bd03

File tree

2 files changed

+60
-60
lines changed

2 files changed

+60
-60
lines changed

index.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ var os = require('os')
77

88
var win32 = os.platform() === 'win32'
99

10-
var noop = function() {}
10+
var noop = function () {}
1111

12-
var echo = function(name) {
12+
var echo = function (name) {
1313
return name
1414
}
1515

16-
var normalize = !win32 ? echo : function(name) {
16+
var normalize = !win32 ? echo : function (name) {
1717
return name.replace(/\\/g, '/').replace(/:/g, '_')
1818
}
1919

20-
var statAll = function(fs, stat, cwd, ignore, entries) {
20+
var statAll = function (fs, stat, cwd, ignore, entries) {
2121
var queue = entries || ['.']
2222

23-
return function loop(callback) {
23+
return function loop (callback) {
2424
if (!queue.length) return callback()
2525
var next = queue.shift()
2626
var nextAbs = path.join(cwd, next)
2727

28-
stat(nextAbs, function(err, stat) {
28+
stat(nextAbs, function (err, stat) {
2929
if (err) return callback(err)
3030

3131
if (!stat.isDirectory()) return callback(null, next, stat)
3232

33-
fs.readdir(nextAbs, function(err, files) {
33+
fs.readdir(nextAbs, function (err, files) {
3434
if (err) return callback(err)
3535

3636
for (var i = 0; i < files.length; i++) {
@@ -43,15 +43,15 @@ var statAll = function(fs, stat, cwd, ignore, entries) {
4343
}
4444
}
4545

46-
var strip = function(map, level) {
47-
return function(header) {
46+
var strip = function (map, level) {
47+
return function (header) {
4848
header.name = header.name.split('/').slice(level).join('/')
4949
if (header.linkname) header.linkname = header.linkname.split('/').slice(level).join('/')
5050
return map(header)
5151
}
5252
}
5353

54-
exports.pack = function(cwd, opts) {
54+
exports.pack = function (cwd, opts) {
5555
if (!cwd) cwd = '.'
5656
if (!opts) opts = {}
5757

@@ -65,15 +65,15 @@ exports.pack = function(cwd, opts) {
6565

6666
if (opts.strip) map = strip(map, opts.strip)
6767

68-
var onlink = function(filename, header) {
69-
xfs.readlink(path.join(cwd, filename), function(err, linkname) {
68+
var onlink = function (filename, header) {
69+
xfs.readlink(path.join(cwd, filename), function (err, linkname) {
7070
if (err) return pack.destroy(err)
7171
header.linkname = normalize(linkname)
7272
pack.entry(header, onnextentry)
7373
})
7474
}
7575

76-
var onstat = function(err, filename, stat) {
76+
var onstat = function (err, filename, stat) {
7777
if (err) return pack.destroy(err)
7878
if (!filename) return pack.finalize()
7979

@@ -106,7 +106,7 @@ exports.pack = function(cwd, opts) {
106106
// TODO: add fifo etc...
107107

108108
if (!stat.isFile()) {
109-
if (strict) return pack.destroy(new Error('unsupported type for '+filename))
109+
if (strict) return pack.destroy(new Error('unsupported type for ' + filename))
110110
return onnextentry()
111111
}
112112

@@ -115,14 +115,14 @@ exports.pack = function(cwd, opts) {
115115

116116
var rs = mapStream(xfs.createReadStream(path.join(cwd, filename)), header)
117117

118-
rs.on('error', function(err) { // always forward errors on destroy
118+
rs.on('error', function (err) { // always forward errors on destroy
119119
entry.destroy(err)
120120
})
121121

122122
pump(rs, entry)
123123
}
124124

125-
var onnextentry = function(err) {
125+
var onnextentry = function (err) {
126126
if (err) return pack.destroy(err)
127127
statNext(onstat)
128128
}
@@ -132,19 +132,19 @@ exports.pack = function(cwd, opts) {
132132
return pack
133133
}
134134

135-
var head = function(list) {
135+
var head = function (list) {
136136
return list.length ? list[list.length-1] : null
137137
}
138138

139-
var processGetuid = function() {
139+
var processGetuid = function () {
140140
return process.getuid ? process.getuid() : -1
141141
}
142142

143-
var processUmask = function() {
143+
var processUmask = function () {
144144
return process.umask ? process.umask() : 0
145145
}
146146

147-
exports.extract = function(cwd, opts) {
147+
exports.extract = function (cwd, opts) {
148148
if (!cwd) cwd = '.'
149149
if (!opts) opts = {}
150150

@@ -172,40 +172,40 @@ exports.extract = function(cwd, opts) {
172172
fmode |= 0222
173173
}
174174

175-
var utimesParent = function(name, cb) { // we just set the mtime on the parent dir again everytime we write an entry
175+
var utimesParent = function (name, cb) { // we just set the mtime on the parent dir again everytime we write an entry
176176
var top
177177
while ((top = head(stack)) && name.slice(0, top[0].length) !== top[0]) stack.pop()
178178
if (!top) return cb()
179179
xfs.utimes(top[0], now, top[1], cb)
180180
}
181181

182-
var utimes = function(name, header, cb) {
182+
var utimes = function (name, header, cb) {
183183
if (opts.utimes === false) return cb()
184184

185185
if (header.type === 'directory') return xfs.utimes(name, now, header.mtime, cb)
186186
if (header.type === 'symlink') return utimesParent(name, cb) // TODO: how to set mtime on link?
187187

188-
xfs.utimes(name, now, header.mtime, function(err) {
188+
xfs.utimes(name, now, header.mtime, function (err) {
189189
if (err) return cb(err)
190190
utimesParent(name, cb)
191191
})
192192
}
193193

194-
var chperm = function(name, header, cb) {
194+
var chperm = function (name, header, cb) {
195195
var link = header.type === 'symlink'
196196
var chmod = link ? xfs.lchmod : xfs.chmod
197197
var chown = link ? xfs.lchown : xfs.chown
198198

199199
if (!chmod) return cb()
200-
chmod(name, (header.mode | (header.type === 'directory' ? dmode : fmode)) & umask, function(err) {
200+
chmod(name, (header.mode | (header.type === 'directory' ? dmode : fmode)) & umask, function (err) {
201201
if (err) return cb(err)
202202
if (!own) return cb()
203203
if (!chown) return cb()
204204
chown(name, header.uid, header.gid, cb)
205205
})
206206
}
207207

208-
extract.on('entry', function(header, stream, next) {
208+
extract.on('entry', function (header, stream, next) {
209209
header = map(header) || header
210210
header.name = normalize(header.name)
211211
var name = path.join(cwd, path.join('/', header.name))
@@ -215,31 +215,31 @@ exports.extract = function(cwd, opts) {
215215
return next()
216216
}
217217

218-
var stat = function(err) {
218+
var stat = function (err) {
219219
if (err) return next(err)
220220
if (win32) return next()
221-
utimes(name, header, function(err) {
221+
utimes(name, header, function (err) {
222222
if (err) return next(err)
223223
chperm(name, header, next)
224224
})
225225
}
226226

227-
var onlink = function() {
227+
var onlink = function () {
228228
if (win32) return next() // skip symlinks on win for now before it can be tested
229-
xfs.unlink(name, function() {
229+
xfs.unlink(name, function () {
230230
xfs.symlink(header.linkname, name, stat)
231231
})
232232
}
233233

234-
var onfile = function() {
234+
var onfile = function () {
235235
var ws = xfs.createWriteStream(name)
236236
var rs = mapStream(stream, header)
237237

238-
ws.on('error', function(err) { // always forward errors on destroy
238+
ws.on('error', function (err) { // always forward errors on destroy
239239
rs.destroy(err)
240240
})
241241

242-
pump(rs, ws, function(err) {
242+
pump(rs, ws, function (err) {
243243
if (err) return next(err)
244244
ws.on('close', stat)
245245
})
@@ -250,12 +250,12 @@ exports.extract = function(cwd, opts) {
250250
return mkdirp(name, {fs:xfs}, stat)
251251
}
252252

253-
mkdirp(path.dirname(name), {fs:xfs}, function(err) {
253+
mkdirp(path.dirname(name), {fs:xfs}, function (err) {
254254
if (err) return next(err)
255255
if (header.type === 'symlink') return onlink()
256256

257257
if (header.type !== 'file') {
258-
if (strict) return next(new Error('unsupported type for '+name+' ('+header.type+')'))
258+
if (strict) return next(new Error('unsupported type for ' + name + ' (' + header.type + ')'))
259259
stream.resume()
260260
return next()
261261
}

test/index.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var os = require('os')
77

88
var win32 = os.platform() === 'win32'
99

10-
test('copy a -> copy/a', function(t) {
10+
test('copy a -> copy/a', function (t) {
1111
t.plan(5)
1212

1313
var a = path.join(__dirname, 'fixtures', 'a')
@@ -28,7 +28,7 @@ test('copy a -> copy/a', function(t) {
2828
})
2929
})
3030

31-
test('copy b -> copy/b', function(t) {
31+
test('copy b -> copy/b', function (t) {
3232
t.plan(8)
3333

3434
var a = path.join(__dirname, 'fixtures', 'b')
@@ -54,7 +54,7 @@ test('copy b -> copy/b', function(t) {
5454
})
5555
})
5656

57-
test('symlink', function(t) {
57+
test('symlink', function (t) {
5858
if (win32) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
5959
t.plan(1)
6060
t.ok(true)
@@ -87,7 +87,7 @@ test('symlink', function(t) {
8787
})
8888
})
8989

90-
test('follow symlinks', function(t) {
90+
test('follow symlinks', function (t) {
9191
if (win32) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow
9292
t.plan(1)
9393
t.ok(true)
@@ -106,7 +106,7 @@ test('follow symlinks', function(t) {
106106
rimraf.sync(b)
107107
tar.pack(a, {dereference: true})
108108
.pipe(tar.extract(b))
109-
.on('finish', function() {
109+
.on('finish', function () {
110110
var files = fs.readdirSync(b).sort()
111111
t.same(files.length, 2)
112112
t.same(files[0], '.gitignore')
@@ -121,7 +121,7 @@ test('follow symlinks', function(t) {
121121
})
122122

123123

124-
test('strip', function(t) {
124+
test('strip', function (t) {
125125
t.plan(2)
126126

127127
var a = path.join(__dirname, 'fixtures', 'b')
@@ -131,61 +131,61 @@ test('strip', function(t) {
131131

132132
tar.pack(a)
133133
.pipe(tar.extract(b, {strip:1}))
134-
.on('finish', function() {
135-
var files = fs.readdirSync(b).sort()
136-
t.same(files.length, 1)
137-
t.same(files[0], 'test.js')
134+
.on('finish', function () {
135+
var files = fs.readdirSync(b).sort()
136+
t.same(files.length, 1)
137+
t.same(files[0], 'test.js')
138138
})
139139
})
140140

141-
test('strip + map', function(t) {
141+
test('strip + map', function (t) {
142142
t.plan(2)
143143

144144
var a = path.join(__dirname, 'fixtures', 'b')
145145
var b = path.join(__dirname, 'fixtures', 'copy', 'b-strip')
146146

147147
rimraf.sync(b)
148148

149-
var uppercase = function(header) {
149+
var uppercase = function (header) {
150150
header.name = header.name.toUpperCase()
151151
return header
152152
}
153153

154154
tar.pack(a)
155155
.pipe(tar.extract(b, {strip:1, map:uppercase}))
156-
.on('finish', function() {
157-
var files = fs.readdirSync(b).sort()
158-
t.same(files.length, 1)
159-
t.same(files[0], 'TEST.JS')
156+
.on('finish', function () {
157+
var files = fs.readdirSync(b).sort()
158+
t.same(files.length, 1)
159+
t.same(files[0], 'TEST.JS')
160160
})
161161
})
162162

163-
test('map + dir + permissions', function(t) {
163+
test('map + dir + permissions', function (t) {
164164
t.plan(2)
165165

166166
var a = path.join(__dirname, 'fixtures', 'b')
167167
var b = path.join(__dirname, 'fixtures', 'copy', 'a-perms')
168168

169169
rimraf.sync(b)
170170

171-
var aWithMode = function(header) {
171+
var aWithMode = function (header) {
172172
if(header.name === 'a') {
173-
header.mode = 0700;
173+
header.mode = 0700
174174
}
175175
return header
176-
};
176+
}
177177

178178
tar.pack(a)
179179
.pipe(tar.extract(b, {map:aWithMode}))
180-
.on('finish', function() {
180+
.on('finish', function () {
181181
var files = fs.readdirSync(b).sort()
182-
var stat = fs.statSync(path.join(b, 'a'));
182+
var stat = fs.statSync(path.join(b, 'a'))
183183
t.same(files.length, 1)
184184
t.same(stat.mode & 0777, 0700)
185185
})
186-
});
186+
})
187187

188-
test('specific entries', function(t) {
188+
test('specific entries', function (t) {
189189
t.plan(6)
190190

191191
var a = path.join(__dirname, 'fixtures', 'd')
@@ -196,7 +196,7 @@ test('specific entries', function(t) {
196196
rimraf.sync(b)
197197
tar.pack(a, { entries: entries })
198198
.pipe(tar.extract(b))
199-
.on('finish', function() {
199+
.on('finish', function () {
200200
var files = fs.readdirSync(b)
201201
t.same(files.length, 3)
202202
t.notSame(files.indexOf('file1'), -1)

0 commit comments

Comments
 (0)