]> git.ardis.lu - csvio/commitdiff
Simplify ReadableStream constructor
authorArdis Lu <ardisglu@gmail.com>
Sun, 9 Feb 2025 05:18:27 +0000 (21:18 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sun, 9 Feb 2025 05:18:27 +0000 (21:18 -0800)
test/utils.js

index 847391676862d531d7cf69eb4ffa228c8110d9b3..deadbd422743894289acf19a99d3dbb462fd8baa 100644 (file)
@@ -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
This page took 0.046016 seconds and 4 git commands to generate.