Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: felixge/node-formidable
base: v0.9.10
...
head fork: felixge/node-formidable
compare: v0.9.11
  • 8 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 19, 2010
Tim Koschuetzki tim-kos Emit 'progress' event before parsing data
The 'progress' event is meant to indicate upload progress, not parsing
progress. This patch puts things into the right order.
f22993a
Commits on Jan 18, 2011
Felix Geisendörfer Workaround stupid new node feature
This is only needed for the test suite.
62dc04b
Felix Geisendörfer Use HTML5 FileAPI properties for File class
This does not break backwards compatiblity yet, but future
versions will remove the old property alias.

See: https://github.com/felixge/node-formidable/issues#issue/32
29716c1
Felix Geisendörfer Implement lastModifiedDate
Completes the basic HTML5 API compatibility from a property point of
view.
8507002
Felix Geisendörfer Add changelog to readme
Not documenting the old releases for now

Also moved Todo into own file
2a93def
Felix Geisendörfer Compact older releases 85b6d13
Felix Geisendörfer Update docs 129b51e
Felix Geisendörfer Bump version 63347d8
49 Readme.md
View
@@ -18,9 +18,41 @@ a big variety of clients and is considered production-ready.
* Graceful error handling
* Very high test coverage
-### Todo
-
-* Implement QuerystringParser the same way as MultipartParser
+## Changelog
+
+### v0.9.11
+
+* Emit `'progress'` event when receiving data, regardless of parsing it. (Tim Koschützki)
+* Use [W3C FileAPI Draft](http://dev.w3.org/2006/webapi/FileAPI/) properties for File class
+
+**Important:** The old property names of the File class will be removed in a
+future release.
+
+[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.10...v0.9.11)
+
+### Older releases
+
+These releases were done before starting to maintain the above Changelog:
+
+* [v0.9.10](https://github.com/felixge/node-formidable/compare/v0.9.9...v0.9.10)
+* [v0.9.9](https://github.com/felixge/node-formidable/compare/v0.9.8...v0.9.9)
+* [v0.9.8](https://github.com/felixge/node-formidable/compare/v0.9.7...v0.9.8)
+* [v0.9.7](https://github.com/felixge/node-formidable/compare/v0.9.6...v0.9.7)
+* [v0.9.6](https://github.com/felixge/node-formidable/compare/v0.9.5...v0.9.6)
+* [v0.9.5](https://github.com/felixge/node-formidable/compare/v0.9.4...v0.9.5)
+* [v0.9.4](https://github.com/felixge/node-formidable/compare/v0.9.3...v0.9.4)
+* [v0.9.3](https://github.com/felixge/node-formidable/compare/v0.9.2...v0.9.3)
+* [v0.9.2](https://github.com/felixge/node-formidable/compare/v0.9.1...v0.9.2)
+* [v0.9.1](https://github.com/felixge/node-formidable/compare/v0.9.0...v0.9.1)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
+* [v0.1.0](https://github.com/felixge/node-formidable/commits/v0.1.0)
## Installation
@@ -163,7 +195,7 @@ Emitted when the entire request has been received, and all contained files have
### formdiable.File
-#### file.length = 0
+#### file.size = 0
The size of the uploade file in bytes. If the file is still being uploaded (see `'fileBegin'` event), this property says how many bytes of the file have been written to disk yet.
@@ -172,14 +204,19 @@ The size of the uploade file in bytes. If the file is still being uploaded (see
The path this file is being written to. You can modify this in the `'fileBegin'` event in
case you are unhappy with the way formidable generates a temporary path for your files.
-#### file.filename = null
+#### file.name = null
The name this file had according to the uploading client.
-#### file.mime = null
+#### file.type = null
The mime type of this file, according to the uploading client.
+#### file.lastModifiedDate = null
+
+A date object (or `null`) containing the time this file was last written to. Mostly
+here for compatiblity with the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/).
+
## License
Formidable is licensed under the MIT license.
3  TODO
View
@@ -0,0 +1,3 @@
+- Better bufferMaxSize handling approach
+- Add tests for JSON parser pull request and merge it
+- Implement QuerystringParser the same way as MultipartParser
28 lib/formidable/file.js
View
@@ -7,20 +7,37 @@ var util = require('./util'),
function File(properties) {
EventEmitter.call(this);
- this.length = 0;
+ this.size = 0;
this.path = null;
- this.filename = null;
- this.mime = null;
+ this.name = null;
+ this.type = null;
+ this.lastModifiedDate = null;
this._writeStream = null;
for (var key in properties) {
this[key] = properties[key];
}
+
+ this._backwardsCompatibility();
}
module.exports = File;
util.inherits(File, EventEmitter);
+// @todo Next release: Show error messages when accessing these
+File.prototype._backwardsCompatibility = function() {
+ var self = this;
+ this.__defineGetter__('length', function() {
+ return self.size;
+ });
+ this.__defineGetter__('filename', function() {
+ return self.name;
+ });
+ this.__defineGetter__('mime', function() {
+ return self.type;
+ });
+};
+
File.prototype.open = function() {
this._writeStream = new WriteStream(this.path);
};
@@ -28,8 +45,9 @@ File.prototype.open = function() {
File.prototype.write = function(buffer, cb) {
var self = this;
this._writeStream.write(buffer, function() {
- self.length += buffer.length;
- self.emit('progress', self.length);
+ self.lastModifiedDate = new Date();
+ self.size += buffer.length;
+ self.emit('progress', self.size);
cb();
});
};
10 lib/formidable/incoming_form.js
View
@@ -115,14 +115,14 @@ IncomingForm.prototype.write = function(buffer) {
return;
}
+ this.bytesReceived += buffer.length;
+ this.emit('progress', this.bytesReceived, this.bytesExpected);
+
var bytesParsed = this._parser.write(buffer);
if (bytesParsed !== buffer.length) {
this._error(new Error('parser error, '+bytesParsed+' of '+buffer.length+' bytes parsed'));
}
- this.bytesReceived += bytesParsed;
- this.emit('progress', this.bytesReceived, this.bytesExpected);
-
return bytesParsed;
};
@@ -167,8 +167,8 @@ IncomingForm.prototype.handlePart = function(part) {
var file = new File({
path: this._uploadPath(part.filename),
- filename: part.filename,
- mime: part.mime,
+ name: part.filename,
+ type: part.mime,
});
this.emit('fileBegin', part.name, file);
2  package.json
View
@@ -1,5 +1,5 @@
{ "name" : "formidable",
- "version": "0.9.10",
+ "version": "0.9.11",
"dependencies": {"gently": ">=0.7.0"},
"directories" : { "lib" : "./lib/formidable" },
"main" : "./lib/formidable/index"
7 test/common.js
View
@@ -20,3 +20,10 @@ global.assert = require('assert');
global.TEST_PORT = 13532;
global.TEST_FIXTURES = path.join(__dirname, 'fixture');
global.TEST_TMP = path.join(__dirname, 'tmp');
+
+// Stupid new feature in node that complains about gently attaching too many
+// listeners to process 'exit'. This is a workaround until I can think of a
+// better way to deal with this.
+if (process.setMaxListeners) {
+ process.setMaxListeners(10000);
+}
16 test/simple/test-file.js
View
@@ -15,10 +15,11 @@ function test(test) {
test(function constructor() {
assert.ok(file instanceof EventEmitter);
- assert.strictEqual(file.length, 0);
+ assert.strictEqual(file.size, 0);
assert.strictEqual(file.path, null);
- assert.strictEqual(file.filename, null);
- assert.strictEqual(file.mime, null);
+ assert.strictEqual(file.name, null);
+ assert.strictEqual(file.type, null);
+ assert.strictEqual(file.lastModifiedDate, null);
assert.strictEqual(file._writeStream, null);
@@ -54,23 +55,24 @@ test(function write() {
assert.strictEqual(buffer, BUFFER);
gently.expect(file, 'emit', function (event, bytesWritten) {
+ assert.ok(file.lastModifiedDate instanceof Date);
assert.equal(event, 'progress');
- assert.equal(bytesWritten, file.length);
+ assert.equal(bytesWritten, file.size);
});
CB_STUB = gently.expect(function writeCb() {
- assert.equal(file.length, 10);
+ assert.equal(file.size, 10);
});
cb();
gently.expect(file, 'emit', function (event, bytesWritten) {
assert.equal(event, 'progress');
- assert.equal(bytesWritten, file.length);
+ assert.equal(bytesWritten, file.size);
});
CB_STUB = gently.expect(function writeCb() {
- assert.equal(file.length, 20);
+ assert.equal(file.size, 20);
});
cb();
20 test/simple/test-incoming-form.js
View
@@ -260,22 +260,24 @@ test(function write() {
form.bytesExpected = 523423;
(function testBasic() {
- gently.expect(parser, 'write', function(buffer) {
- assert.strictEqual(buffer, BUFFER);
- return buffer.length;
- });
-
gently.expect(form, 'emit', function(event, bytesReceived, bytesExpected) {
assert.equal(event, 'progress');
assert.equal(bytesReceived, BUFFER.length);
assert.equal(bytesExpected, form.bytesExpected);
});
+ gently.expect(parser, 'write', function(buffer) {
+ assert.strictEqual(buffer, BUFFER);
+ return buffer.length;
+ });
+
assert.equal(form.write(BUFFER), BUFFER.length);
assert.equal(form.bytesReceived, BUFFER.length);
})();
(function testParserError() {
+ gently.expect(form, 'emit');
+
gently.expect(parser, 'write', function(buffer) {
assert.strictEqual(buffer, BUFFER);
return buffer.length - 1;
@@ -285,10 +287,8 @@ test(function write() {
assert.ok(err.message.match(/parser error/i));
});
- gently.expect(form, 'emit');
-
assert.equal(form.write(BUFFER), BUFFER.length - 1);
- assert.equal(form.bytesReceived, BUFFER.length + BUFFER.length - 1);
+ assert.equal(form.bytesReceived, BUFFER.length + BUFFER.length);
})();
(function testUninitialized() {
@@ -595,8 +595,8 @@ test(function handlePart() {
gently.expect(FileStub, 'new', function(properties) {
assert.equal(properties.path, PATH);
- assert.equal(properties.filename, PART.filename);
- assert.equal(properties.mime, PART.mime);
+ assert.equal(properties.name, PART.filename);
+ assert.equal(properties.type, PART.mime);
FILE = this;
gently.expect(form, 'emit', function (event, field, file) {

No commit comments for this range

Something went wrong with that request. Please try again.