Skip to content
This repository
  • 8 commits
  • 8 files changed
  • 0 comments
  • 2 contributors
Dec 19, 2010
Tim Koschuetzki 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
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
Source Rendered
@@ -18,9 +18,41 @@ a big variety of clients and is considered production-ready.
18 18
 * Graceful error handling
19 19
 * Very high test coverage
20 20
 
21  
-### Todo
22  
-
23  
-* Implement QuerystringParser the same way as MultipartParser
  21
+## Changelog
  22
+
  23
+### v0.9.11
  24
+
  25
+* Emit `'progress'` event when receiving data, regardless of parsing it. (Tim Koschützki)
  26
+* Use [W3C FileAPI Draft](http://dev.w3.org/2006/webapi/FileAPI/) properties for File class
  27
+
  28
+**Important:** The old property names of the File class will be removed in a
  29
+future release.
  30
+
  31
+[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.10...v0.9.11)
  32
+
  33
+### Older releases
  34
+
  35
+These releases were done before starting to maintain the above Changelog:
  36
+
  37
+* [v0.9.10](https://github.com/felixge/node-formidable/compare/v0.9.9...v0.9.10)
  38
+* [v0.9.9](https://github.com/felixge/node-formidable/compare/v0.9.8...v0.9.9)
  39
+* [v0.9.8](https://github.com/felixge/node-formidable/compare/v0.9.7...v0.9.8)
  40
+* [v0.9.7](https://github.com/felixge/node-formidable/compare/v0.9.6...v0.9.7)
  41
+* [v0.9.6](https://github.com/felixge/node-formidable/compare/v0.9.5...v0.9.6)
  42
+* [v0.9.5](https://github.com/felixge/node-formidable/compare/v0.9.4...v0.9.5)
  43
+* [v0.9.4](https://github.com/felixge/node-formidable/compare/v0.9.3...v0.9.4)
  44
+* [v0.9.3](https://github.com/felixge/node-formidable/compare/v0.9.2...v0.9.3)
  45
+* [v0.9.2](https://github.com/felixge/node-formidable/compare/v0.9.1...v0.9.2)
  46
+* [v0.9.1](https://github.com/felixge/node-formidable/compare/v0.9.0...v0.9.1)
  47
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  48
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  49
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  50
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  51
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  52
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  53
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  54
+* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
  55
+* [v0.1.0](https://github.com/felixge/node-formidable/commits/v0.1.0)
24 56
 
25 57
 ## Installation
26 58
 
@@ -163,7 +195,7 @@ Emitted when the entire request has been received, and all contained files have
163 195
 
164 196
 ### formdiable.File
165 197
 
166  
-#### file.length = 0
  198
+#### file.size = 0
167 199
 
168 200
 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.
169 201
 
@@ -172,14 +204,19 @@ The size of the uploade file in bytes. If the file is still being uploaded (see
172 204
 The path this file is being written to. You can modify this in the `'fileBegin'` event in
173 205
 case you are unhappy with the way formidable generates a temporary path for your files.
174 206
 
175  
-#### file.filename = null
  207
+#### file.name = null
176 208
 
177 209
 The name this file had according to the uploading client.
178 210
 
179  
-#### file.mime = null
  211
+#### file.type = null
180 212
 
181 213
 The mime type of this file, according to the uploading client.
182 214
 
  215
+#### file.lastModifiedDate = null
  216
+
  217
+A date object (or `null`) containing the time this file was last written to. Mostly
  218
+here for compatiblity with the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/).
  219
+
183 220
 ## License
184 221
 
185 222
 Formidable is licensed under the MIT license.
3  TODO
... ...
@@ -0,0 +1,3 @@
  1
+- Better bufferMaxSize handling approach
  2
+- Add tests for JSON parser pull request and merge it
  3
+- Implement QuerystringParser the same way as MultipartParser
28  lib/formidable/file.js
@@ -7,20 +7,37 @@ var util = require('./util'),
7 7
 function File(properties) {
8 8
   EventEmitter.call(this);
9 9
 
10  
-  this.length = 0;
  10
+  this.size = 0;
11 11
   this.path = null;
12  
-  this.filename = null;
13  
-  this.mime = null;
  12
+  this.name = null;
  13
+  this.type = null;
  14
+  this.lastModifiedDate = null;
14 15
 
15 16
   this._writeStream = null;
16 17
 
17 18
   for (var key in properties) {
18 19
     this[key] = properties[key];
19 20
   }
  21
+
  22
+  this._backwardsCompatibility();
20 23
 }
21 24
 module.exports = File;
22 25
 util.inherits(File, EventEmitter);
23 26
 
  27
+// @todo Next release: Show error messages when accessing these
  28
+File.prototype._backwardsCompatibility = function() {
  29
+  var self = this;
  30
+  this.__defineGetter__('length', function() {
  31
+    return self.size;
  32
+  });
  33
+  this.__defineGetter__('filename', function() {
  34
+    return self.name;
  35
+  });
  36
+  this.__defineGetter__('mime', function() {
  37
+    return self.type;
  38
+  });
  39
+};
  40
+
24 41
 File.prototype.open = function() {
25 42
   this._writeStream = new WriteStream(this.path);
26 43
 };
@@ -28,8 +45,9 @@ File.prototype.open = function() {
28 45
 File.prototype.write = function(buffer, cb) {
29 46
   var self = this;
30 47
   this._writeStream.write(buffer, function() {
31  
-    self.length += buffer.length;
32  
-    self.emit('progress', self.length);
  48
+    self.lastModifiedDate = new Date();
  49
+    self.size += buffer.length;
  50
+    self.emit('progress', self.size);
33 51
     cb();
34 52
   });
35 53
 };
10  lib/formidable/incoming_form.js
@@ -115,14 +115,14 @@ IncomingForm.prototype.write = function(buffer) {
115 115
     return;
116 116
   }
117 117
 
  118
+  this.bytesReceived += buffer.length;
  119
+  this.emit('progress', this.bytesReceived, this.bytesExpected);
  120
+
118 121
   var bytesParsed = this._parser.write(buffer);
119 122
   if (bytesParsed !== buffer.length) {
120 123
     this._error(new Error('parser error, '+bytesParsed+' of '+buffer.length+' bytes parsed'));
121 124
   }
122 125
 
123  
-  this.bytesReceived += bytesParsed;
124  
-  this.emit('progress', this.bytesReceived, this.bytesExpected);
125  
-
126 126
   return bytesParsed;
127 127
 };
128 128
 
@@ -167,8 +167,8 @@ IncomingForm.prototype.handlePart = function(part) {
167 167
 
168 168
   var file = new File({
169 169
     path: this._uploadPath(part.filename),
170  
-    filename: part.filename,
171  
-    mime: part.mime,
  170
+    name: part.filename,
  171
+    type: part.mime,
172 172
   });
173 173
 
174 174
   this.emit('fileBegin', part.name, file);
2  package.json
... ...
@@ -1,5 +1,5 @@
1 1
 { "name" : "formidable",
2  
-  "version": "0.9.10",
  2
+  "version": "0.9.11",
3 3
   "dependencies": {"gently": ">=0.7.0"},
4 4
   "directories" : { "lib" : "./lib/formidable" },
5 5
   "main" : "./lib/formidable/index"
7  test/common.js
@@ -20,3 +20,10 @@ global.assert = require('assert');
20 20
 global.TEST_PORT = 13532;
21 21
 global.TEST_FIXTURES = path.join(__dirname, 'fixture');
22 22
 global.TEST_TMP = path.join(__dirname, 'tmp');
  23
+
  24
+// Stupid new feature in node that complains about gently attaching too many
  25
+// listeners to process 'exit'. This is a workaround until I can think of a
  26
+// better way to deal with this.
  27
+if (process.setMaxListeners) {
  28
+  process.setMaxListeners(10000);
  29
+}
16  test/simple/test-file.js
@@ -15,10 +15,11 @@ function test(test) {
15 15
 
16 16
 test(function constructor() {
17 17
   assert.ok(file instanceof EventEmitter);
18  
-  assert.strictEqual(file.length, 0);
  18
+  assert.strictEqual(file.size, 0);
19 19
   assert.strictEqual(file.path, null);
20  
-  assert.strictEqual(file.filename, null);
21  
-  assert.strictEqual(file.mime, null);
  20
+  assert.strictEqual(file.name, null);
  21
+  assert.strictEqual(file.type, null);
  22
+  assert.strictEqual(file.lastModifiedDate, null);
22 23
 
23 24
   assert.strictEqual(file._writeStream, null);
24 25
 
@@ -54,23 +55,24 @@ test(function write() {
54 55
     assert.strictEqual(buffer, BUFFER);
55 56
 
56 57
     gently.expect(file, 'emit', function (event, bytesWritten) {
  58
+      assert.ok(file.lastModifiedDate instanceof Date);
57 59
       assert.equal(event, 'progress');
58  
-      assert.equal(bytesWritten, file.length);
  60
+      assert.equal(bytesWritten, file.size);
59 61
     });
60 62
 
61 63
     CB_STUB = gently.expect(function writeCb() {
62  
-      assert.equal(file.length, 10);
  64
+      assert.equal(file.size, 10);
63 65
     });
64 66
 
65 67
     cb();
66 68
 
67 69
     gently.expect(file, 'emit', function (event, bytesWritten) {
68 70
       assert.equal(event, 'progress');
69  
-      assert.equal(bytesWritten, file.length);
  71
+      assert.equal(bytesWritten, file.size);
70 72
     });
71 73
 
72 74
     CB_STUB = gently.expect(function writeCb() {
73  
-      assert.equal(file.length, 20);
  75
+      assert.equal(file.size, 20);
74 76
     });
75 77
 
76 78
     cb();
20  test/simple/test-incoming-form.js
@@ -260,22 +260,24 @@ test(function write() {
260 260
   form.bytesExpected = 523423;
261 261
 
262 262
   (function testBasic() {
263  
-    gently.expect(parser, 'write', function(buffer) {
264  
-      assert.strictEqual(buffer, BUFFER);
265  
-      return buffer.length;
266  
-    });
267  
-
268 263
     gently.expect(form, 'emit', function(event, bytesReceived, bytesExpected) {
269 264
       assert.equal(event, 'progress');
270 265
       assert.equal(bytesReceived, BUFFER.length);
271 266
       assert.equal(bytesExpected, form.bytesExpected);
272 267
     });
273 268
 
  269
+    gently.expect(parser, 'write', function(buffer) {
  270
+      assert.strictEqual(buffer, BUFFER);
  271
+      return buffer.length;
  272
+    });
  273
+
274 274
     assert.equal(form.write(BUFFER), BUFFER.length);
275 275
     assert.equal(form.bytesReceived, BUFFER.length);
276 276
   })();
277 277
 
278 278
   (function testParserError() {
  279
+    gently.expect(form, 'emit');
  280
+
279 281
     gently.expect(parser, 'write', function(buffer) {
280 282
       assert.strictEqual(buffer, BUFFER);
281 283
       return buffer.length - 1;
@@ -285,10 +287,8 @@ test(function write() {
285 287
       assert.ok(err.message.match(/parser error/i));
286 288
     });
287 289
 
288  
-    gently.expect(form, 'emit');
289  
-
290 290
     assert.equal(form.write(BUFFER), BUFFER.length - 1);
291  
-    assert.equal(form.bytesReceived, BUFFER.length + BUFFER.length - 1);
  291
+    assert.equal(form.bytesReceived, BUFFER.length + BUFFER.length);
292 292
   })();
293 293
 
294 294
   (function testUninitialized() {
@@ -595,8 +595,8 @@ test(function handlePart() {
595 595
 
596 596
     gently.expect(FileStub, 'new', function(properties) {
597 597
       assert.equal(properties.path, PATH);
598  
-      assert.equal(properties.filename, PART.filename);
599  
-      assert.equal(properties.mime, PART.mime);
  598
+      assert.equal(properties.name, PART.filename);
  599
+      assert.equal(properties.type, PART.mime);
600 600
       FILE = this;
601 601
 
602 602
       gently.expect(form, 'emit', function (event, field, file) {

No commit comments for this range

Something went wrong with that request. Please try again.