sendfile() — express Function Reference
Architecture documentation for the sendfile() function in response.js from the express codebase.
Entity Profile
Dependency Diagram
graph TD 7cf11697_b32b_3362_0b5d_beb3602edbdc["sendfile()"] e8de3182_7771_c885_d297_ca4255bae3a6["response.js"] 7cf11697_b32b_3362_0b5d_beb3602edbdc -->|defined in| e8de3182_7771_c885_d297_ca4255bae3a6 654363af_a1b9_0807_17be_896895e23cd5["res()"] 654363af_a1b9_0807_17be_896895e23cd5 -->|calls| 7cf11697_b32b_3362_0b5d_beb3602edbdc style 7cf11697_b32b_3362_0b5d_beb3602edbdc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
lib/response.js lines 921–1009
function sendfile(res, file, options, callback) {
var done = false;
var streaming;
// request aborted
function onaborted() {
if (done) return;
done = true;
var err = new Error('Request aborted');
err.code = 'ECONNABORTED';
callback(err);
}
// directory
function ondirectory() {
if (done) return;
done = true;
var err = new Error('EISDIR, read');
err.code = 'EISDIR';
callback(err);
}
// errors
function onerror(err) {
if (done) return;
done = true;
callback(err);
}
// ended
function onend() {
if (done) return;
done = true;
callback();
}
// file
function onfile() {
streaming = false;
}
// finished
function onfinish(err) {
if (err && err.code === 'ECONNRESET') return onaborted();
if (err) return onerror(err);
if (done) return;
setImmediate(function () {
if (streaming !== false && !done) {
onaborted();
return;
}
if (done) return;
done = true;
callback();
});
}
// streaming
function onstream() {
streaming = true;
}
file.on('directory', ondirectory);
file.on('end', onend);
file.on('error', onerror);
file.on('file', onfile);
file.on('stream', onstream);
onFinished(res, onfinish);
if (options.headers) {
// set headers on successful transfer
file.on('headers', function headers(res) {
var obj = options.headers;
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does sendfile() do?
sendfile() is a function in the express codebase, defined in lib/response.js.
Where is sendfile() defined?
sendfile() is defined in lib/response.js at line 921.
What calls sendfile()?
sendfile() is called by 1 function(s): res.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free