Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bun.js/webcore/ByteBlobLoader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ pub fn toBufferedValue(this: *ByteBlobLoader, globalThis: *JSGlobalObject, actio
return blob.toPromise(globalThis, action);
}

return .zero;
var empty: Blob.Any = .{ .Blob = Blob.initEmpty(globalThis) };
return empty.toPromise(globalThis, action);
}

pub fn memoryCost(this: *const ByteBlobLoader) usize {
Expand Down
23 changes: 23 additions & 0 deletions test/js/web/streams/blob-stream-bytes-consumed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from "bun:test";

test("bytes() on consumed blob ReadableStream returns valid result", async () => {
// Create a blob-backed stream and fully consume it via reader
const blob = new Blob(["test data"]);
const stream = blob.stream();
const reader = stream.getReader();
const chunks: Uint8Array[] = [];
while (true) {
const { value, done } = await reader.read();
if (done) break;
chunks.push(value);
}
reader.releaseLock();

// Stream is closed, source store is consumed.
// Calling bytes() should return a valid empty Uint8Array, not crash.
// Without the fix, the native toBufferedValue returns .zero without
// setting an exception, causing an assertion failure in debug builds.
const result = await stream.bytes();
expect(result).toBeInstanceOf(Uint8Array);
expect(result.length).toBe(0);
});
Comment thread
claude[bot] marked this conversation as resolved.
Loading