Skip to content

Commit

Permalink
Merge pull request #1 from jpodwys/features
Browse files Browse the repository at this point in the history
Features
  • Loading branch information
Joe Podwys committed Jul 30, 2015
2 parents 418d866 + 7231f8d commit 195bc1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions expressStream.js
Original file line number Diff line number Diff line change
@@ -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(){}
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 195bc1f

Please sign in to comment.