|
@ -32,6 +32,12 @@ var Stream = require('stream'); |
|
|
|
|
|
|
|
|
util.inherits(Writable, Stream); |
|
|
util.inherits(Writable, Stream); |
|
|
|
|
|
|
|
|
|
|
|
function WriteReq(chunk, encoding, cb) { |
|
|
|
|
|
this.chunk = chunk; |
|
|
|
|
|
this.encoding = encoding; |
|
|
|
|
|
this.callback = cb; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function WritableState(options, stream) { |
|
|
function WritableState(options, stream) { |
|
|
options = options || {}; |
|
|
options = options || {}; |
|
|
|
|
|
|
|
@ -190,7 +196,7 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) { |
|
|
state.needDrain = !ret; |
|
|
state.needDrain = !ret; |
|
|
|
|
|
|
|
|
if (state.writing) |
|
|
if (state.writing) |
|
|
state.buffer.push([chunk, encoding, cb]); |
|
|
state.buffer.push(new WriteReq(chunk, encoding, cb)); |
|
|
else |
|
|
else |
|
|
doWrite(stream, state, len, chunk, encoding, cb); |
|
|
doWrite(stream, state, len, chunk, encoding, cb); |
|
|
|
|
|
|
|
@ -268,9 +274,9 @@ function clearBuffer(stream, state) { |
|
|
|
|
|
|
|
|
for (var c = 0; c < state.buffer.length; c++) { |
|
|
for (var c = 0; c < state.buffer.length; c++) { |
|
|
var entry = state.buffer[c]; |
|
|
var entry = state.buffer[c]; |
|
|
var chunk = entry[0]; |
|
|
var chunk = entry.chunk; |
|
|
var encoding = entry[1]; |
|
|
var encoding = entry.encoding; |
|
|
var cb = entry[2]; |
|
|
var cb = entry.callback; |
|
|
var len = state.objectMode ? 1 : chunk.length; |
|
|
var len = state.objectMode ? 1 : chunk.length; |
|
|
|
|
|
|
|
|
doWrite(stream, state, len, chunk, encoding, cb); |
|
|
doWrite(stream, state, len, chunk, encoding, cb); |
|
|