MCPcopy Index your code
hub / github.com/nodejs/node / writeOrBuffer

Function writeOrBuffer

lib/internal/streams/writable.js:548–585  ·  view source on GitHub ↗
(stream, state, chunk, encoding, callback)

Source from the content-addressed store, hash-verified

546// in the queue, and wait our turn. Otherwise, call _write
547// If we return false, then we need a drain event, so set that flag.
548function writeOrBuffer(stream, state, chunk, encoding, callback) {
549 const len = (state[kState] & kObjectMode) !== 0 ? 1 : chunk.length;
550
551 state.length += len;
552
553 if ((state[kState] & (kWriting | kErrored | kCorked | kConstructed)) !== kConstructed) {
554 if ((state[kState] & kBuffered) === 0) {
555 state[kState] |= kBuffered;
556 state[kBufferedValue] = [];
557 }
558
559 state[kBufferedValue].push({ chunk, encoding, callback });
560 if ((state[kState] & kAllBuffers) !== 0 && encoding !== 'buffer') {
561 state[kState] &= ~kAllBuffers;
562 }
563 if ((state[kState] & kAllNoop) !== 0 && callback !== nop) {
564 state[kState] &= ~kAllNoop;
565 }
566 } else {
567 state.writelen = len;
568 if (callback !== nop) {
569 state.writecb = callback;
570 }
571 state[kState] |= kWriting | kSync | kExpectWriteCb;
572 stream._write(chunk, encoding, state.onwrite);
573 state[kState] &= ~kSync;
574 }
575
576 const ret = state.length < state.highWaterMark || state.length === 0;
577
578 if (!ret) {
579 state[kState] |= kNeedDrain;
580 }
581
582 // Return false if errored or destroyed in order to break
583 // any synchronous while(stream.write(data)) loops.
584 return ret && (state[kState] & (kDestroyed | kErrored)) === 0;
585}
586
587function doWrite(stream, state, writev, len, chunk, encoding, cb) {
588 state.writelen = len;

Callers 1

_writeFunction · 0.85

Calls 2

pushMethod · 0.45
_writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…