I have a websocket handler that writes a message to a file with the function below. However, with a large message, saving the file can take a long time. Is there a way to pipe the the websocket message directly to the file, or to speed up how long it takes to receive and save it?
var fs = require('fs');
function wsHandler(ws) {
ws.on('message', function wsData(msg) {
try {
let data = (JSON.parse(msg));
/*data would be this:
data = {'command':'saveFile',
'fileName': 'test.txt',
'fileData':'This is a test of the file data,
but imagine it is 4KB of information.'
}
*/
try {
switch(data.command) {
case 'saveFile':
fs.writeFileSync(data.fileName, data.fileData);
break;
}
}
catch(err){}
}
catch(err){}
});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I have a websocket handler that writes a message to a file with the function below. However, with a large message, saving the file can take a long time. Is there a way to pipe the the websocket message directly to the file, or to speed up how long it takes to receive and save it?