Skip to content

fix(core): part of a Blob read as a stream ends where it was asked to, on any runtime - #52

Merged
pierreneter merged 1 commit into
mainfrom
fix/blob-stream-length
Nov 23, 2026
Merged

pierreneter merged 1 commit into
mainfrom
fix/blob-stream-length

Conversation

@pierreneter

Copy link
Copy Markdown
Member

Fixes #49.

What was wrong

On Bun 1.3.6 the stream of a Blob slice does not stop at the end of the slice: blob.slice(10, 49).stream() gives 990 bytes of a 1000-byte Blob (39 on Bun 1.4.4 and Node). A stored ZIP entry is read to the end of its stream, so the checksum of an .odt's mimetype covered the rest of the file and every .odt failed to open there.

The change

BlobSource.stream() cuts its stream at the length asked for and cancels what would still come, whatever the runtime sends. No engines requirement: a server package (#43) does not have to rely on the runtime here.

The other .stream() calls in src/core read a whole Blob, not a slice, and are not affected.

Tests

New test/blob-source.test.ts: a Blob whose slice streams run on to the end, as on Bun 1.3, so the case is tested on every runtime; empty chunks; cancelling; a stored ZIP entry followed by others, read through ZipArchive against its checksum.

Runtime source.ts test/blob-source.test.ts test/legacy-odt.test.ts
Bun 1.4.4 main 3 of 5 fail 20 pass
Bun 1.3.6 main 4 of 5 fail 5 of 20 fail
Bun 1.4.4 this change 5 pass 20 pass
Bun 1.3.6 this change 5 pass 20 pass

🤖 Generated with Claude Code

…, on any runtime

On Bun 1.3 the stream of a Blob slice runs on to the end of the whole Blob.
A stored ZIP entry is read to the end of its stream, so its checksum covered
the rest of the file: every .odt failed to open ("the part “mimetype” does
not unpack correctly") and 5 tests of test/legacy-odt.test.ts failed there.

BlobSource.stream() now cuts its stream at the length asked for and cancels
what would still come, whatever the runtime sends.

Fixes #49

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@pierreneter
pierreneter merged commit f08a997 into main Nov 23, 2026
2 checks passed
@pierreneter
pierreneter deleted the fix/blob-stream-length branch November 23, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BlobSource.stream() returns bytes past the requested length on Bun 1.3

1 participant