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

Function writeBlob

lib/dispatcher/client-h1.js:1517–1541  ·  view source on GitHub ↗

* @param {AbortCallback} abort * @param {Blob} body * @param {import('./client.js')} client * @param {import('../core/request.js')} request * @param {import('net').Socket} socket * @param {number} contentLength * @param {string} header * @param {boolean} expectsPayload * @returns {Promise<vo

(abort, body, client, request, socket, contentLength, header, expectsPayload)

Source from the content-addressed store, hash-verified

1515 * @returns {Promise<void>}
1516 */
1517async function writeBlob (abort, body, client, request, socket, contentLength, header, expectsPayload) {
1518 try {
1519 if (contentLength != null && contentLength !== body.size) {
1520 throw new RequestContentLengthMismatchError()
1521 }
1522
1523 const buffer = Buffer.from(await body.arrayBuffer())
1524
1525 socket.cork()
1526 socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
1527 socket.write(buffer)
1528 socket.uncork()
1529
1530 request.onBodySent(buffer)
1531 request.onRequestSent()
1532
1533 if (!expectsPayload && request.reset !== false) {
1534 socket[kReset] = true
1535 }
1536
1537 client[kResume]()
1538 } catch (err) {
1539 abort(err)
1540 }
1541}
1542
1543/**
1544 * @param {AbortCallback} abort

Callers 1

writeH1Function · 0.70

Calls 7

corkMethod · 0.80
uncorkMethod · 0.80
abortFunction · 0.70
arrayBufferMethod · 0.65
onBodySentMethod · 0.65
onRequestSentMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…