|
@ -67,40 +67,40 @@ proto.init = function(options) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
proto.write = function(chunk) { |
|
|
proto.write = function(chunk) { |
|
|
this.bytesReceived = this.bytesReceived + chunk.length; |
|
|
this.bytesReceived = this.bytesReceived + chunk.length; |
|
|
this.buffer = this.buffer + chunk; |
|
|
this.buffer = this.buffer + chunk; |
|
|
|
|
|
|
|
|
while (this.buffer.length) { |
|
|
while (this.buffer.length) { |
|
|
var offset = this.buffer.indexOf(this.boundary); |
|
|
var offset = this.buffer.indexOf(this.boundary); |
|
|
|
|
|
|
|
|
if (offset === 0) { |
|
|
if (offset === 0) { |
|
|
this.buffer = this.buffer.substr(offset + this.boundary.length + 2); |
|
|
this.buffer = this.buffer.substr(offset + this.boundary.length + 2); |
|
|
} else if (offset == -1) { |
|
|
} else if (offset == -1) { |
|
|
if (this.buffer === "\r\n") { |
|
|
if (this.buffer === "\r\n") { |
|
|
this.buffer = ''; |
|
|
this.buffer = ''; |
|
|
} else { |
|
|
} else { |
|
|
this.part = (this.part || new Part(this)); |
|
|
this.part = (this.part || new Part(this)); |
|
|
this.part.write(this.buffer); |
|
|
this.part.write(this.buffer); |
|
|
this.buffer = []; |
|
|
this.buffer = []; |
|
|
} |
|
|
} |
|
|
} else if (offset > 0) { |
|
|
} else if (offset > 0) { |
|
|
this.part = (this.part || new Part(this)); |
|
|
this.part = (this.part || new Part(this)); |
|
|
this.part.write(this.buffer.substr(0, offset - 2)); |
|
|
this.part.write(this.buffer.substr(0, offset - 2)); |
|
|
|
|
|
|
|
|
this.part.emit('complete'); |
|
|
this.part.emit('complete'); |
|
|
|
|
|
|
|
|
this.part = new Part(this); |
|
|
this.part = new Part(this); |
|
|
this.buffer = this.buffer.substr(offset + this.boundary.length + 2); |
|
|
this.buffer = this.buffer.substr(offset + this.boundary.length + 2); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
function Part(stream) { |
|
|
function Part(stream) { |
|
|
node.EventEmitter.call(this); |
|
|
node.EventEmitter.call(this); |
|
|
|
|
|
|
|
|
this.headers = {}; |
|
|
this.headers = {}; |
|
|
this.buffer = ''; |
|
|
this.buffer = ''; |
|
|
this.bytesReceived = 0; |
|
|
this.bytesReceived = 0; |
|
|
|
|
|
|
|
|
// Avoids turning Part into a circular JSON object
|
|
|
// Avoids turning Part into a circular JSON object
|
|
|
this.getStream = function() { |
|
|
this.getStream = function() { |
|
|