Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ Decoder.prototype._write = function (chunk, encoding, cb) {
}

Decoder.prototype._writeOffset = function (chunk, offset, cb) {
while (offset < chunk.length) {
debug('decoding chunk', util.inspect(chunk.slice(offset).toString()))
if (this._inBody) {
offset = this._writeBody(chunk, offset, cb)
if (offset === 0) return // chunk not consumed - _writeOffset will be called again when ready
} else {
offset = this._writeHead(chunk, offset)
try {
while (offset < chunk.length) {
debug('decoding chunk', util.inspect(chunk.slice(offset).toString()))
if (this._inBody) {
offset = this._writeBody(chunk, offset, cb)
if (offset === 0) return // chunk not consumed - _writeOffset will be called again when ready
} else {
offset = this._writeHead(chunk, offset)
}
}
cb()
} catch (err) {
cb(err);
}
cb()
}

Decoder.prototype._writeHead = function (chunk, offset) {
Expand Down