(chunkOrString: Buffer | string)
| 1 | export function* eachLine(chunkOrString: Buffer | string): Generator<Buffer | string> { |
| 2 | let position = 0; |
| 3 | const chunk = typeof chunkOrString === 'string' ? Buffer.from(chunkOrString) : chunkOrString; |
| 4 | while (position < chunk.length) { |
| 5 | const newline = chunk.indexOf('\n', position); |
| 6 | if (newline === -1) { |
| 7 | yield chunk.subarray(position).toString('utf8') + '\n'; |
| 8 | break; |
| 9 | } |
| 10 | yield chunk.subarray(position, newline).toString('utf8') + `\n`; |
| 11 | position = newline + 1; |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | export async function* pipeEachLine(source: AsyncGenerator<Buffer | string>): AsyncGenerator<Buffer | string> { |
| 16 | for await (const chunk of source) { |
no test coverage detected