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

Function processSyncInput

lib/internal/streams/iter/transform.js:557–615  ·  view source on GitHub ↗
(input, flushFlag)

Source from the content-addressed store, hash-verified

555 let pendingBytes = 0;
556
557 function processSyncInput(input, flushFlag) {
558 let inOff = 0;
559 let availIn = TypedArrayPrototypeGetByteLength(input);
560 let availOutBefore = chunkSize - outOffset;
561
562 handle.writeSync(flushFlag,
563 input, inOff, availIn,
564 outBuf, outOffset, availOutBefore);
565 if (error) throw error;
566
567 while (true) {
568 const availOut = writeState[0];
569 const availInAfter = writeState[1];
570 const have = availOutBefore - availOut;
571 const bufferExhausted = availOut === 0 ||
572 outOffset + have >= chunkSize;
573
574 if (have > 0) {
575 if (bufferExhausted && outOffset === 0) {
576 // Entire buffer filled - yield directly, no copy.
577 ArrayPrototypePush(pending, outBuf);
578 } else if (bufferExhausted) {
579 // Tail filled, buffer being replaced - subarray is safe.
580 ArrayPrototypePush(pending,
581 outBuf.subarray(outOffset, outOffset + have));
582 } else {
583 // Partial fill, buffer reused - must copy.
584 ArrayPrototypePush(pending,
585 TypedArrayPrototypeSlice(outBuf,
586 outOffset,
587 outOffset + have));
588 }
589 pendingBytes += have;
590 outOffset += have;
591 }
592
593 if (bufferExhausted) {
594 outBuf = Buffer.allocUnsafe(chunkSize);
595 outOffset = 0;
596 }
597
598 if (availOut === 0) {
599 // Engine has more output - loop.
600 const consumed = availIn - availInAfter;
601 inOff += consumed;
602 availIn = availInAfter;
603 availOutBefore = chunkSize - outOffset;
604
605 handle.writeSync(flushFlag,
606 input, inOff, availIn,
607 outBuf, outOffset, availOutBefore);
608 if (error) throw error;
609 continue;
610 }
611
612 // All input consumed.
613 break;
614 }

Callers 1

makeZlibTransformSyncFunction · 0.85

Calls 1

writeSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…