Browse Source

multipart no longer depends on Promise

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
5fbc750db7
  1. 21
      doc/api.txt
  2. 14
      lib/multipart.js

21
doc/api.txt

@ -1254,18 +1254,21 @@ Node. To use it, +require("multipart")+.
+ +
See the Stream class below. See the Stream class below.
+multipart.cat(message)+ :: +multipart.cat(message, callback)+ ::
Returns a promise. On success, +callback+ is called with +(null, stream)+ where +stream+ is a
- on success: Returns a multipart.Stream object representing the completed +multipart.Stream+ object representing the completed message. The body of
message. The body of each part is saved on the `body` member. each part is saved on the `body` member.
- on error: Returns an instanceof Error object. This indicates
that the message was malformed in some way.
+ +
*Note*: This function saves the *entire* message into memory. As such, On error, +callback+ is called with +(err)+ where +err+ is an instanceof
it is ill-suited to parsing actual incoming messages from an HTTP request! the +Error+ object. This indicates that the message was malformed in some
way.
+
*Note*: This function saves the *entire* message into memory. As such, it
is ill-suited to parsing actual incoming messages from an HTTP request!
If a user uploads a very large file, then it may cause serious problems. If a user uploads a very large file, then it may cause serious problems.
No checking is done to ensure that the file does not overload the memory. No checking is done to ensure that the file does not overload the memory.
Only use multipart.cat with known and trusted input! Only use +multipart.cat+ with known and trusted input!
=== +multipart.Stream+ === +multipart.Stream+

14
lib/multipart.js

@ -37,9 +37,8 @@ function parse (message) {
// rack up as much memory usage as they can manage. This function // rack up as much memory usage as they can manage. This function
// buffers the whole message, which is very convenient, but also // buffers the whole message, which is very convenient, but also
// very much the wrong thing to do in most cases. // very much the wrong thing to do in most cases.
function cat (message) { function cat (message, callback) {
var p = new (events.Promise), var stream = parse(message);
stream = parse(message);
stream.files = {}; stream.files = {};
stream.fields = {}; stream.fields = {};
stream.addListener("partBegin", function (part) { stream.addListener("partBegin", function (part) {
@ -49,9 +48,12 @@ function cat (message) {
stream.addListener("body", function (chunk) { stream.addListener("body", function (chunk) {
stream.part.body = (stream.part.body || "") + chunk; stream.part.body = (stream.part.body || "") + chunk;
}); });
stream.addListener("error", function (e) { p.emitError(e) }); stream.addListener("error", function (e) { p.emitError(e)
stream.addListener("complete", function () { p.emitSuccess(stream) }); if (callback) callback(e);
return p; });
stream.addListener("complete", function () {
if (callback) callback(null, stream);
});
}; };
// events: // events:

Loading…
Cancel
Save