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

Method end

lib/internal/streams/iter/push.js:274–300  ·  view source on GitHub ↗

* Signal end of stream. Returns total bytes written. * @returns {number}

()

Source from the content-addressed store, hash-verified

272 * @returns {number}
273 */
274 end() {
275 if (this.#writerState === 'errored') {
276 return -2; // Signal to reject with stored error
277 }
278 if (this.#writerState === 'closing') {
279 return -3; // Signal to PushWriter: wait for drain to complete
280 }
281 if (this.#writerState === 'closed') {
282 return this.#bytesWritten; // Idempotent
283 }
284
285 this.#cleanup();
286 this.#rejectPendingWrites(
287 new ERR_INVALID_STATE.TypeError('Writer closed'));
288 this.#resolvePendingDrains(false);
289
290 // If buffer is empty, close immediately
291 if (this.#slots.length === 0) {
292 this.#writerState = 'closed';
293 this.#resolvePendingReads();
294 return this.#bytesWritten;
295 }
296
297 // Buffer has data: transition to closing, defer completion until drained
298 this.#writerState = 'closing';
299 return -3; // Signal to PushWriter: create deferred end promise
300 }
301
302 /**
303 * Called by the read path when the consumer has drained all data while

Callers 15

onendFunction · 0.45
readable.jsFile · 0.45
onEofChunkFunction · 0.45
onendFunction · 0.45
endWritableNTFunction · 0.45
pumpToNodeFunction · 0.45
pipelineImplFunction · 0.45
endFnFunction · 0.45
compose.jsFile · 0.45
_duplexifyFunction · 0.45
endFunction · 0.45
_finalFunction · 0.45

Calls 4

#cleanupMethod · 0.95
#rejectPendingWritesMethod · 0.95
#resolvePendingDrainsMethod · 0.95
#resolvePendingReadsMethod · 0.95

Tested by

no test coverage detected