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

Function processCallback

lib/zlib.js:504–601  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

502}
503
504function processCallback() {
505 // This callback's context (`this`) is the `_handle` (ZCtx) object. It is
506 // important to null out the values once they are no longer needed since
507 // `_handle` can stay in memory long after the buffer is needed.
508 const handle = this;
509 const self = this[owner_symbol];
510 const state = self._writeState;
511
512 if (self.destroyed) {
513 this.buffer = null;
514 this.cb();
515 return;
516 }
517
518 const availOutAfter = state[0];
519 const availInAfter = state[1];
520
521 const inDelta = handle.availInBefore - availInAfter;
522 self.bytesWritten += inDelta;
523
524 const have = handle.availOutBefore - availOutAfter;
525 let streamBufferIsFull = false;
526 if (have > 0) {
527 const out = self._outBuffer.slice(self._outOffset, self._outOffset + have);
528 self._outOffset += have;
529 streamBufferIsFull = !self.push(out);
530 } else {
531 assert(have === 0, 'have should not go down');
532 }
533
534 if (self.destroyed) {
535 this.cb();
536 return;
537 }
538
539 // Exhausted the output buffer, or used all the input create a new one.
540 if (availOutAfter === 0 || self._outOffset >= self._chunkSize) {
541 handle.availOutBefore = self._chunkSize;
542 self._outOffset = 0;
543 self._outBuffer = Buffer.allocUnsafe(self._chunkSize);
544 }
545
546 if (availOutAfter === 0) {
547 // Not actually done. Need to reprocess.
548 // Also, update the availInBefore to the availInAfter value,
549 // so that if we have to hit it a third (fourth, etc.) time,
550 // it'll have the correct byte counts.
551 handle.inOff += inDelta;
552 handle.availInBefore = availInAfter;
553
554
555 if (!streamBufferIsFull) {
556 this.write(handle.flushFlag,
557 this.buffer, // in
558 handle.inOff, // in_off
559 handle.availInBefore, // in_len
560 self._outBuffer, // out
561 self._outOffset, // out_off

Callers

nothing calls this directly

Calls 6

assertFunction · 0.70
sliceMethod · 0.65
pushMethod · 0.45
writeMethod · 0.45
_readMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…