Created
March 24, 2020 15:06
-
-
Save hetzge/8399cb1e1279c0f50772e0e24d3576f1 to your computer and use it in GitHub Desktop.
Read ArrayBuffer line by line in browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function readLineByLine(data, callback) { | |
| let dataLength = data.length; | |
| let lineStart = 0; | |
| for (let i = 0; i < dataLength; i++) { | |
| // 10 = \n | |
| // 13 = \r | |
| if (data[i] === 10 || data[i] === 13) { | |
| try { | |
| const line = data.slice(lineStart, i).toString().trim(); | |
| if (line !== "") { | |
| callback(line); | |
| } | |
| } finally { | |
| lineStart = i; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment