Skip to content

Instantly share code, notes, and snippets.

@tusharmath
Created July 29, 2015 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tusharmath/f6fcf3a0f58194aeba60 to your computer and use it in GitHub Desktop.
Save tusharmath/f6fcf3a0f58194aeba60 to your computer and use it in GitHub Desktop.
Dynamically create a downloadable file for test purposes
"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