|
@ -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:
|
|
|