UNPKG

@beenotung/tslib

Version:
37 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stream_lines = void 0; const tslib_1 = require("tslib"); function stream_lines(stream) { return tslib_1.__asyncGenerator(this, arguments, function* stream_lines_1() { var e_1, _a; let acc = ''; try { for (var stream_1 = tslib_1.__asyncValues(stream), stream_1_1; stream_1_1 = yield tslib_1.__await(stream_1.next()), !stream_1_1.done;) { const chunk = stream_1_1.value; acc += chunk; for (;;) { const idx = acc.indexOf('\n'); if (idx === -1) { break; } const line = acc.slice(0, idx); yield yield tslib_1.__await(line); acc = acc.slice(idx + 1); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (stream_1_1 && !stream_1_1.done && (_a = stream_1.return)) yield tslib_1.__await(_a.call(stream_1)); } finally { if (e_1) throw e_1.error; } } if (acc.length > 0) { yield yield tslib_1.__await(acc); } }); } exports.stream_lines = stream_lines; //# sourceMappingURL=generator.js.map