🐛 GCV: Fix pending file position bug
If we strip \r from \r\n, our line length and thus file position calculation will be off by one. We'll just leave it in as it doesn't influence our parsing and makes things way easier. Thanks to @JoveToo for the heads-up on Discord.
This commit is contained in:
1 parent
6f02720d38
commit
61ec5bd5b7
1 file changed
+16
-3
@@ -54,7 +54,7 @@ GCODE.gCodeReader = (function () {
|
||||
|
||||
byteCount = 0;
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
byteCount += lines[i].length + 1; // line length + line ending
|
||||
byteCount += lines[i].length + 1; // line length + '\n'
|
||||
gcode.push({line: lines[i], percentage: (byteCount * 100) / totalSize});
|
||||
}
|
||||
lines = [];
|
||||
@@ -188,8 +188,21 @@ GCODE.gCodeReader = (function () {
|
||||
this.clear();
|
||||
|
||||
var totalSize = reader.target.result.length;
|
||||
// With a regex split below as previous, memory usage is huge & takes longer.
|
||||
lines = reader.target.result.replace("\r\n", "\n").split("\n");
|
||||
|
||||
/*
|
||||
* Split by line ending
|
||||
*
|
||||
* Note that for windows line endings \r\n this leaves the \r attached to
|
||||
* the lines. That will not influence our parser, but makes file position
|
||||
* calculation way easier (line length + 1), so we just leave it in.
|
||||
*
|
||||
* This cannot cope with old MacOS \r line endings, but those should
|
||||
* really not be used anymore and thus we'll happily ignore them here.
|
||||
*
|
||||
* A simple string split uses up *much* less memory than regex.
|
||||
*/
|
||||
lines = reader.target.result.split("\n");
|
||||
|
||||
reader.target.result = null;
|
||||
prepareGCode(totalSize);
|
||||
|
||||
|
||||
Reference in new issue
Block a user