Skip to content

feat(eventStream): collector-backed writer sinks — Part10Writer and DicomWebJsonWriter - #553

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/writer-sinks
Sep 30, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/writer-sinks

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This lands the first two writer sinks, making the event-stream contract a two-way street. Until now the contract only read: bytes, dicts, or DICOMweb JSON in — events out. These two listeners are the other direction: events in, serialized output out. Part10Writer produces Part 10 bytes, and DicomWebJsonWriter produces the DICOMweb JSON metadata model. With them merged, any source can be re-serialized to either format, and DICOMweb JSON round-trips through the contract as an identity.

Both are deliberately thin. Part10Writer is a 36-line layer over the canonical encoder, not a second encoder: it extends CollectorListener to gather the events into a tag-keyed { meta, dict } tree, then delegates every byte of serialization — VRs, undefined-length sequences, padding, group-length recompute — to the proven DicomDict.write(). DicomWebJsonWriter walks the events with a small container stack and emits { vr, Value } / { BulkDataURI } / { InlineBinary } attributes, preserving the binary source form (a bulk reference stays a reference; assembled fragments become base64) and using the PS3.18 escape hatch of string-encoding DS/IS values whose numeric form would silently lose integer precision.

To be plain about provenance, since this is a port from the v2 rewrite branch: both source files are verbatim v2 code. The hand-written parts are the index.js exports (core's index is ahead of v2's, so those are added by hand rather than copied) and three adaptations in the ported tests. The fixture paths moved to this branch's layout (packages/fixtures/...). One v2 test drove the writer through the DicomEventStream.toPart10() facade, which is a later slice here, so the same minimal write is exercised through the listener directly. And the corpus round-trip gate — every vendored fixture read to events, written back to Part 10, re-read, and compared naturalized-object to naturalized-object — skip-lists the three deflate fixtures on the write side only, with a comment explaining why: this branch's DicomDict.write does not yet implement deflate-on-write (that is the W4 slice of the writers wave), so it would emit an uncompressed body under the deflated transfer syntax. The skip entries name the files explicitly and come out when W4 lands.

Using the pair looks like this:

import { fromPart10, Part10Writer, DicomWebJsonWriter } from "./src/eventStream/index.js";

// Part 10 bytes -> events -> Part 10 bytes (semantically faithful re-serialization)
const writer = new Part10Writer();
await fromPart10(sourceBuffer, writer);
const bytes = writer.write();

// Part 10 bytes -> events -> DICOMweb JSON metadata
const json = new DicomWebJsonWriter();
await fromPart10(sourceBuffer, json);
json.result; // { "00100020": { vr: "LO", Value: ["12345"] }, ... }

33 new tests, 659 passing overall on this branch.

🤖 Generated with Claude Code

…icomWebJsonWriter

Ports the two collector-backed sinks from the v2 rewrite: Part10Writer
(events -> Part 10 bytes via CollectorListener + DicomDict.write) and
DicomWebJsonWriter (events -> DICOMweb JSON model). Both source files are
verbatim v2 ports; the index exports are added by hand. Tests travel with
the port, reworked for this branch's fixture layout, with the deflate
fixtures skip-listed on the write round-trip until deflate-on-write lands.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 4c14aee into release/1.0-beta-core Sep 30, 2026
10 of 11 checks passed
@awatson1978
awatson1978 deleted the core/writer-sinks branch September 30, 2026 12:38
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant