Permalink
Browse files

emit 'size' for streamed encoding where length is required

  • Loading branch information...
1 parent 42f6958 commit ae5217dfe4f5f14b3d1b28b84920f179ce256d4c @coolaj86 committed Jan 13, 2011
Showing with 14 additions and 1 deletion.
  1. +2 −0 examples/form-data-test.js
  2. +12 −1 lib/form-data.js
@@ -11,6 +11,8 @@
formData.setNodeChunkedEncoding(chunked);
+ // TODO auto-unfold arrays onto `key[]`
+ // TODO auto-unfold objects onto `key[subkey]`
formData.append('items[]', 'value0');
formData.append('items[]', 'value1');
formData.append('item', 'value2');
View
@@ -133,7 +133,18 @@
});
emitter.on('ready', function () {
- emitter.emit('load', Buffer.concat(buffers));
+ var data = Buffer.concat(buffers);
+ // TODO
+ // determine the size as quickly as possible
+ // so that the data can still be streamed, even
+ // if the content-length must be known
+ //
+ // This will only take a significant amount of time
+ // if one of the `File`s is stream-backed. Waiting
+ // for the stream's `end` will hold-up the content-length
+ // calculation.
+ emitter.emit('size', data.length);
+ emitter.emit('load', data);
emitter.emit('end');
});

0 comments on commit ae5217d

Please sign in to comment.