Skip to content

Commit e16ac55

Browse files
committed
more conventional indentations
1 parent ec8087e commit e16ac55

File tree

2 files changed

+76
-76
lines changed

2 files changed

+76
-76
lines changed

lib/index.js

+57-57
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
var busboy = require('connect-busboy'),
2-
fs = require('fs-extra'),
3-
streamifier = require('streamifier');
2+
fs = require('fs-extra'),
3+
streamifier = require('streamifier');
44

55
module.exports = function(options) {
6-
options = options || {};
6+
options = options || {};
77

8-
return function(req, res, next) {
9-
return busboy(options)(req, res, function() {
8+
return function(req, res, next) {
9+
return busboy(options)(req, res, function() {
1010

11-
// If no busboy req obj, then no uploads are taking place
12-
if (!req.busboy)
13-
return next();
11+
// If no busboy req obj, then no uploads are taking place
12+
if (!req.busboy)
13+
return next();
1414

15-
req.files = null;
15+
req.files = null;
1616

17-
req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
18-
req.body = req.body || {};
19-
req.body[fieldname] = val;
20-
});
17+
req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
18+
req.body = req.body || {};
19+
req.body[fieldname] = val;
20+
});
2121

22-
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
23-
var buf = new Buffer(0);
22+
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
23+
var buf = new Buffer(0);
2424

25-
file.on('data', function(data) {
26-
buf = Buffer.concat([buf, data]);
27-
if (options.debug) {
28-
return console.log('Uploading %s -> %s', fieldname, filename);
29-
}
30-
});
25+
file.on('data', function(data) {
26+
buf = Buffer.concat([buf, data]);
27+
if (options.debug) {
28+
return console.log('Uploading %s -> %s', fieldname, filename);
29+
}
30+
});
3131

32-
file.on('end', function() {
33-
if (!req.files)
34-
req.files = {};
35-
36-
37-
// see: https://github.com/richardgirges/express-fileupload/issues/14
38-
// firefox uploads empty file in case of cache miss when f5ing page.
39-
// resulting in unexpected behavior. if there is no file data, the file is invalid.
40-
41-
if(!buf.length)
42-
return;
32+
file.on('end', function() {
33+
if (!req.files)
34+
req.files = {};
35+
36+
37+
// see: https://github.com/richardgirges/express-fileupload/issues/14
38+
// firefox uploads empty file in case of cache miss when f5ing page.
39+
// resulting in unexpected behavior. if there is no file data, the file is invalid.
40+
41+
if(!buf.length)
42+
return;
4343

44-
return req.files[fieldname] = {
45-
name: filename,
46-
data: buf,
47-
encoding: encoding,
48-
mimetype: mimetype,
49-
mv: function(path, callback) {
50-
var fstream;
51-
fstream = fs.createWriteStream(path);
52-
streamifier.createReadStream(buf).pipe(fstream);
53-
fstream.on('error', function(error) {
54-
callback(error);
55-
});
56-
fstream.on('close', function() {
57-
callback(null);
58-
});
59-
}
60-
};
61-
62-
63-
});
64-
});
44+
return req.files[fieldname] = {
45+
name: filename,
46+
data: buf,
47+
encoding: encoding,
48+
mimetype: mimetype,
49+
mv: function(path, callback) {
50+
var fstream;
51+
fstream = fs.createWriteStream(path);
52+
streamifier.createReadStream(buf).pipe(fstream);
53+
fstream.on('error', function(error) {
54+
callback(error);
55+
});
56+
fstream.on('close', function() {
57+
callback(null);
58+
});
59+
}
60+
};
61+
62+
63+
});
64+
});
6565

66-
req.busboy.on('finish', next);
66+
req.busboy.on('finish', next);
6767

68-
req.pipe(req.busboy);
69-
});
70-
};
68+
req.pipe(req.busboy);
69+
});
70+
};
7171
};

test/upload.test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
var express = require('express'),
2-
fileUpload = require('../lib/index.js'),
3-
app = express();
2+
fileUpload = require('../lib/index.js'),
3+
app = express();
44

55
app.use('/form', express.static(__dirname + '/upload.test.html'));
66

77
// default options
88
app.use(fileUpload());
99

1010
app.get('/ping', function(req, res) {
11-
res.send('pong');
11+
res.send('pong');
1212
});
1313

1414
app.post('/upload', function(req, res) {
15-
var sampleFile, uploadPath;
15+
var sampleFile, uploadPath;
1616

17-
if (!req.files) {
18-
res.status(400).send('No files were uploaded.');
19-
return;
20-
}
17+
if (!req.files) {
18+
res.status(400).send('No files were uploaded.');
19+
return;
20+
}
2121

22-
sampleFile = req.files.sampleFile;
22+
sampleFile = req.files.sampleFile;
2323

24-
uploadPath = __dirname + '/uploadedfiles/' + sampleFile.name;
24+
uploadPath = __dirname + '/uploadedfiles/' + sampleFile.name;
2525

26-
sampleFile.mv(uploadPath, function(err) {
27-
if (err) {
28-
res.status(500).send(err);
29-
}
30-
else {
31-
res.send('File uploaded to ' + uploadPath);
32-
}
33-
});
26+
sampleFile.mv(uploadPath, function(err) {
27+
if (err) {
28+
res.status(500).send(err);
29+
}
30+
else {
31+
res.send('File uploaded to ' + uploadPath);
32+
}
33+
});
3434
});
3535

3636
app.listen(8000, function() {
37-
console.log('Express server listening on port 8000');
37+
console.log('Express server listening on port 8000');
3838
})

0 commit comments

Comments
 (0)