server/utils.js
function interceptWriteStream(writeStream) {
	return new Promise((resolve, reject) => {
		let response = "";
		let writeBkp = writeStream.write;
		let sendBkp = writeStream.send; // For express response streams
		let endBkp = writeStream.end;

		writeStream.write = function(chunk, encoding, callback) {
			response += chunk;

			if(typeof encoding == "function") {
				encoding();
			} else if(callback) {
				callback();
			}
			return true;
		};

		writeStream.send = function(body) {
			writeStream.end(body);
		};

		writeStream.end = function(chunk, encoding, callback) {
			if(chunk) {
				response += chunk;
			}

			writeStream.write = writeBkp;
			writeStream.send = sendBkp;
			writeStream.end = endBkp;

			if(typeof encoding == "function") {
				writeStream.once("finish", encoding);
			} else if(callback) {
				writeStream.once("finish", encoding);
			}

			resolve(response);
		};
	});
}
function interceptWriteStream(writeStream) {
	return new Promise((resolve, reject) => {
		let response = "";
		let writeBkp = writeStream.write;
		let sendBkp = writeStream.send; // For express response streams
		let endBkp = writeStream.end;

		writeStream.write = function(chunk, encoding, callback) {
			response += chunk;

			if(typeof encoding == "function") {
				encoding();
			} else if(callback) {
				callback();
			}
			return true;
		};

		writeStream.send = function(body) {
			writeStream.end(body);
		};

		writeStream.end = function(chunk, encoding, callback) {
			if(chunk) {
				response += chunk;
			}

			writeStream.write = writeBkp;
			writeStream.send = sendBkp;
			writeStream.end = endBkp;

			if(typeof encoding == "function") {
				writeStream.once("finish", encoding);
			} else if(callback) {
				writeStream.once("finish", encoding);
			}

			resolve(response);
		};
	});
}
Intercepts the "write" and "end" methods of the given writable stream and buffers the values written to them instead.
When the stream ends, the buffered value is returned and the original "write" and "end" methods are restored.
@param writeStream {stream.Writable}
@returns {Promise.<string>}