UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

26 lines (25 loc) 923 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseLineByLine = parseLineByLine; const index_1 = require("./index"); 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++ % 10000 === 0) { statusCallback(`Loading ${(0, index_1.getProgressDisplayStr)(blockStart, buffer.length)}`); } blockStart = lineEnd + 1; } }