UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

25 lines 807 B
(function (undefined) { Ioc.define('backend.fileHelper', [], function (provide) { provide({ isFile: function (url) { 'use strict'; return (url || '').match(/\.([0-9a-z]+)(?:[\?#]|$)/i); }, downloadStream: function (fileName, res, attachment) { FS.stat(fileName, function (err, stat) { if (err) { res.status(404).send(); return; } res.writeHead(200, { 'Content-Type': MIME.lookup(fileName), 'Content-Length': stat.size, 'Content-disposition': attachment === true ? 'attachment; filename=' + PATH.basename(fileName) : undefined }); var readStream = FS.createReadStream(fileName); readStream.pipe(res); }); } }); }); }());