Skip to content

Commit

Permalink
fixed #9 - multipart transformations broken
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Sep 20, 2014
1 parent 9482e53 commit 3ed07f0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/transforms/multipart._js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// `var ez = require("ez-streams")`
///
var generic = require('../devices/generic');
var flows = require('streamline/lib/util/flows');

function parseContentType(contentType) {
if (!contentType) throw new Error("content-type missing");
Expand Down Expand Up @@ -34,6 +35,7 @@ module.exports = {

return function(_, reader, writer) {
reader = reader.peekable();
var handshake = flows.handshake();
while (true) {
var buf = reader.read(_, 2048);
if (!buf || !buf.length) return;
Expand All @@ -52,7 +54,10 @@ module.exports = {
var read = function(_) {
var len = Math.max(boundary.length, 256);
var buf = reader.read(_, 32 * len);
if (!buf || !buf.length) return;
if (!buf || !buf.length) {
handshake.notify();
return;
}
// would be nice if Buffer had an indexOf. Would avoid a conversion to string.
// I could use node-buffertools but it introduces a dependency on a binary module.
var s = buf.toString("binary");
Expand All @@ -61,6 +66,7 @@ module.exports = {
var j = s.indexOf('\n', boundary.length);
if (j < 0) throw new Error("newline missing after boundary");
reader.unread(buf.slice(j + 1));
handshake.notify();
return undefined;
} else if (i > 0) {
var j = s.lastIndexOf('\n', i);
Expand All @@ -75,6 +81,7 @@ module.exports = {
var partReader = generic.reader(read);
partReader.headers = headers;
writer.write(_, partReader);
handshake.wait(_);
}
};
},
Expand Down

0 comments on commit 3ed07f0

Please sign in to comment.