MCPcopy
hub / github.com/nodejs/undici / BodyReadable

Class BodyReadable

lib/api/readable.js:27–363  ·  view source on GitHub ↗

* @class * @extends {Readable} * @see https://fetch.spec.whatwg.org/#body

Source from the content-addressed store, hash-verified

25 * @see https://fetch.spec.whatwg.org/#body
26 */
27class BodyReadable extends Readable {
28 /**
29 * @param {object} opts
30 * @param {(this: Readable, size: number) => void} opts.resume
31 * @param {() => (void | null)} opts.abort
32 * @param {string} [opts.contentType = '']
33 * @param {number} [opts.contentLength]
34 * @param {number} [opts.highWaterMark = 64 * 1024]
35 */
36 constructor ({
37 resume,
38 abort,
39 contentType = '',
40 contentLength,
41 highWaterMark = 64 * 1024 // Same as nodejs fs streams.
42 }) {
43 super({
44 autoDestroy: true,
45 read: resume,
46 highWaterMark
47 })
48
49 this._readableState.dataEmitted = false
50
51 this[kAbort] = abort
52
53 /** @type {Consume | null} */
54 this[kConsume] = null
55
56 /** @type {number} */
57 this[kBytesRead] = 0
58
59 /** @type {ReadableStream|null} */
60 this[kBody] = null
61
62 /** @type {boolean} */
63 this[kUsed] = false
64
65 /** @type {string} */
66 this[kContentType] = contentType
67
68 /** @type {number|null} */
69 this[kContentLength] = Number.isFinite(contentLength) ? contentLength : null
70
71 /**
72 * Is stream being consumed through Readable API?
73 * This is an optimization so that we avoid checking
74 * for 'data' and 'readable' listeners in the hot path
75 * inside push().
76 *
77 * @type {boolean}
78 */
79 this[kReading] = false
80 }
81
82 /**
83 * @param {Error|null} err
84 * @param {(error:(Error|null)) => void} callback

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…