@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
23 lines (22 loc) • 814 B
JavaScript
import { getProgressDisplayStr } from "./index.js";
export function parseLineByLine(buffer, lineCallback, statusCallback = () => { }) {
const decoder = new TextDecoder('utf8');
let blockStart = 0;
let i = 0;
while (blockStart < buffer.length) {
const n = buffer.indexOf(10, blockStart);
const lineEnd = n === -1 ? buffer.length : n;
const b = buffer.subarray(blockStart, lineEnd);
const line = decoder.decode(b).trim();
if (line) {
const shouldContinue = lineCallback(line, i);
if (shouldContinue === false) {
break;
}
}
if (i++ % 10_000 === 0) {
statusCallback(`Loading ${getProgressDisplayStr(blockStart, buffer.length)}`);
}
blockStart = lineEnd + 1;
}
}