MCPcopy Create free account
hub / github.com/thinkjs/thinkjs / download

Function download

lib/extend/context.js:303–319  ·  view source on GitHub ↗

* download * @param {String} filepath * @param {String} filename

(filepath, filename = path.basename(filepath))

Source from the content-addressed store, hash-verified

301 * @param {String} filename
302 */
303 download(filepath, filename = path.basename(filepath)) {
304 assert(filepath, 'filepath can not be empty');
305 const contentType = this.response.get('Content-Type');
306 if (!contentType) {
307 this.type = path.extname(filename);
308 }
309 const contentDisposition = this.response.get('Content-Disposition');
310 if (!contentDisposition) {
311 this.attachment(filename);
312 }
313 const stream = fs.createReadStream(filepath);
314 this.body = stream;
315 onFinished(this.res, () => {
316 destroy(stream);
317 });
318 return false;
319 }
320};

Callers

nothing calls this directly

Calls 1

getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…