Created
July 29, 2015 07:11
-
-
Save tusharmath/f6fcf3a0f58194aeba60 to your computer and use it in GitHub Desktop.
Dynamically create a downloadable file for test purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var express = require('express'), | |
app = express(), | |
CHAR = '*', | |
port = 3000; | |
var defer = Promise.defer(); | |
app.get('/chunk/:size.txt', function (req, res) { | |
var count = 0, | |
size = parseInt(req.params.size); | |
while (count < size) { | |
res.write(CHAR); | |
count++; | |
} | |
res.send(); | |
}).get('/range/:size.txt', function (req, res) { | |
var count = 0, | |
str = '', | |
size = parseInt(req.params.size); | |
while (count < size) { | |
str += CHAR; | |
count++; | |
} | |
res.send(str); | |
}); | |
exports.start = function () { | |
app.listen(port, defer.resolve); | |
return defer.promise; | |
}; | |
exports.stop = ()=> app._close; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment