]> git.ardis.lu - csvio/commitdiff
Explicitly assert that `byobRequest` and `view` are not null
authorArdis Lu <ardisglu@gmail.com>
Sun, 4 May 2025 02:21:40 +0000 (19:21 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 4 May 2025 02:21:40 +0000 (19:21 -0700)
src/core.js

index 37b36368efa8d9ae1ca673d54e3953cced30adb7..4756db73282621409d2f630ab4af292b05700c7a 100644 (file)
@@ -48,16 +48,23 @@ export function createFileStream(path) {
       resolveReady();
     },
     async pull(controller) {
-      const v = controller.byobRequest.view;
-      const { bytesRead } = await handle.read(v, 0, v.byteLength, position);
+      // byobRequest can never be null if autoAllocateChunkSize is set.
+      // https://streams.spec.whatwg.org/#dom-underlyingsource-autoallocatechunksize
+      const byobRequest = /** @type {ReadableStreamBYOBRequest} */(controller.byobRequest);
+
+      // view can never be null since this is the first reference to the view within the response (i.e., it is
+      // impossible to respond to the byobRequest and set view to null before this moment).
+      const view = /** @type {ArrayBufferView<ArrayBufferLike>} */(byobRequest.view);
+
+      const { bytesRead } = await handle.read(view, 0, view.byteLength, position);
       if (bytesRead === 0) {
         await handle.close();
         controller.close();
-        controller.byobRequest.respond(0);
+        byobRequest.respond(0);
       }
       else {
         position += bytesRead;
-        controller.byobRequest.respond(bytesRead);
+        byobRequest.respond(bytesRead);
       }
     },
     async cancel() {
This page took 0.049127 seconds and 4 git commands to generate.