Repository navigation
feat: write the deflated transfer syntax - #560
Merged
Merged
Conversation
DicomDict.write now emits Deflated Explicit VR Little Endian (1.2.840.10008.1.2.1.99): the preamble, DICM magic and file meta group stay uncompressed per PS3.10 A.5, and the body is encoded as explicit little endian then raw-deflated (pako.deflateRaw, the mirror of the read side's inflateRaw). Ported from the v2 rewrite's DicomDict deflate branch, minus the lazy-core passthrough context that does not exist on this branch. BufferStream gains writeRawBytes for appending the already-encoded deflated body. The corpus gate's deflate skip-list (image_dfl, report_dfl, wave_dfl) is removed — the trio now round-trips bytes -> events -> Part 10 -> readback like every other fixture. test/write-deflate.test.js adapts the v2 suite to this branch's two read paths (eager readFile and fromPart10Stream), and the lossless-read-write deflate pixel-data test now inflates the body before scanning, since the body is actually compressed. 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 ports deflate-on-write from the v2 rewrite, closing the last write-side transfer-syntax gap on this branch. Until now
DicomDict.writecould read Deflated Explicit VR Little Endian (1.2.840.10008.1.2.1.99) but not write it: asked to write under that syntax, it emitted an uncompressed body beneath a meta group that declared it deflated, which no conformant reader can consume. That is exactly why PR #553's corpus gate had to skip-list the deflate trio (image_dfl,report_dfl,wave_dfl).The fix is the v2 branch's deflate arm of
DicomDict.write, ported nearly verbatim minus the lazy-core passthrough context that does not exist here: per PS3.10 A.5 the preamble,DICMand the file meta group are written uncompressed, then the body is encoded as plain explicit little endian into a scratch stream and appended raw-deflated (pako.deflateRaw, the exact mirror of the read side'sinflateRaw— pako was already a dependency for reading, so no new package).BufferStreamgains the smallwriteRawByteshelper the branch needs, adapted from v2 without its zero-copy window machinery.Writing a deflated file and reading it back now just works, through both read paths:
Tests came first, failing on the unfixed code with pako's "invalid stored block lengths" — the raw-inflate of what was really an uncompressed body. The new
test/write-deflate.test.jsadapts v2's 398-linewrite-deflate.test.jsto this branch: the helpers (fixture reading, byte-diff reporting) came over verbatim, but the lazy-core passthrough byte-identity assertions became a core-valid equivalent — inflating the deflated output body must be byte-identical to writing the same dict as plain ELE — and the v2 "both cores" re-reads became this branch's two readers, eagerreadFileandfromPart10Stream. The v2 suite's@dcmjs/parserand published dicom-parser cross-checks were replaced by the independenttest/issues/part10Walker.js, which proves the meta group stays uncompressed using no dcmjs read code at all. Seven tests cover: the three fixtures round-tripping as deflated, an edited element re-encoded under the wrapper, ELE→deflated and deflated→ELE conversions, and a freshly built dict written deflated.With the capability in place, the #553 skip-list is deleted outright — the corpus gate now runs the deflate trio through bytes → events → Part 10 → readback like every other fixture, so deflate round-trips are gate-covered from here on. One pre-existing test moved with the behavior: the lossless-read-write "deflated pixel data has explicit length" test scanned the raw output buffer, which only worked because the body was (wrongly) uncompressed; it now inflates the body first and scans that.
On the budget: 418 inserted lines total, of which roughly 85 are verbatim or near-verbatim from v2 (the
DicomDict.writedeflate branch,writeRawBytes, and the test helpers), leaving about 330 hand-written — most of it the reworked test suite. Suite goes from 832 passing / 846 total to 842 passing / 856 total: seven new tests plus the three un-skipped corpus fixtures.🤖 Generated with Claude Code