Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Go back to traditional coding style

Comma first doesn't seem light it has caught on, so this commit changes
the projects coding style back to the Google-ish standard formatting.
  • Loading branch information...
commit ed4e2972cd5a80baa9c758b59800f5a912c04959 1 parent 0e54a07
@felixge authored
View
20 Readme.md
@@ -34,9 +34,9 @@ Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run
Parse an incoming file upload.
- var formidable = require('formidable')
- , http = require('http')
- , sys = require('sys');
+ var formidable = require('formidable'),
+ http = require('http')
@mscdex
mscdex added a note

Shouldn't there be a comma at the end here? :-)

@gf3
gf3 added a note

Hehehe

@dvv
dvv added a note

This is just readme :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ sys = require('sys');
http.createServer(function(req, res) {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
@@ -52,13 +52,13 @@ Parse an incoming file upload.
// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
- res.end
- ( '<form action="/upload" enctype="multipart/form-data" method="post">'
- + '<input type="text" name="title"><br>'
- + '<input type="file" name="upload" multiple="multiple"><br>'
- + '<input type="submit" value="Upload">'
- + '</form>'
- );
+ res.end(
+ '<form action="/upload" enctype="multipart/form-data" method="post">'+
+ '<input type="text" name="title"><br>'+
+ '<input type="file" name="upload" multiple="multiple"><br>'+
+ '<input type="submit" value="Upload">'+
+ '</form>'
+ );
});
## API
View
42 benchmark/bench-multipart-parser.js
@@ -1,18 +1,18 @@
require('../test/common');
-var multipartParser = require('formidable/multipart_parser')
- , MultipartParser = multipartParser.MultipartParser
- , parser = new MultipartParser()
- , Buffer = require('buffer').Buffer
- , boundary = '-----------------------------168072824752491622650073'
- , mb = 100
- , buffer = createMultipartBuffer(boundary, mb * 1024 * 1024)
- , callbacks =
- { partBegin: -1
- , partEnd: -1
- , headerField: -1
- , headerValue: -1
- , partData: -1
- , end: -1
+var multipartParser = require('formidable/multipart_parser'),
+ MultipartParser = multipartParser.MultipartParser,
+ parser = new MultipartParser(),
+ Buffer = require('buffer').Buffer,
+ boundary = '-----------------------------168072824752491622650073',
+ mb = 100,
+ buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
+ callbacks =
+ { partBegin: -1,
+ partEnd: -1,
+ headerField: -1,
+ headerValue: -1,
+ partData: -1,
+ end: -1,
};
@@ -41,10 +41,10 @@ parser.onEnd = function() {
callbacks.end++;
};
-var start = +new Date()
- , nparsed = parser.write(buffer)
- , duration = +new Date - start
- , mbPerSec = (mb / (duration / 1000)).toFixed(2);
+var start = +new Date(),
+ nparsed = parser.write(buffer),
+ duration = +new Date - start,
+ mbPerSec = (mb / (duration / 1000)).toFixed(2);
p(mbPerSec+' mb/sec');
@@ -63,4 +63,8 @@ function createMultipartBuffer(boundary, size) {
return buffer;
}
-assert.callbacks(callbacks);
+process.on('exit', function() {
+ for (var k in callbacks) {
+ assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
+ }
+});
View
26 example/post.js
@@ -1,22 +1,22 @@
require('../test/common');
-var http = require('http')
- , util = require('util')
- , formidable = require('formidable')
- , server;
+var http = require('http'),
+ util = require('util'),
+ formidable = require('formidable'),
+ server;
server = http.createServer(function(req, res) {
if (req.url == '/') {
res.writeHead(200, {'content-type': 'text/html'});
- res.end
- ( '<form action="/post" method="post">'
- + '<input type="text" name="title"><br>'
- + '<input type="text" name="data[foo][]"><br>'
- + '<input type="submit" value="Submit">'
- + '</form>'
- )
+ res.end(
+ '<form action="/post" method="post">'+
+ '<input type="text" name="title"><br>'+
+ '<input type="text" name="data[foo][]"><br>'+
+ '<input type="submit" value="Submit">'+
+ '</form>'
+ );
} else if (req.url == '/post') {
- var form = new formidable.IncomingForm()
- , fields = [];
+ var form = new formidable.IncomingForm(),
+ fields = [];
form
.on('error', function(err) {
View
28 example/upload.js
@@ -1,23 +1,23 @@
require('../test/common');
-var http = require('http')
- , util = require('util')
- , formidable = require('formidable')
- , server;
+var http = require('http'),
+ util = require('util'),
+ formidable = require('formidable'),
+ server;
server = http.createServer(function(req, res) {
if (req.url == '/') {
res.writeHead(200, {'content-type': 'text/html'});
- res.end
- ( '<form action="/upload" enctype="multipart/form-data" method="post">'
- + '<input type="text" name="title"><br>'
- + '<input type="file" name="upload" multiple="multiple"><br>'
- + '<input type="submit" value="Upload">'
- + '</form>'
- )
+ res.end(
+ '<form action="/upload" enctype="multipart/form-data" method="post">'+
+ '<input type="text" name="title"><br>'+
+ '<input type="file" name="upload" multiple="multiple"><br>'+
+ '<input type="submit" value="Upload">'+
+ '</form>'
+ );
} else if (req.url == '/upload') {
- var form = new formidable.IncomingForm()
- , files = []
- , fields = [];
+ var form = new formidable.IncomingForm(),
+ files = [],
+ fields = [];
form.uploadDir = TEST_TMP;
View
28 lib/formidable/incoming_form.js
@@ -1,12 +1,12 @@
if (global.GENTLY) require = GENTLY.hijack(require);
var util = require('./util')
@dvv
dvv added a note

Please, append comma here

--Vladimir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- , path = require('path')
- , File = require('./file')
- , MultipartParser = require('./multipart_parser').MultipartParser
- , QuerystringParser = require('./querystring_parser').QuerystringParser
- , StringDecoder = require('string_decoder').StringDecoder
- , EventEmitter = require('events').EventEmitter;
+ path = require('path'),
+ File = require('./file'),
+ MultipartParser = require('./multipart_parser').MultipartParser,
+ QuerystringParser = require('./querystring_parser').QuerystringParser,
+ StringDecoder = require('string_decoder').StringDecoder,
+ EventEmitter = require('events').EventEmitter;
function IncomingForm() {
if (!(this instanceof IncomingForm)) return new IncomingForm;
@@ -185,11 +185,7 @@ IncomingForm.prototype.handlePart = function(part) {
part.on('end', function() {
file.end(function() {
self._flushing--;
- self.emit
- ( 'file'
- , part.name
- , file
- );
+ self.emit('file', part.name, file);
self._maybeEnd();
});
});
@@ -243,11 +239,11 @@ IncomingForm.prototype._newParser = function() {
IncomingForm.prototype._initMultipart = function(boundary) {
this.type = 'multipart';
- var parser = new MultipartParser()
- , self = this
- , headerField
- , headerValue
- , part;
+ var parser = new MultipartParser(),
+ self = this,
+ headerField,
+ headerValue,
+ part;
parser.initWithBoundary(boundary);
View
106 lib/formidable/multipart_parser.js
@@ -1,36 +1,36 @@
var Buffer = require('buffer').Buffer
- , s = 0
- , S =
- { PARSER_UNINITIALIZED: s++
- , START: s++
- , START_BOUNDARY: s++
- , HEADER_FIELD_START: s++
- , HEADER_FIELD: s++
- , HEADER_VALUE_START: s++
- , HEADER_VALUE: s++
- , HEADER_VALUE_ALMOST_DONE: s++
- , HEADERS_ALMOST_DONE: s++
- , PART_DATA_START: s++
- , PART_DATA: s++
- , PART_END: s++
- , END: s++
- }
+ s = 0,
+ S =
+ { PARSER_UNINITIALIZED: s++,
+ START: s++,
+ START_BOUNDARY: s++,
+ HEADER_FIELD_START: s++,
+ HEADER_FIELD: s++,
+ HEADER_VALUE_START: s++,
+ HEADER_VALUE: s++,
+ HEADER_VALUE_ALMOST_DONE: s++,
+ HEADERS_ALMOST_DONE: s++,
+ PART_DATA_START: s++,
+ PART_DATA: s++,
+ PART_END: s++,
+ END: s++,
+ },
- , f = 1
- , F =
- { PART_BOUNDARY: f
- , LAST_BOUNDARY: f *= 2
- }
+ f = 1,
+ F =
+ { PART_BOUNDARY: f,
+ LAST_BOUNDARY: f *= 2,
+ },
- , LF = 10
- , CR = 13
- , SPACE = 32
- , HYPHEN = 45
- , COLON = 58
- , A = 97
- , Z = 122
+ LF = 10,
+ CR = 13,
+ SPACE = 32,
+ HYPHEN = 45,
+ COLON = 58,
+ A = 97,
+ Z = 122,
- , lower = function(c) {
+ lower = function(c) {
return c | 0x20;
};
@@ -63,29 +63,29 @@ MultipartParser.prototype.initWithBoundary = function(str) {
};
MultipartParser.prototype.write = function(buffer) {
- var self = this
- , i = 0
- , len = buffer.length
- , prevIndex = this.index
- , index = this.index
- , state = this.state
- , flags = this.flags
- , lookbehind = this.lookbehind
- , boundary = this.boundary
- , boundaryChars = this.boundaryChars
- , boundaryLength = this.boundary.length
- , boundaryEnd = boundaryLength - 1
- , bufferLength = buffer.length
- , c
- , cl
+ var self = this,
+ i = 0,
+ len = buffer.length,
+ prevIndex = this.index,
+ index = this.index,
+ state = this.state,
+ flags = this.flags,
+ lookbehind = this.lookbehind,
+ boundary = this.boundary,
+ boundaryChars = this.boundaryChars,
+ boundaryLength = this.boundary.length,
+ boundaryEnd = boundaryLength - 1,
+ bufferLength = buffer.length,
+ c,
+ cl,
- , mark = function(name) {
+ mark = function(name) {
self[name+'Mark'] = i;
- }
- , clear = function(name) {
+ },
+ clear = function(name) {
delete self[name+'Mark'];
- }
- , callback = function(name, buffer, start, end) {
+ },
+ callback = function(name, buffer, start, end) {
if (start !== undefined && start === end) {
return;
}
@@ -94,8 +94,8 @@ MultipartParser.prototype.write = function(buffer) {
if (callbackSymbol in self) {
self[callbackSymbol](buffer, start, end);
}
- }
- , dataCallback = function(name, clear) {
+ },
+ dataCallback = function(name, clear) {
var markSymbol = name+'Mark';
if (!(markSymbol in self)) {
return;
@@ -288,7 +288,7 @@ MultipartParser.prototype.write = function(buffer) {
// it could be the beginning of a new sequence
i--;
}
-
+
break;
default:
return i;
@@ -310,4 +310,4 @@ MultipartParser.prototype.end = function() {
if (this.state != S.END) {
return new Error('MultipartParser.end(): stream ended unexpectedly');
}
-};
+};
View
10 package.json
@@ -1,6 +1,6 @@
-{ "name" : "formidable"
-, "version": "0.9.8"
-, "dependencies": {"gently": ">=0.7.0"}
-, "directories" : { "lib" : "./lib/formidable" }
-, "main" : "./lib/formidable/index"
+{ "name" : "formidable",
+ "version": "0.9.8",
+ "dependencies": {"gently": ">=0.7.0"},
+ "directories" : { "lib" : "./lib/formidable" },
+ "main" : "./lib/formidable/index",
@dvv
dvv added a note

Please, remove the trailing comma here -- json doesn't allow pending commas. W/o this the package cannot be require()d by nodules

TIA,
--Vladimir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
View
43 test/common.js
@@ -1,6 +1,5 @@
-var path = require('path')
- , fs = require('fs')
- , timeout;
+var path = require('path'),
+ fs = require('fs');
require.paths.unshift(path.dirname(__dirname)+'/lib');
var util = require('formidable/util');
@@ -21,41 +20,3 @@ global.assert = require('assert');
global.TEST_PORT = 13532;
global.TEST_FIXTURES = path.join(__dirname, 'fixture');
global.TEST_TMP = path.join(__dirname, 'tmp');
-
-assert.timeout = function(ms) {
- return setTimeout(function() {
- timeout = 'timeout (after '+ms+' ms): ';
- process.emit('exit');
-
- throw new Error('timeout after '+ms+' ms');
- }, ms);
-};
-
-assert.callbacks = function(callbacks) {
- process.on('exit', function() {
- for (var k in callbacks) {
- assert.equal(0, callbacks[k], (timeout || '')+k+' count off by '+callbacks[k]);
- }
- });
-};
-
-assert.properties = function(obj, properties) {
- properties.forEach(function(property) {
- assert.ok(property in obj, 'has property: '+property);
- });
-
- for (var property in obj) {
- if (!obj.hasOwnProperty(property)) {
- continue;
- }
-
- if (typeof obj[property] == 'function') {
- continue;
- }
-
- assert.ok(
- properties.indexOf(property) > -1,
- 'does not have property: '+property
- );
- }
-};
View
36 test/fixture/multipart.js
@@ -1,6 +1,6 @@
exports['rfc1867'] =
- { boundary: 'AaB03x'
- , raw:
+ { boundary: 'AaB03x',
+ raw:
'--AaB03x\r\n'+
'content-disposition: form-data; name="field1"\r\n'+
'\r\n'+
@@ -10,25 +10,25 @@ exports['rfc1867'] =
'Content-Type: text/plain\r\n'+
'\r\n'+
'... contents of file1.txt ...\r\r\n'+
- '--AaB03x--\r\n'
- , parts:
- [ { headers:
- { 'content-disposition': 'form-data; name="field1"'
- }
- , data: 'Joe Blow\r\nalmost tricked you!'
- }
- , { headers:
- { 'content-disposition': 'form-data; name="pics"; filename="file1.txt"'
- , 'Content-Type': 'text/plain'
- }
- , data: '... contents of file1.txt ...\r'
+ '--AaB03x--\r\n',
+ parts:
+ [ { headers: {
+ 'content-disposition': 'form-data; name="field1"',
+ },
+ data: 'Joe Blow\r\nalmost tricked you!',
+ },
+ { headers: {
+ 'content-disposition': 'form-data; name="pics"; filename="file1.txt"',
+ 'Content-Type': 'text/plain',
+ },
+ data: '... contents of file1.txt ...\r',
}
]
};
exports['emptyHeader'] =
- { boundary: 'AaB03x'
- , raw:
+ { boundary: 'AaB03x',
+ raw:
'--AaB03x\r\n'+
'content-disposition: form-data; name="field1"\r\n'+
': foo\r\n'+
@@ -39,6 +39,6 @@ exports['emptyHeader'] =
'Content-Type: text/plain\r\n'+
'\r\n'+
'... contents of file1.txt ...\r\r\n'+
- '--AaB03x--\r\n'
- , expectError: true
+ '--AaB03x--\r\n',
+ expectError: true,
};
View
32 test/integration/test-multipart-parser.js
@@ -1,23 +1,23 @@
require('../common');
-var CHUNK_LENGTH = 10
- , multipartParser = require('formidable/multipart_parser')
- , MultipartParser = multipartParser.MultipartParser
- , parser = new MultipartParser()
- , fixtures = require('../fixture/multipart')
- , Buffer = require('buffer').Buffer;
+var CHUNK_LENGTH = 10,
+ multipartParser = require('formidable/multipart_parser'),
+ MultipartParser = multipartParser.MultipartParser,
+ parser = new MultipartParser(),
+ fixtures = require('../fixture/multipart'),
+ Buffer = require('buffer').Buffer;
Object.keys(fixtures).forEach(function(name) {
- var fixture = fixtures[name]
- , buffer = new Buffer(Buffer.byteLength(fixture.raw, 'binary'))
- , offset = 0
- , chunk
- , nparsed
+ var fixture = fixtures[name],
+ buffer = new Buffer(Buffer.byteLength(fixture.raw, 'binary')),
+ offset = 0,
+ chunk,
+ nparsed,
- , parts = []
- , part = null
- , headerField
- , headerValue
- , endCalled = '';
+ parts = [],
+ part = null,
+ headerField,
+ headerValue,
+ endCalled = '';
parser.initWithBoundary(fixture.boundary);
parser.onPartBegin = function() {
View
73 test/simple/test-incoming-form.js
@@ -1,18 +1,18 @@
require('../common');
-var MultipartParserStub = GENTLY.stub('./multipart_parser', 'MultipartParser')
- , QuerystringParserStub = GENTLY.stub('./querystring_parser', 'QuerystringParser')
- , EventEmitterStub = GENTLY.stub('events', 'EventEmitter')
- , FileStub = GENTLY.stub('./file');
-
-var formidable = require('formidable')
- , IncomingForm = formidable.IncomingForm
- , events = require('events')
- , fs = require('fs')
- , path = require('path')
- , Buffer = require('buffer').Buffer
- , fixtures = require('../fixture/multipart')
- , form
- , gently;
+var MultipartParserStub = GENTLY.stub('./multipart_parser', 'MultipartParser'),
+ QuerystringParserStub = GENTLY.stub('./querystring_parser', 'QuerystringParser'),
+ EventEmitterStub = GENTLY.stub('events', 'EventEmitter'),
+ FileStub = GENTLY.stub('./file');
+
+var formidable = require('formidable'),
+ IncomingForm = formidable.IncomingForm,
+ events = require('events'),
+ fs = require('fs'),
+ path = require('path'),
+ Buffer = require('buffer').Buffer,
+ fixtures = require('../fixture/multipart'),
+ form,
+ gently;
function test(test) {
gently = new Gently();
@@ -130,7 +130,7 @@ test(function parse() {
assert.strictEqual(form.resume(), false);
})();
-
+
(function testEmitError() {
var ERR = new Error('something bad happened');
gently.expect(form, '_error',function(err) {
@@ -138,7 +138,7 @@ test(function parse() {
});
emit.error(ERR);
})();
-
+
(function testEmitData() {
var BUFFER = [1, 2, 3];
gently.expect(form, 'write', function(buffer) {
@@ -173,54 +173,53 @@ test(function parse() {
emit.end();
})();
})();
-
(function testWithCallback() {
gently.expect(EventEmitterStub, 'call');
- var form = new IncomingForm()
- , REQ = {headers: {}}
- , parseCalled = 0;
-
+ var form = new IncomingForm(),
+ REQ = {headers: {}},
+ parseCalled = 0;
+
gently.expect(form, 'writeHeaders');
gently.expect(REQ, 'on', 3, function() {
return this;
});
-
+
gently.expect(form, 'on', 4, function(event, fn) {
if (event == 'field') {
fn('field1', 'foo');
fn('field1', 'bar');
fn('field2', 'nice');
}
-
+
if (event == 'file') {
fn('file1', '1');
fn('file1', '2');
fn('file2', '3');
}
-
+
if (event == 'end') {
fn();
}
return this;
});
-
+
form.parse(REQ, gently.expect(function parseCbOk(err, fields, files) {
assert.deepEqual(fields, {field1: 'bar', field2: 'nice'});
assert.deepEqual(files, {file1: '2', file2: '3'});
}));
-
+
gently.expect(form, 'writeHeaders');
gently.expect(REQ, 'on', 3, function() {
return this;
});
-
+
var ERR = new Error('test');
gently.expect(form, 'on', 3, function(event, fn) {
if (event == 'field') {
fn('foo', 'bar');
}
-
+
if (event == 'error') {
fn(ERR);
gently.expect(form, 'on');
@@ -254,8 +253,8 @@ test(function writeHeaders() {
});
test(function write() {
- var parser = {}
- , BUFFER = [1, 2, 3];
+ var parser = {},
+ BUFFER = [1, 2, 3];
form._parser = parser;
form.bytesExpected = 523423;
@@ -369,8 +368,8 @@ test(function parseContentLength() {
});
test(function _initMultipart() {
- var BOUNDARY = '123'
- , PARSER;
+ var BOUNDARY = '123',
+ PARSER;
gently.expect(MultipartParserStub, 'new', function() {
PARSER = this;
@@ -581,9 +580,9 @@ test(function handlePart() {
})();
(function testFilePart() {
- var PART = new events.EventEmitter()
- , FILE = new events.EventEmitter()
- , PATH = '/foo/bar';
+ var PART = new events.EventEmitter(),
+ FILE = new events.EventEmitter(),
+ PATH = '/foo/bar';
PART.name = 'my_file';
PART.filename = 'sweet.txt';
@@ -658,8 +657,8 @@ test(function _uploadPath() {
(function testFileExtension() {
form.keepExtensions = true;
- var FILENAME = 'foo.jpg'
- , EXT = '.bar';
+ var FILENAME = 'foo.jpg',
+ EXT = '.bar';
gently.expect(GENTLY.hijacked.path, 'extname', function(filename) {
assert.equal(filename, FILENAME);
View
16 test/simple/test-multipart-parser.js
@@ -1,9 +1,9 @@
require('../common');
-var multipartParser = require('formidable/multipart_parser')
- , MultipartParser = multipartParser.MultipartParser
- , events = require('events')
- , Buffer = require('buffer').Buffer
- , parser;
+var multipartParser = require('formidable/multipart_parser'),
+ MultipartParser = multipartParser.MultipartParser,
+ events = require('events'),
+ Buffer = require('buffer').Buffer,
+ parser;
function test(test) {
parser = new MultipartParser();
@@ -30,8 +30,8 @@ test(function initWithBoundary() {
});
test(function parserError() {
- var boundary = 'abc'
- , buffer = new Buffer(5);
+ var boundary = 'abc',
+ buffer = new Buffer(5);
parser.initWithBoundary(boundary);
buffer.write('--ad', 'ascii', 0);
@@ -47,4 +47,4 @@ test(function end() {
parser.state = multipartParser.END;
assert.strictEqual(parser.end(), undefined);
})();
-});
+});
View
10 test/simple/test-querystring-parser.js
@@ -1,8 +1,8 @@
require('../common');
-var QuerystringParser = require('formidable/querystring_parser').QuerystringParser
- , Buffer = require('buffer').Buffer
- , gently
- , parser;
+var QuerystringParser = require('formidable/querystring_parser').QuerystringParser,
+ Buffer = require('buffer').Buffer,
+ gently,
+ parser;
function test(test) {
gently = new Gently();
@@ -42,4 +42,4 @@ test(function end() {
parser.buffer = 'my buffer';
parser.end();
assert.equal(parser.buffer, '');
-});
+});
View
34 test/system/test-multi-video-upload.js
@@ -1,15 +1,15 @@
require('../common');
-var BOUNDARY = '---------------------------10102754414578508781458777923'
- , FIXTURE = TEST_FIXTURES+'/multi_video.upload'
- , fs = require('fs')
- , util = require('formidable/util')
- , http = require('http')
- , formidable = require('formidable')
- , server = http.createServer();
+var BOUNDARY = '---------------------------10102754414578508781458777923',
+ FIXTURE = TEST_FIXTURES+'/multi_video.upload',
+ fs = require('fs'),
+ util = require('formidable/util'),
+ http = require('http'),
+ formidable = require('formidable'),
+ server = http.createServer();
server.on('request', function(req, res) {
- var form = new formidable.IncomingForm()
- , uploads = {};
+ var form = new formidable.IncomingForm(),
+ uploads = {};
form.uploadDir = TEST_TMP;
form.parse(req);
@@ -53,14 +53,14 @@ server.on('request', function(req, res) {
});
server.listen(TEST_PORT, function() {
- var client = http.createClient(TEST_PORT)
- , stat = fs.statSync(FIXTURE)
- , headers =
- { 'content-type': 'multipart/form-data; boundary='+BOUNDARY
- , 'content-length': stat.size
- }
- , request = client.request('POST', '/', headers)
- , fixture = new fs.ReadStream(FIXTURE);
+ var client = http.createClient(TEST_PORT),
+ stat = fs.statSync(FIXTURE),
+ headers = {
+ 'content-type': 'multipart/form-data; boundary='+BOUNDARY,
+ 'content-length': stat.size,
+ }
+ request = client.request('POST', '/', headers),
+ fixture = new fs.ReadStream(FIXTURE);
fixture
.on('data', function(b) {
Please sign in to comment.
Something went wrong with that request. Please try again.