-
• #2
There's nothing built-in, but I did do something for the laser cutter that worked quite well. I just stripped it down for you below:
function readLines(fileName, lineCallback, completeCallback) { var f = E.openFile(fileName); var buffer = f.read(64); if (buffer===undefined) { console.log("Couldn't load file"); completeCallback(); return; } function newLine() { // get new data from file while (buffer.indexOf("\n")<0) { var r = f.read(64); if (r===undefined) { f.close(); break; } buffer += r; } // if we didn't get any data, finish... if (buffer==="") return completeCallback(); // get new line var eol = buffer.indexOf("\n"); if (eol<0) eol = buffer.length; var line = buffer.substr(0,eol); buffer = buffer.substr(eol+1); lineCallback(line); setTimeout(newLine, 1); // next line on idle } newLine(); }
Is there a function to loop through lines in a file, something like file.readLine ?
I'm working on a datalogger which creates big json-files.
Data will be available using an ESP8266.
There are some limitations in serial interface, therefore I need to split data.