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

Method dump

lib/api/readable.js:267–321  ·  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

265 * @returns {Promise<null>}
266 */
267 dump (opts) {
268 const signal = opts?.signal
269
270 if (signal != null && (typeof signal !== 'object' || !('aborted' in signal))) {
271 return Promise.reject(new InvalidArgumentError('signal must be an AbortSignal'))
272 }
273
274 const limit = opts?.limit && Number.isFinite(opts.limit)
275 ? opts.limit
276 : 128 * 1024
277
278 if (signal?.aborted) {
279 return Promise.reject(signal.reason ?? new AbortError())
280 }
281
282 if (this._readableState.closeEmitted) {
283 return Promise.resolve(null)
284 }
285
286 return new Promise((resolve, reject) => {
287 if (
288 (this[kContentLength] && (this[kContentLength] > limit)) ||
289 this[kBytesRead] > limit
290 ) {
291 this.destroy(new AbortError())
292 }
293
294 if (signal) {
295 const onAbort = () => {
296 this.destroy(signal.reason ?? new AbortError())
297 }
298 const abortListener = addAbortListener(signal, onAbort)
299 this
300 .on('close', function () {
301 abortListener[Symbol.dispose]()
302 if (signal.aborted) {
303 reject(signal.reason ?? new AbortError())
304 } else {
305 resolve(null)
306 }
307 })
308 } else {
309 this.on('close', resolve)
310 }
311
312 this
313 .on('error', noop)
314 .on('data', () => {
315 if (this[kBytesRead] > limit) {
316 this.destroy()
317 }
318 })
319 .resume()
320 })
321 }
322
323 /**
324 * @param {BufferEncoding} encoding

Callers 15

stream-compat.jsFile · 0.80
issue-4880.jsFile · 0.80
http2-body.jsFile · 0.80
http2-goaway.jsFile · 0.80
headers-crlf.jsFile · 0.80
client-request.jsFile · 0.80
request.jsFile · 0.80
readable.test-d.tsFile · 0.80

Calls 6

onMethod · 0.95
addAbortListenerFunction · 0.85
rejectFunction · 0.85
resolveFunction · 0.85
resumeMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected