From 47b0c503a45acdf39c81a7671b89e43753288940 Mon Sep 17 00:00:00 2001 From: Joseph Lokahi Podwys Date: Thu, 30 Jul 2015 10:42:11 -0600 Subject: [PATCH 1/4] Proposing some new features. --- expressStream.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/expressStream.js b/expressStream.js index 36e8ee5..27d3d28 100644 --- a/expressStream.js +++ b/expressStream.js @@ -10,6 +10,7 @@ exports.write = function(path, encoding){ var streamBefore = []; var streamAfter = []; +var closeHeadOpenBody = false; exports.setStreamBefore = function(before){ streamBefore = before; @@ -19,7 +20,11 @@ exports.setStreamAfter = function(after){ streamAfter = after; } -exports.stream = function(){ +exports.setCloseHeadOpenBody = function(val){ + closeHeadOpenBody = val; +} + +exports.stream = function(middlewareViews){ return function (req, res, next){ res.set = function(){} @@ -50,6 +55,21 @@ 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); + } + } + + if(closeHeadOpenBody){ + res.write(''); + } + next(); } } From c645e1a4955a57f6f023597d869715fed1c7f2b5 Mon Sep 17 00:00:00 2001 From: Joseph Lokahi Podwys Date: Thu, 30 Jul 2015 11:39:00 -0600 Subject: [PATCH 2/4] Adding additional possible features. --- expressStream.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/expressStream.js b/expressStream.js index 27d3d28..3672336 100644 --- a/expressStream.js +++ b/expressStream.js @@ -1,29 +1,31 @@ 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 = []; +var openDocument = false; var closeHeadOpenBody = false; +var closeDocument = false; -exports.setStreamBefore = function(before){ +exports.streamBefore = function(before){ streamBefore = before; } -exports.setStreamAfter = function(after){ +exports.streamAfter = function(after){ streamAfter = after; } -exports.setCloseHeadOpenBody = function(val){ +exports.openDocument = function(val){ + openDocument = val; +} + +exports.closeHeadOpenBody = function(val){ closeHeadOpenBody = val; } +exports.closeDocument = function(val){ + closeDocument = val; +} + exports.stream = function(middlewareViews){ return function (req, res, next){ @@ -47,10 +49,17 @@ exports.stream = function(middlewareViews){ for(var i = 0; i < streamAfter.length; i++){ res.stream(streamAfter[i]); } + if(closeDocument){ + res.write(''); + } this._end(); } } + if(openDocument){ + res.write(''); + } + for(var i = 0; i < streamBefore.length; i++){ res.stream(streamBefore[i]); } From aabe19834da45272f8f2070e702b0d401f771e19 Mon Sep 17 00:00:00 2001 From: Joseph Lokahi Podwys Date: Thu, 30 Jul 2015 12:33:13 -0600 Subject: [PATCH 3/4] Adding type checking. Removing dumb stuff. --- expressStream.js | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/expressStream.js b/expressStream.js index 3672336..c7aaa43 100644 --- a/expressStream.js +++ b/expressStream.js @@ -2,28 +2,13 @@ var fs = require('fs'); var streamBefore = []; var streamAfter = []; -var openDocument = false; -var closeHeadOpenBody = false; -var closeDocument = false; exports.streamBefore = function(before){ - streamBefore = before; + streamBefore = (typeof before === 'object' && before.length) ? before : []; } exports.streamAfter = function(after){ - streamAfter = after; -} - -exports.openDocument = function(val){ - openDocument = val; -} - -exports.closeHeadOpenBody = function(val){ - closeHeadOpenBody = val; -} - -exports.closeDocument = function(val){ - closeDocument = val; + streamAfter = (typeof after === 'object' && after.length) ? after : []; } exports.stream = function(middlewareViews){ @@ -49,17 +34,10 @@ exports.stream = function(middlewareViews){ for(var i = 0; i < streamAfter.length; i++){ res.stream(streamAfter[i]); } - if(closeDocument){ - res.write(''); - } this._end(); } } - if(openDocument){ - res.write(''); - } - for(var i = 0; i < streamBefore.length; i++){ res.stream(streamBefore[i]); } @@ -75,10 +53,6 @@ exports.stream = function(middlewareViews){ } } - if(closeHeadOpenBody){ - res.write(''); - } - next(); } } From 7231f8d1c45db074cc8c72548ec5935c12c1dc58 Mon Sep 17 00:00:00 2001 From: Joseph Lokahi Podwys Date: Thu, 30 Jul 2015 12:34:28 -0600 Subject: [PATCH 4/4] Bumping release. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": {