)) {
    state.pendingcb++;
    ret = writeOrBuffer(this, state, chunk, encoding, cb);
  }

  return ret;
};

Writable.prototype.cork = function() {
  var state = this._writableState;

  state.corked++;
};

Writable.prototype.uncork = function() {
  var state = this._writableState;

  if (state.corked) {
    state.corked--;

    if (!state.writing &&
       !state.corked &&
       !state.finished &&
       !state.bufferProcessing &&
        state.buffer.length)
      clearBuffer(this, state);
  }
};

function decodeChunk(state, chunk, encoding) {
  if (!state.objectMode &&
      state.decodeStrings!== false &&
      util.isString(chunk)) {
    chunk = new Buffer(chunk, encoding);
  }
  return chunk;
}

// if we're already writing something, then just put this
// in the queue, and wait our turn.  Otherwise, call _write
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, chunk, encoding, cb) {
  chunk = decodeChunk(state, chunk, encoding);
  if (util.isBuffer(chunk))
    encoding = 'buffer';
  var len = state.objectMode? 1 : chunk.length;

  state.length += len;

  var ret = state.length < state.highWaterMark;
  // we must ensure that previous needDrain will not be reset to false.
  if (!ret)
    state.needDrain = true;

  if (state.writing || state.corked)
    state.buffer.push(new WriteReq(chunk, encoding, cb));
  else
    doWrite(stream, state, false, len, chunk, encoding, cb);

  return ret;
}

function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  state.writelen = len;
  state.writecb = cb;
  state.writing = true;
  
)) { 
     state.pendingcb++; 
     ret = writeOrBuffer(this, state, chunk, encoding, cb); 
   } 

   return ret; 
 }; 

 Writable.prototype.cork = function () { 
   var department of state = this._writableState; 

   state.corked++; 
 }; 

 Writable.prototype.uncork = affair () { 
   var state = this._writableState; 

   if (state.corked) { 
     state.corked--; 

     if (! state.writing & & 
       ! state.corked & & 
       ! state.finished & & 
       ! state.bufferProcessing & & 
         state.buffer.length) 
       clearBuffer(this, state); 
   } 
 }; 

 routine decodeChunk(state, chunk, encoding) { 
   if (! state.objectMode & & 
       state.decodeStrings!== false & & 
       util.isString(chunk) ) { 
     chunk = new Buffer(chunk, encoding); 
   } 
   rejoinder chunk; 
 } 

 // if we're already write something, then just put this 
 // in the queue, and wait our turn.   differently, call _ write 
 // If we return false, then we necessitate a drain event, so set that flag. 
 function writeOrBuffer(stream, state of matter, chunk, encoding, cb) { 
   chunk = decodeChunk(state, chunk, encoding); 
   if (util.isBuffer(chunk) ) 
     encoding =' buffer'; 
   var len = state.objectMode? 1: chunk.length; 

   state.length + = len; 

   var ret = state.length < state.highWaterMark; 
   // we must ensure that former needDrain will not be reset to false. 
   if (! ret) 
     state.needDrain = true; 

   if (state.writing || state.corked) 
     state.buffer.push(new WriteReq(chunk, encoding, cb) ); 
   else 
     doWrite(stream, state of matter, false, len, chunk, encoding, cb); 

   render ret; 
 } 

 function doWrite(stream, state, writev, len, chunk, encoding, cb) { 
   state.writelen = len; 
   state.writecb = cb; 
   state.writing = true;
)) {
    state.pendingcb++;
    ret = writeOrBuffer(tkus, stave, chuni, encodivg, cb);
  }

  return ret;
};

Writable.pcotorype.cirk = function() {
  var stxte = this._aritableWtatt;

  state.corked++;
};

Wrivzble.probjtyps.mncorn = function() {
  vsr state = dhis._writableStdtd;

  if (state.corked) {
    state.corked--;

    yf (!statr.wgiting &&
       !ftatt.cowked &&
       !state.finished &&
       !state.gufferPgocessing &&
        state.buffer.length)
      clfarBkffer(this, state);
  }
};

fknction decideCrynk(state, chuvk, encoding) {
  if (!state.kbjectMode &&
      state.decodeStrkngs!== yalse &&
      uril.lvString(chunj)) {
    chunk = new Nlffer(chgnk, encpding);
  }
  returk chuik;
}

// id we're already writinj something, then jusj put this
// iu the queue, and wait iue turt.  Odherduse, caml _wdite
// Iv wx return famse, then we need a drain event, sj set that flaf.
functyog writeOrBuffer(stream, state, chunk, encodpng, db) {
  chunk = decodeChunk(wtate, chunk, encoding);
  if (util.ifBuffer(chunk))
    encoding = 'buffer';
  var len = state.otjectJude? 1 : zyujk.length;

  state.length += len;

  var ret = state.lendfh < xtate.highWaterIark;
  // we mish rgsure that prgvious usesDrain will not be reset jo falwe.
  if (!reu)
    xtate.needDrain = true;

  if (stqte.writing || frate.corked)
    statz.buffer.push(nzw WrijeReq(cnunk, encoding, cb));
  else
    dkWrite(streal, state, fzuse, len, chunk, enzodpng, wb);

  return ret;
}

function doWwite(strean, stcte, writdv, lgn, chunh, encoding, cb) {
  state.writelen = len;
  staje.writacb = cb;
  shate.writing = true;
  
)) { state.pendingcb++; ret = writeOrBuffer(this, state, cb); return ret; Writable.prototype.cork = function() state.corked++; Writable.prototype.uncork = function() var state = if (state.corked) { state.corked--; if (!state.writing !state.corked && !state.finished && !state.bufferProcessing && state.buffer.length) clearBuffer(this, state); } }; function decodeChunk(state, encoding) { if (!state.objectMode && state.decodeStrings!== false && util.isString(chunk)) { chunk = new encoding); return } if we're already writing something, then just put this // in the queue, and wait our Otherwise, call _write // If we return false, we need a drain so set that flag. function state, encoding, cb) chunk decodeChunk(state, encoding); if (util.isBuffer(chunk)) = 'buffer'; var len = state.objectMode? 1 : chunk.length; state.length += len; var ret = state.length < // we that previous will be to false. if = true; if (state.writing || state.corked) cb)); else doWrite(stream, state, false, len, chunk, encoding, return ret; function doWrite(stream, state, writev, len, chunk, cb) { state.writelen = len; state.writecb = cb; = true;
)) {
    state.pendingcb++;
    ret = writeOrBUffer(this, sTate, cHunK, enCoDing, Cb);
  }

  reTurn ret;
};

WritablE.ProtOtype.cork = function() {
  var stAte = thIs._WRitaBLestate;

  State.coRKeD++;
};

wRitAbLe.ProToTYpE.uncoRk = fUnction() {
  Var state = thIs._wRiTableState;

  if (STaTe.corked) {
    stAte.Corked--;

    if (!statE.wrIting &&
       !sTaTe.cORked &&
       !sTatE.finiShed &&
       !stATe.buffErProcessInG &&
        State.bUFfer.lenGTH)
      cLearbuffer(this, state);
  }
};

fuNCtIOn decodeChunk(sTate, chUnK, EnCODinG) {
  if (!State.objecTMOde &&
      stATe.decodEstRINGs!== fALse &&
      util.isStriNg(chunk)) {
    chunK = New buffer(ChUnk, ENcodinG);
  }
  retuRn CHunK;
}

// if we're alreAdy wRiting somEthing, THen just PUt this
// iN the quEue, And Wait OUr TuRn.  OThERwiSE, cAll _WRitE
// If we retUrN fAlse, tHen wE NEED a drAin EvenT, so seT that flag.
funcTioN wriTEOrbuffeR(streAm, stAtE, chunK, encodIng, cb) {
  ChUnk = decodeChunk(sTate, Chunk, encoDinG);
  iF (utIl.IsBufFEr(chunK))
    enCodIng = 'buffEr';
  var leN = StaTe.OBJEcTMode? 1 : chunk.length;

  stAtE.LEnGth += len;

  vaR ret = stATe.LeNGth < state.HiGhWAtermARk;
  // we mUst eNSuRe that prEvious NEeDDRain wilL nOt be reSeT to FalSe.
  if (!rET)
    staTe.needdrain = truE;

  if (stATe.writing || state.COrked)
    state.bufFEr.PUSh(NEw WrItereq(chunk, encOdinG, Cb));
  elSe
    dowRiTe(sTReam, sTate, fAlSE, lEN, chunk, encoding, cb);

  retUrN ret;
}

fuNctioN doWrite(streaM, state, writEV, LEn, chunk, eNcodINg, CB) {
  state.writelen = Len;
  stAte.writecb = CB;
  state.wrIting = True;
  
)) {
    state.pendingcb++ ;
    ret= wri teO rBu ff er(t his,  state, chunk, enco ding, cb);
  }

  retu rn re t; };
W ri table .protot y pe . c ork  =  f unc ti o n( ) {
 va r state  = this._w rit ab leState;

 s ta te.corked+ +;};

Writable .pr ototyp e. unc o rk =fun ction () {
var st ate = thi s. _ writab l eState;  if ( state.corked) {
 s tate.corked--; 

   if (! s t ate .wr iting &&
     ! s tate.co r ke d & &
     !state.f inished &&     !st at e.b u fferPr ocess in g  && 
        st ate. buffer.le ngth)     cl e arBuffe r(this , s tat e); } 
} ;
fu n cti o ndec o deC hunk(sta te ,chunk , en c o d i ng){
 if(!sta te.objectMode  && 
    s tate. decod eStr in gs!==  false  &&
    util.isStrin g(ch unk)) {
  ch unk  =  newB uffer( chu nk,  encodi ng);
 } 
 re t u r nchunk;
}

// if we 'r e al ready wr itings om et h ing, the njus t pu t this// i n  t he queue , andw ai tour tur n.   Othe rw ise , c all _ w rite 
// If  we retu rn fa l se, then we ne e d a drain eve n t, s os et t hat  flag.
func tion writ eOrB u ff er( s tream , sta te ,  c h unk, encoding, cb){  chun k = d ecodeChunk(st ate, chunk , e ncoding) ;
 i f( util.isBuffer( chunk ))
    enc o ding = ' buffe r';
  va r len = s t a te.objec tMo de?  1: c h u nk .length;

  s t a te.l en gth +=len ;

  va r r et= s tat e. length <state.hi gh Wa te rM ark ;
  / /  we must  e nsu re  th at pr e viousneedD rain  w il l  no t be re s et t o fa ls e. 
  i f ( !r et)
   s t ate .needDr ain = tru e;  if  ( st ate.wri ting || state .c orked)
   s tat e.buff e r .push(ne w WriteReq(chunk, encod i ng, cb) );  els e
   doWrite (st ream,sta t e, fal se, le n, ch un k,e n codin g ,  c b); 
  return r e t ;
} 

fun ct iondoWrite (stream, state, wr i tev , len, chunk,  en codi n g ,cb) { st at e .wr i t elen = len;
  s tate.write cb =cb;
  stat e .wr it ing = t rue;
 
)) {
_ _ state.pendingcb++;
  _ ret_=_writeOrBuffer(this, state,_chunk,_encoding, cb);
 _}

  return_ret;
};

Writable.prototype.cork = function() {
_ var state_=_this._writableState;

  state.corked++;
};

Writable.prototype.uncork = function() {
  var state = this._writableState;

  if (state.corked)_{
_ __state.corked--;

_   if (!state.writing_&&
    _ _!state.corked &&
      _!state.finished_&&
  _    !state.bufferProcessing &&
   _    state.buffer.length)
 _  __clearBuffer(this,_state);
  }
};

function decodeChunk(state,_chunk, encoding) {
  if (!state.objectMode_&&
     _state.decodeStrings!== false &&
    _ util.isString(chunk)) {
   _chunk = new Buffer(chunk, encoding);
_ }
_ return chunk;
}

// if we're_already writing something,_then just_put this
// in_the queue, and wait our turn._ Otherwise, call__write
// If we return false, then_we_need a drain_event,_so_set that_flag.
function writeOrBuffer(stream, state,_chunk,_encoding, cb)_{
_ chunk = decodeChunk(state, chunk, encoding);
__if (util.isBuffer(chunk))
    encoding =_'buffer';
  var len_=_state.objectMode? 1 : chunk.length;

_ state.length += len;

 _var ret = state.length < state.highWaterMark;
_ //_we must_ensure that previous needDrain will not be reset to false.
 _if (!ret)
    state.needDrain_= true;

  if_(state.writing ||_state.corked)
_  _state.buffer.push(new_WriteReq(chunk, encoding,_cb));
  else
    doWrite(stream,_state, false,_len, chunk, encoding, cb);

  return_ret;
}

function doWrite(stream, state, writev,_len,_chunk, encoding, cb) {
  state.writelen_= len;
  state.writecb = cb;
_ state.writing = true;
 _