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

Method constructor

lib/internal/webstreams/encoding.js:133–151  ·  view source on GitHub ↗

* @param {string} [encoding] * @param {{ * fatal? : boolean, * ignoreBOM? : boolean, * }} [options]

(encoding = 'utf-8', options = kEmptyObject)

Source from the content-addressed store, hash-verified

131 * }} [options]
132 */
133 constructor(encoding = 'utf-8', options = kEmptyObject) {
134 this.#handle = new TextDecoder(encoding, options);
135 this.#transform = new TransformStream({
136 transform: (chunk, controller) => {
137 if (chunk === undefined) {
138 throw new ERR_INVALID_ARG_TYPE('chunk', 'string', chunk);
139 }
140 const value = this.#handle.decode(chunk, { stream: true });
141 if (value)
142 controller.enqueue(value);
143 },
144 flush: (controller) => {
145 const value = this.#handle.decode();
146 if (value)
147 controller.enqueue(value);
148 controller.terminate();
149 },
150 });
151 }
152
153 /**
154 * @readonly

Callers

nothing calls this directly

Calls 3

decodeMethod · 0.65
enqueueMethod · 0.45
terminateMethod · 0.45

Tested by

no test coverage detected