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

Function bodyLength

deps/undici/src/lib/core/util.js:332–347  ·  view source on GitHub ↗

* @param {Blob|Buffer|import ('stream').Stream} body * @returns {number|null}

(body)

Source from the content-addressed store, hash-verified

330 * @returns {number|null}
331 */
332function bodyLength (body) {
333 if (body == null) {
334 return 0
335 } else if (isStream(body)) {
336 const state = body._readableState
337 return state && state.objectMode === false && state.ended === true && Number.isFinite(state.length)
338 ? state.length
339 : null
340 } else if (isBlobLike(body)) {
341 return body.size != null ? body.size : null
342 } else if (isBuffer(body)) {
343 return body.byteLength
344 }
345
346 return null
347}
348
349/**
350 * @param {import ('stream').Stream} body

Callers 1

wrapRequestBodyFunction · 0.70

Calls 3

isStreamFunction · 0.70
isBlobLikeFunction · 0.70
isBufferFunction · 0.70

Tested by

no test coverage detected