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

Method dump

deps/undici/undici.js:17249–17287  ·  view source on GitHub ↗

* Dumps the response body by reading `limit` number of bytes. * @param {object} opts * @param {number} [opts.limit = 131072] Number of bytes to read. * @param {AbortSignal} [opts.signal] An AbortSignal to cancel the dump. * @returns {Promise }

(opts)

Source from the content-addressed store, hash-verified

17247 * @returns {Promise<null>}
17248 */
17249 dump(opts) {
17250 const signal = opts?.signal;
17251 if (signal != null && (typeof signal !== "object" || !("aborted" in signal))) {
17252 return Promise.reject(new InvalidArgumentError("signal must be an AbortSignal"));
17253 }
17254 const limit = opts?.limit && Number.isFinite(opts.limit) ? opts.limit : 128 * 1024;
17255 if (signal?.aborted) {
17256 return Promise.reject(signal.reason ?? new AbortError());
17257 }
17258 if (this._readableState.closeEmitted) {
17259 return Promise.resolve(null);
17260 }
17261 return new Promise((resolve, reject) => {
17262 if (this[kContentLength] && this[kContentLength] > limit || this[kBytesRead] > limit) {
17263 this.destroy(new AbortError());
17264 }
17265 if (signal) {
17266 const onAbort = /* @__PURE__ */ __name(() => {
17267 this.destroy(signal.reason ?? new AbortError());
17268 }, "onAbort");
17269 const abortListener = addAbortListener(signal, onAbort);
17270 this.on("close", function() {
17271 abortListener[Symbol.dispose]();
17272 if (signal.aborted) {
17273 reject(signal.reason ?? new AbortError());
17274 } else {
17275 resolve(null);
17276 }
17277 });
17278 } else {
17279 this.on("close", resolve);
17280 }
17281 this.on("error", noop).on("data", () => {
17282 if (this[kBytesRead] > limit) {
17283 this.destroy();
17284 }
17285 }).resume();
17286 });
17287 }
17288 /**
17289 * @param {BufferEncoding} encoding
17290 * @returns {this}

Callers 2

mainFunction · 0.45
mainFunction · 0.45

Calls 9

__nameFunction · 0.85
rejectMethod · 0.80
addAbortListenerFunction · 0.70
resumeMethod · 0.65
rejectFunction · 0.50
resolveFunction · 0.50
resolveMethod · 0.45
destroyMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected