UNPKG

@beenotung/tslib

Version:
22 lines (21 loc) 537 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stream_lines = stream_lines; async function* stream_lines(stream) { let acc = ''; for await (const chunk of stream) { acc += chunk; for (;;) { const idx = acc.indexOf('\n'); if (idx === -1) { break; } const line = acc.slice(0, idx); yield line; acc = acc.slice(idx + 1); } } if (acc.length > 0) { yield acc; } }