Repository navigation
feat: the bounded-memory streaming Part 10 reader, free of the vendored tokenizer - #538
Merged
Merged
Conversation
…ndored tokenizer Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
awatson1978
added a commit
that referenced
this pull request
Sep 30, 2026
Kept in-branch rather than as a GitHub issue for now. Finding 13 is marked fixed (#533) and the fromPart10Stream budget question is recorded as resolved by the granted waiver (#538). Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Sep 30, 2026
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the big one: the streaming Part 10 reader. It lands under the explicitly granted budget waiver —
fromPart10Streamis a single 1,468-line state machine and its test file is another 2,307 lines, so it arrives as one reviewable whole rather than artificially sliced into pieces that wouldn't make sense on their own.Here's what it does in plain terms. You feed it DICOM bytes in chunks — from a file stream, a network response, or one big buffer — and it emits parse events as the bytes arrive, instead of waiting for the whole file. The File Meta Information (the small header group that says, among other things, which transfer syntax — the byte-encoding scheme — the rest of the file uses) is decoded incrementally, so those events fire before the body has even finished arriving. The body then streams natively for every transfer syntax, including deflate (the compressed variant; it's inflated incrementally via pako rather than buffered whole). Encapsulated pixel data — compressed image frames stored as a list of fragments — streams fragment by fragment, with the Basic Offset Table (the index saying where each frame's fragments start) used to window them.
Memory stays bounded the whole time. Each top-level element's chunk memory is released via
consume()once the parse moves past it, and I added a backpressure relay toReadBufferStreamso that a throttled producer can never deadlock against a starved consumer. That relay is the machinery for review finding 12 (the feed loop used to keep buffering after a parse failure), and the K5b gate test covers it.Two structural decisions from your review are implemented here rather than inherited. First, the inversion you recommended: the vendored dicom-parser tokenizer is gone. The buffered
fromPart10is now a thin wrapper that feeds the streaming reader a single chunk, so the library carries exactly one tokenizer instead of two that have to agree. The shared emit helpers moved into their own module,src/eventStream/emit.js. Second, non-DICOM input now fails loudly on both entry points, with the streaming reader's own error — we no longer delegate to the old tokenizer just to match its error text. If you genuinely have a bare DIMSE-style dataset (one with no File Meta group at all), you force-read it with theallowMissingHeaderopt-in that landed in the previous PR. The issue #93 suite now pins that end to end, with its two placeholder tests unskipped.One test flipped direction because of the inversion. It used to pin a known divergence: for a non-conformant undefined-length UT element, the old tokenizer path silently returned garbage while the stream threw. Both entry points are now the same code, so the test pins the opposite — both fail loudly instead of silently corrupting data.
Here's what using it looks like. Any chunked source works: Node streams, WHATWG
ReadableStream, async generators, or a plain buffer as a degenerate single chunk.On testing: the corpus gate runs every vendored test image — all endianness, deflate, and encapsulated permutations — through the raw-bytes-to-events path and compares element for element against the eager reader. That gate is also what surfaced the xs resolution defect fixed in the previous PR.
🤖 Generated with Claude Code