MCPcopy Create free account
hub / github.com/nodejs/node / textStream

Function textStream

deps/undici/src/lib/web/fetch/body.js:397–438  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

395 },
396
397 textStream () {
398 const this_ = getInternalState(this)
399
400 // 1. If this is unusable, then throw a TypeError.
401 if (bodyUnusable(this_)) {
402 throw new TypeError('Body is unusable: Body has already been read')
403 }
404
405 // 2. If this’s body is null:
406 if (this_.body == null) {
407 // 2.1. Let emptyStream be a new ReadableStream in this’s relevant realm.
408 // 2.2. Set up emptyStream.
409 /** @type {ReadableStreamDefaultController<any>} */
410 let controller
411 const emptyStream = new ReadableStream({
412 start: (c) => {
413 controller = c
414 },
415 pull: () => Promise.resolve(),
416 cancel: () => Promise.resolve()
417 }, {
418 size: () => 1
419 })
420
421 // 2.3. Close emptyStream.
422 controller.close()
423
424 // 2.4. Return emptyStream.
425 return emptyStream
426 }
427
428 // 3. Let stream be this’s body’s stream.
429 /** @type {ReadableStream} */
430 const stream = this_.body.stream
431
432 // 4. Let decoder be a new TextDecoderStream object in this’s relevant realm.
433 // 5. Set up decoder with UTF-8.
434 const decoder = new TextDecoderStream('UTF-8')
435
436 // 6. Return the result of stream, piped through decoder.
437 return stream.pipeThrough(decoder)
438 }
439 }
440
441 return methods

Callers

nothing calls this directly

Calls 4

pipeThroughMethod · 0.80
bodyUnusableFunction · 0.70
closeMethod · 0.65
resolveMethod · 0.45

Tested by

no test coverage detected