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

Function doSendFileFD

lib/internal/http2/core.js:2799–2866  ·  view source on GitHub ↗
(session, options, fd, headers, streamOptions, err, stat)

Source from the content-addressed store, hash-verified

2797}
2798
2799function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) {
2800 const onError = options.onError;
2801
2802 if (err) {
2803 tryClose(fd);
2804 if (onError)
2805 onError(err);
2806 else
2807 this.destroy(err);
2808 return;
2809 }
2810
2811 if (!stat.isFile()) {
2812 const isDirectory = stat.isDirectory();
2813 if (options.offset !== undefined || options.offset > 0 ||
2814 options.length !== undefined || options.length >= 0 ||
2815 isDirectory) {
2816 const err = isDirectory ?
2817 new ERR_HTTP2_SEND_FILE() : new ERR_HTTP2_SEND_FILE_NOSEEK();
2818 tryClose(fd);
2819 if (onError)
2820 onError(err);
2821 else
2822 this.destroy(err);
2823 return;
2824 }
2825
2826 options.offset = -1;
2827 options.length = -1;
2828 }
2829
2830 if (this.destroyed || this.closed) {
2831 tryClose(fd);
2832 this.destroy(new ERR_HTTP2_INVALID_STREAM());
2833 return;
2834 }
2835
2836 const statOptions = {
2837 offset: options.offset !== undefined ? options.offset : 0,
2838 length: options.length !== undefined ? options.length : -1,
2839 };
2840
2841 // options.statCheck is a user-provided function that can be used to
2842 // verify stat values, override or set headers, or even cancel the
2843 // response operation. If statCheck explicitly returns false, the
2844 // response is canceled. The user code may also send a separate type
2845 // of response so check again for the HEADERS_SENT flag
2846 if ((typeof options.statCheck === 'function' &&
2847 options.statCheck.call(this, stat, headers) === false) ||
2848 (this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) {
2849 tryClose(fd);
2850 return;
2851 }
2852
2853 if (stat.isFile()) {
2854 statOptions.length =
2855 statOptions.length < 0 ? stat.size - (+statOptions.offset) :
2856 MathMin(stat.size - (+statOptions.offset),

Callers

nothing calls this directly

Calls 7

tryCloseFunction · 0.85
processRespondWithFDFunction · 0.85
onErrorFunction · 0.50
destroyMethod · 0.45
isFileMethod · 0.45
isDirectoryMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…