diff --git a/expressStream.js b/expressStream.js index 36e8ee5..c7aaa43 100644 --- a/expressStream.js +++ b/expressStream.js @@ -1,25 +1,17 @@ var fs = require('fs'); -exports.write = function(path, encoding){ - return function(req, res, next){ - var headerFile = fs.readFileSync(path, encoding); - res.write(headerFile); - next(); - } -} - var streamBefore = []; var streamAfter = []; -exports.setStreamBefore = function(before){ - streamBefore = before; +exports.streamBefore = function(before){ + streamBefore = (typeof before === 'object' && before.length) ? before : []; } -exports.setStreamAfter = function(after){ - streamAfter = after; +exports.streamAfter = function(after){ + streamAfter = (typeof after === 'object' && after.length) ? after : []; } -exports.stream = function(){ +exports.stream = function(middlewareViews){ return function (req, res, next){ res.set = function(){} @@ -50,6 +42,17 @@ exports.stream = function(){ res.stream(streamBefore[i]); } + if(middlewareViews){ + if(typeof middlewareViews === 'object'){ + for(var i = 0; i < middlewareViews.length; i++){ + res.stream(middlewareViews[i]); + } + } + else if(typeof middlewareViews === 'string'){ + res.stream(middlewareViews); + } + } + next(); } } diff --git a/package.json b/package.json index 33f9f6f..e63d655 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-stream", - "version": "0.1.0", + "version": "0.2.0", "description": "Response streaming middleware for Express 4.", "main": "./expressStream.js", "scripts": {