From: Ardis Lu Date: Sun, 9 Feb 2025 05:18:27 +0000 (-0800) Subject: Simplify ReadableStream constructor X-Git-Tag: v0.1.0~65 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=10339b5f01fc61905513b62f2061b2883decad85;p=csvio Simplify ReadableStream constructor --- diff --git a/test/utils.js b/test/utils.js index 8473916..deadbd4 100644 --- a/test/utils.js +++ b/test/utils.js @@ -191,23 +191,12 @@ function getPseudoRandomValues(typedArray, seed) { */ export function createRandomCSV(rows, columns, seed) { const chunks = (function* () { - while (rows) { + while (rows--) { const data = new Uint32Array(columns); getPseudoRandomValues(data, seed); seed = data[columns - 1]; - rows--; - yield Array.from(data); + yield JSON.stringify(Array.from(data)); } })(); - return new ReadableStream({ - pull(controller) { - const { value, done } = chunks.next(); - if (done) { - controller.close(); - } - else { - controller.enqueue(JSON.stringify(value)); - } - } - }); + return ReadableStream.from(chunks); } \ No newline at end of file