@dcmjs-org/generator 0.0.0-stage → 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/License.txt ADDED
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2017 Steve Pieper
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ # @dcmjs-org/generator
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The event-stream writing side of dcmjs: the sinks that consume the
4
+ `@dcmjs-org/parser` contract and produce output — `Part10Writer` (collect, then
5
+ serialize through the canonical encoder), `StreamingPart10Writer` (emit Part
6
+ 10 bytes incrementally, bounded memory), and `DicomWebJsonWriter` (the DICOM
7
+ JSON model).
8
+
9
+ Dependencies, by design:
10
+
11
+ - `@dcmjs-org/parser` for the contract (`EventStreamListener`) and the
12
+ `CollectorListener` the collect-then-serialize writer layers on;
13
+ - `@dcmjs-org/core` for the write primitives (`writeDataSet`, `writeTagObject`),
14
+ the Part 10 envelope (`writePart10` — deflate, padding, Big16, group-length
15
+ recomputation; `Part10Writer` is by design a thin layer over it), buffer
16
+ streams, and constants. That is the whole list: the temporary
17
+ `@dcmjs-org/legacy` edge this paragraph used to declare (Part10Writer
18
+ layering on legacy `DicomDict.write()`) closed in October 2026 when that
19
+ envelope was relocated into core as `writePart10` and `DicomDict.write()`
20
+ became a delegating call; `test/standalone.test.js` in this package pins
21
+ the legacy-free module graph.
22
+
23
+ During the 1.0 beta this package is marked private; the publish flag flips when
24
+ the workspace layout settles, per RELEASE_PLAN.md.
package/dist/index.cjs ADDED
@@ -0,0 +1,515 @@
1
+ 'use strict';
2
+
3
+ var parser = require('@dcmjs-org/parser');
4
+ var core = require('@dcmjs-org/core');
5
+
6
+ /**
7
+ * Part10Writer — slice E2: an event-stream sink that produces DICOM Part 10
8
+ * bytes.
9
+ *
10
+ * Architecture: this is a thin LAYER over the canonical encoder, not a second
11
+ * encoder. It collects the event stream into a tag-keyed `{ meta, dict }` tree
12
+ * (reusing CollectorListener) and delegates serialization to core's
13
+ * `writePart10` (the proven Part 10 envelope, relocated from legacy
14
+ * `DicomDict.write()`), which handles every VR, undefined-length sequences,
15
+ * deflate, padding, Big16, and FileMetaInformationGroupLength recomputation.
16
+ * This closed the one temporary `@dcmjs-org/legacy` edge this package had.
17
+ *
18
+ * Byte-IDENTICAL Part 10 round-tripping (incl. re-emitting compressed pixel data
19
+ * verbatim) is intentionally NOT this path's job — that is a non-goal of the
20
+ * naturalized/event layer (spec §4.5) and remains served by the lazy-read +
21
+ * R4 passthrough-write path. This writer produces correct, semantically faithful
22
+ * Part 10 output from any event source.
23
+ */
24
+ class Part10Writer extends parser.CollectorListener {
25
+ /**
26
+ * Serialize the collected dataset to a Part 10 ArrayBuffer.
27
+ * @param {Object} [writeOptions] forwarded to writePart10
28
+ * @returns {ArrayBuffer}
29
+ */
30
+ write(writeOptions) {
31
+ const meta = { ...this.result.meta };
32
+ // writePart10 recomputes the group length; drop any collected one so
33
+ // it is not double-counted.
34
+ delete meta["00020000"];
35
+
36
+ const dataSet = { meta, dict: this.result.dict };
37
+ return writeOptions
38
+ ? core.writePart10(dataSet, writeOptions)
39
+ : core.writePart10(dataSet);
40
+ }
41
+ }
42
+
43
+ const FMI_GROUP_LENGTH = "00020000";
44
+ const TRANSFER_SYNTAX_UID = "00020010";
45
+ const UNDEFINED_LENGTH = 0xffffffff;
46
+
47
+ /**
48
+ * StreamingPart10Writer — plan-R2: an event-stream sink that emits DICOM
49
+ * Part 10 bytes incrementally, as events arrive, instead of collecting the
50
+ * whole dataset first like {@link Part10Writer}.
51
+ *
52
+ * Purpose: writing datasets whose Pixel Data does not fit in memory (the
53
+ * R2 trigger — e.g. a Supplement 225 fragmentable video instance measured in
54
+ * tens of GB). Peak memory is bounded by the largest single non-encapsulated
55
+ * element plus the file meta group; encapsulated pixel-data fragments are
56
+ * forwarded chunk-for-chunk and never accumulated.
57
+ *
58
+ * Output contract: `options.onChunk(Uint8Array)` is called zero or more times
59
+ * per event, in file order. Absent `onChunk`, chunks accumulate on
60
+ * `this.chunks` (testing convenience; that mode is NOT streaming). The caller
61
+ * owns backpressure: wire the generator's `setDrain` to the sink that
62
+ * consumes the chunks (e.g. a Node fs write stream's own drain).
63
+ *
64
+ * Encoding decisions (all legal Part 10, all chosen to avoid backpatching):
65
+ * - the file meta group is buffered — it is small and its group length
66
+ * (0002,0000) must be computed over the encoded elements, exactly as
67
+ * DicomDict.write does;
68
+ * - sequences and their items are written with undefined length and closed
69
+ * with item/sequence delimitation items;
70
+ * - encapsulated pixel data is written with undefined length, an empty
71
+ * Basic Offset Table, one item per incoming fragment (odd fragments are
72
+ * padded), and a sequence delimiter.
73
+ *
74
+ * Byte-identical round-tripping remains a non-goal (spec §4.5 / D15): output
75
+ * is correct, semantically faithful Part 10, not a byte-for-byte copy of any
76
+ * source.
77
+ *
78
+ * Not supported (throws): deflated transfer syntax, bulkDataReference events
79
+ * (the bytes are elsewhere — materialize them first), sequences inside the
80
+ * file meta group.
81
+ */
82
+ class StreamingPart10Writer extends parser.EventStreamListener {
83
+ /**
84
+ * @param {Object} [options]
85
+ * @param {(chunk: Uint8Array) => void} [options.onChunk] - Byte sink;
86
+ * defaults to accumulating on `this.chunks`.
87
+ * @param {Object} [options.writeOptions] - Forwarded to the element
88
+ * encoders (e.g. { allowInvalidVRLength }).
89
+ * @param {...Object} filters - Event-stream filters, as for any listener.
90
+ */
91
+ constructor(options = {}, ...filters) {
92
+ super(...filters);
93
+ this.chunks = [];
94
+ this._onChunk = options.onChunk ?? (chunk => this.chunks.push(chunk));
95
+ this._writeOptions = options.writeOptions ?? {
96
+ allowInvalidVRLength: false
97
+ };
98
+ this.bytesWritten = 0;
99
+ this._inMeta = false;
100
+ this._meta = {};
101
+ this._bodySyntax = core.EXPLICIT_LITTLE_ENDIAN;
102
+ this._current = null;
103
+ this._encapsulated = false;
104
+ this.done = false;
105
+ }
106
+
107
+ /**
108
+ * Endianness for every header the writer builds itself (sequence, item,
109
+ * delimiter and encapsulated pixel-data headers). Review finding 5: these
110
+ * were hardcoded little-endian while plain elements followed the body
111
+ * syntax, so an Explicit VR Big Endian file disagreed with itself. File
112
+ * Meta streams do NOT use this — the meta group is always explicit
113
+ * little endian (PS3.10 §7.1).
114
+ * @private
115
+ */
116
+ get _bodyLittleEndian() {
117
+ return this._bodySyntax !== core.EXPLICIT_BIG_ENDIAN;
118
+ }
119
+
120
+ /** @param {ArrayBuffer|Uint8Array} bytes @private */
121
+ _emit(bytes) {
122
+ const chunk =
123
+ bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
124
+ this.bytesWritten += chunk.byteLength;
125
+ this._onChunk(chunk);
126
+ }
127
+
128
+ /** @private */
129
+ _emitStream(stream) {
130
+ this._emit(stream.getBuffer(0, stream.size));
131
+ }
132
+
133
+ /**
134
+ * Writes a bare tag + 32-bit length, the form shared by item and
135
+ * delimitation items (never a VR).
136
+ * @private
137
+ */
138
+ _writeRawTag(stream, group, element, length) {
139
+ stream.writeUint16(group);
140
+ stream.writeUint16(element);
141
+ stream.writeUint32(length);
142
+ }
143
+
144
+ /**
145
+ * Writes an element header in the long (reserved + 32-bit length) form —
146
+ * the only form needed for the headers this writer emits itself (SQ and
147
+ * encapsulated OB/OW/UN); everything else goes through
148
+ * core's writeTagObject.
149
+ * @private
150
+ */
151
+ _writeLongHeader(stream, tag, vr, length) {
152
+ stream.writeUint16(parseInt(tag.substring(0, 4), 16));
153
+ stream.writeUint16(parseInt(tag.substring(4, 8), 16));
154
+ if (this._bodySyntax !== core.IMPLICIT_LITTLE_ENDIAN) {
155
+ stream.writeAsciiString(vr);
156
+ stream.writeUint16(0);
157
+ }
158
+ stream.writeUint32(length);
159
+ }
160
+
161
+ _baseStartDataSet() {}
162
+
163
+ _baseEndDataSet() {
164
+ this.done = true;
165
+ }
166
+
167
+ _baseStartFileMetaInformation() {
168
+ this._inMeta = true;
169
+ const stream = new core.WriteBufferStream(160, true);
170
+ stream.writeUint8Repeat(0, 128);
171
+ stream.writeAsciiString("DICM");
172
+ this._emitStream(stream);
173
+ }
174
+
175
+ _baseEndFileMetaInformation() {
176
+ this._inMeta = false;
177
+ if (!this._meta[TRANSFER_SYNTAX_UID]) {
178
+ this._meta[TRANSFER_SYNTAX_UID] = {
179
+ vr: "UI",
180
+ Value: [core.EXPLICIT_LITTLE_ENDIAN]
181
+ };
182
+ }
183
+ this._bodySyntax = this._meta[TRANSFER_SYNTAX_UID].Value[0];
184
+ if (this._bodySyntax === core.DEFLATED_EXPLICIT_LITTLE_ENDIAN) {
185
+ throw new Error(
186
+ "StreamingPart10Writer does not support the deflated " +
187
+ "transfer syntax; inflate the source or use Part10Writer"
188
+ );
189
+ }
190
+ // Group length must cover the encoded meta elements, so the group is
191
+ // the one part of the file that cannot stream element-by-element.
192
+ delete this._meta[FMI_GROUP_LENGTH];
193
+ const metaStream = new core.WriteBufferStream(1024, true);
194
+ core.writeDataSet(
195
+ this._meta,
196
+ metaStream,
197
+ core.EXPLICIT_LITTLE_ENDIAN,
198
+ this._writeOptions
199
+ );
200
+ const out = new core.WriteBufferStream(1024 + 16, true);
201
+ core.writeTagObject(
202
+ out,
203
+ FMI_GROUP_LENGTH,
204
+ "UL",
205
+ metaStream.size,
206
+ core.EXPLICIT_LITTLE_ENDIAN,
207
+ this._writeOptions
208
+ );
209
+ out.concat(metaStream);
210
+ this._emitStream(out);
211
+ this._meta = {};
212
+ }
213
+
214
+ _baseStartElement(tag, info = {}) {
215
+ this._current = { tag, vr: info.vr, values: [], emitted: false };
216
+ }
217
+
218
+ _baseValue(v) {
219
+ this._current.values.push(v);
220
+ }
221
+
222
+ _baseEndElement() {
223
+ const el = this._current;
224
+ this._current = null;
225
+ if (el.emitted) {
226
+ return; // encapsulated path already streamed it
227
+ }
228
+ if (this._inMeta) {
229
+ if (el.tag !== FMI_GROUP_LENGTH) {
230
+ this._meta[el.tag] = { vr: el.vr, Value: el.values };
231
+ }
232
+ return;
233
+ }
234
+ const stream = new core.WriteBufferStream(256, this._bodyLittleEndian);
235
+ core.writeTagObject(
236
+ stream,
237
+ el.tag,
238
+ el.vr,
239
+ el.values,
240
+ this._bodySyntax,
241
+ this._writeOptions
242
+ );
243
+ this._emitStream(stream);
244
+ }
245
+
246
+ _baseStartBinary(opts = {}) {
247
+ if (opts.encapsulated && this._inMeta) {
248
+ throw new Error(
249
+ "encapsulated binary is not legal in the file meta group"
250
+ );
251
+ }
252
+ if (!opts.encapsulated) {
253
+ // Defined-length binary: fragments accumulate on the element and
254
+ // endElement serializes it whole (bounded by that one element).
255
+ this._encapsulated = false;
256
+ return;
257
+ }
258
+ this._encapsulated = true;
259
+ this._current.emitted = true;
260
+ const stream = new core.WriteBufferStream(24, this._bodyLittleEndian);
261
+ this._writeLongHeader(
262
+ stream,
263
+ this._current.tag,
264
+ this._current.vr || "OB",
265
+ UNDEFINED_LENGTH
266
+ );
267
+ // Empty Basic Offset Table: generators emit data fragments only (the
268
+ // source table, if any, indexes source offsets that no longer hold).
269
+ this._writeRawTag(stream, 0xfffe, 0xe000, 0);
270
+ this._emitStream(stream);
271
+ }
272
+
273
+ _baseBinaryFragment(chunk) {
274
+ const bytes =
275
+ chunk instanceof Uint8Array
276
+ ? chunk
277
+ : chunk instanceof ArrayBuffer
278
+ ? new Uint8Array(chunk)
279
+ : new Uint8Array(
280
+ chunk.buffer,
281
+ chunk.byteOffset,
282
+ chunk.byteLength
283
+ );
284
+ if (!this._encapsulated) {
285
+ // Review finding 11: bytes.buffer is the WHOLE backing store, so
286
+ // a subarray view would write (and retain) every byte of it.
287
+ // Slice out the view's own window when they differ.
288
+ this._current.values.push(
289
+ bytes.byteOffset === 0 &&
290
+ bytes.byteLength === bytes.buffer.byteLength
291
+ ? bytes.buffer
292
+ : bytes.buffer.slice(
293
+ bytes.byteOffset,
294
+ bytes.byteOffset + bytes.byteLength
295
+ )
296
+ );
297
+ return;
298
+ }
299
+ const pad = bytes.byteLength % 2;
300
+ const header = new core.WriteBufferStream(8, this._bodyLittleEndian);
301
+ this._writeRawTag(header, 0xfffe, 0xe000, bytes.byteLength + pad);
302
+ this._emitStream(header);
303
+ this._emit(bytes);
304
+ if (pad) {
305
+ this._emit(new Uint8Array(1));
306
+ }
307
+ }
308
+
309
+ _baseEndBinary() {
310
+ if (this._encapsulated) {
311
+ const stream = new core.WriteBufferStream(8, this._bodyLittleEndian);
312
+ this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);
313
+ this._emitStream(stream);
314
+ this._encapsulated = false;
315
+ }
316
+ }
317
+
318
+ _baseStartSequence(tag, info = {}) {
319
+ if (this._inMeta) {
320
+ throw new Error("sequences are not legal in the file meta group");
321
+ }
322
+ // Undefined length streams without backpatching; items and the
323
+ // delimiters below close it out (PS3.5 §7.5).
324
+ const stream = new core.WriteBufferStream(16, this._bodyLittleEndian);
325
+ this._writeLongHeader(stream, tag, info.vr || "SQ", UNDEFINED_LENGTH);
326
+ this._emitStream(stream);
327
+ }
328
+
329
+ _baseStartItem() {
330
+ const stream = new core.WriteBufferStream(8, this._bodyLittleEndian);
331
+ this._writeRawTag(stream, 0xfffe, 0xe000, UNDEFINED_LENGTH);
332
+ this._emitStream(stream);
333
+ }
334
+
335
+ _baseEndItem() {
336
+ const stream = new core.WriteBufferStream(8, this._bodyLittleEndian);
337
+ this._writeRawTag(stream, 0xfffe, 0xe00d, 0);
338
+ this._emitStream(stream);
339
+ }
340
+
341
+ _baseEndSequence() {
342
+ const stream = new core.WriteBufferStream(8, this._bodyLittleEndian);
343
+ this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);
344
+ this._emitStream(stream);
345
+ }
346
+
347
+ _baseBulkDataReference(ref = {}) {
348
+ throw new Error(
349
+ "StreamingPart10Writer cannot serialize a bulkDataReference " +
350
+ `(${ref.uri ?? "no uri"}); materialize bulk data before writing`
351
+ );
352
+ }
353
+
354
+ /**
355
+ * Testing convenience for the accumulate mode: the collected chunks as
356
+ * one ArrayBuffer. Meaningless when onChunk was provided.
357
+ * @returns {ArrayBuffer}
358
+ */
359
+ toArrayBuffer() {
360
+ const total = this.chunks.reduce((n, c) => n + c.byteLength, 0);
361
+ const out = new Uint8Array(total);
362
+ let offset = 0;
363
+ for (const chunk of this.chunks) {
364
+ out.set(chunk, offset);
365
+ offset += chunk.byteLength;
366
+ }
367
+ return out.buffer;
368
+ }
369
+ }
370
+
371
+ /**
372
+ * DicomWebJsonWriter — slice E1: an event-stream consumer that writes the
373
+ * DICOM JSON model (DICOMweb metadata representation).
374
+ *
375
+ * The faithful inverse of `fromDicomWebJson`: it makes the contract a SINK as
376
+ * well as a source, so the architecture round-trips
377
+ * (DICOMweb JSON -> events -> DICOMweb JSON is identity) and any source can be
378
+ * serialized to DICOMweb JSON (Part 10 -> events -> JSON).
379
+ *
380
+ * Output shape per tag: `{ vr, Value: [...] }`, or `{ vr, BulkDataURI }`, or
381
+ * `{ vr, InlineBinary: base64 }`. Person Names pass through as the DICOMweb
382
+ * `{ Alphabetic }` objects the contract carries. Binary source form is preserved
383
+ * (§25): a `bulkDataReference` stays a `BulkDataURI`; assembled binary fragments
384
+ * become base64 `InlineBinary`. Meta (group 0002) elements, when present, are
385
+ * written flat alongside the dataset.
386
+ */
387
+ class DicomWebJsonWriter extends parser.EventStreamListener {
388
+ constructor(...filters) {
389
+ super(...filters);
390
+ this.result = {};
391
+ // Stack of containers (the root object or a sequence item object) plus
392
+ // the element/sequence currently being built.
393
+ this._containers = [this.result];
394
+ this._pending = null; // { tag, attr, fragments? }
395
+ }
396
+
397
+ _container() {
398
+ return this._containers[this._containers.length - 1];
399
+ }
400
+
401
+ _baseStartDataSet() {
402
+ this.result = {};
403
+ this._containers = [this.result];
404
+ this._pending = null;
405
+ }
406
+
407
+ _baseStartElement(tag, info = {}) {
408
+ this._pending = { tag, attr: { vr: info.vr }, values: [] };
409
+ }
410
+
411
+ _baseValue(v, info) {
412
+ this._pending.values.push(this._jsonModelValue(v, info));
413
+ }
414
+
415
+ /**
416
+ * PS3.18 F.2.3.1: DS/IS may be encoded as JSON numbers OR strings.
417
+ * Emit a number when the conversion is lossless (dcm4chee parity, #53);
418
+ * fall back to the raw source string when Number() would silently lose
419
+ * integer precision — e.g. DS/IS integers beyond 2^53 (#398). The raw
420
+ * string is the standard's escape hatch; `_rawValue` itself never
421
+ * appears in the JSON model (#404).
422
+ */
423
+ _jsonModelValue(v, info) {
424
+ const vr = this._pending.attr.vr;
425
+ if (
426
+ (vr === "DS" || vr === "IS") &&
427
+ info &&
428
+ typeof info.rawValue === "string"
429
+ ) {
430
+ const raw = info.rawValue.trim();
431
+ const parsed = Number(raw);
432
+ if (
433
+ /^[+-]?\d+$/.test(raw) &&
434
+ !Number.isSafeInteger(parsed) &&
435
+ String(parsed) !== raw
436
+ ) {
437
+ return raw;
438
+ }
439
+ }
440
+ return v;
441
+ }
442
+
443
+ _baseBulkDataReference(ref = {}) {
444
+ this._pending.attr.BulkDataURI = ref.uri;
445
+ this._pending.values = null; // bulk reference carries no Value
446
+ }
447
+
448
+ _baseStartBinary() {
449
+ this._pending.fragments = [];
450
+ this._pending.values = null;
451
+ }
452
+
453
+ _baseBinaryFragment(chunk) {
454
+ this._pending.fragments.push(chunk);
455
+ }
456
+
457
+ _baseEndBinary() {
458
+ this._pending.attr.InlineBinary = core.encodeBase64(
459
+ concatFragments(this._pending.fragments)
460
+ );
461
+ }
462
+
463
+ _baseEndElement() {
464
+ const { tag, attr, values } = this._pending;
465
+ if (values && values.length) {
466
+ attr.Value = values;
467
+ }
468
+ this._container()[tag] = attr;
469
+ this._pending = null;
470
+ }
471
+
472
+ _baseStartSequence(tag, info = {}) {
473
+ const attr = { vr: info.vr, Value: [] };
474
+ this._container()[tag] = attr;
475
+ this._pending = null;
476
+ // Items are pushed into attr.Value via a sequence marker on the stack.
477
+ this._containers.push({ __seqValue: attr.Value });
478
+ }
479
+
480
+ _baseStartItem() {
481
+ const item = {};
482
+ this._container().__seqValue.push(item);
483
+ this._containers.push(item);
484
+ }
485
+
486
+ _baseEndItem() {
487
+ this._containers.pop();
488
+ }
489
+
490
+ _baseEndSequence() {
491
+ this._containers.pop();
492
+ }
493
+ }
494
+
495
+ function concatFragments(fragments) {
496
+ // a view, or a buffer (ArrayBuffer or SharedArrayBuffer)
497
+ const parts = fragments.map(f =>
498
+ ArrayBuffer.isView(f)
499
+ ? new Uint8Array(f.buffer, f.byteOffset, f.byteLength)
500
+ : new Uint8Array(f)
501
+ );
502
+ const total = parts.reduce((n, p) => n + p.length, 0);
503
+ const out = new Uint8Array(total);
504
+ let off = 0;
505
+ for (const p of parts) {
506
+ out.set(p, off);
507
+ off += p.length;
508
+ }
509
+ return out;
510
+ }
511
+
512
+ exports.DicomWebJsonWriter = DicomWebJsonWriter;
513
+ exports.Part10Writer = Part10Writer;
514
+ exports.StreamingPart10Writer = StreamingPart10Writer;
515
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/eventStream/Part10Writer.js","../src/eventStream/StreamingPart10Writer.js","../src/eventStream/DicomWebJsonWriter.js"],"sourcesContent":["import { CollectorListener } from \"@dcmjs-org/parser\";\nimport { writePart10 } from \"@dcmjs-org/core\";\n\n/**\n * Part10Writer — slice E2: an event-stream sink that produces DICOM Part 10\n * bytes.\n *\n * Architecture: this is a thin LAYER over the canonical encoder, not a second\n * encoder. It collects the event stream into a tag-keyed `{ meta, dict }` tree\n * (reusing CollectorListener) and delegates serialization to core's\n * `writePart10` (the proven Part 10 envelope, relocated from legacy\n * `DicomDict.write()`), which handles every VR, undefined-length sequences,\n * deflate, padding, Big16, and FileMetaInformationGroupLength recomputation.\n * This closed the one temporary `@dcmjs-org/legacy` edge this package had.\n *\n * Byte-IDENTICAL Part 10 round-tripping (incl. re-emitting compressed pixel data\n * verbatim) is intentionally NOT this path's job — that is a non-goal of the\n * naturalized/event layer (spec §4.5) and remains served by the lazy-read +\n * R4 passthrough-write path. This writer produces correct, semantically faithful\n * Part 10 output from any event source.\n */\nexport class Part10Writer extends CollectorListener {\n /**\n * Serialize the collected dataset to a Part 10 ArrayBuffer.\n * @param {Object} [writeOptions] forwarded to writePart10\n * @returns {ArrayBuffer}\n */\n write(writeOptions) {\n const meta = { ...this.result.meta };\n // writePart10 recomputes the group length; drop any collected one so\n // it is not double-counted.\n delete meta[\"00020000\"];\n\n const dataSet = { meta, dict: this.result.dict };\n return writeOptions\n ? writePart10(dataSet, writeOptions)\n : writePart10(dataSet);\n }\n}\n","import { EventStreamListener } from \"@dcmjs-org/parser\";\nimport {\n WriteBufferStream,\n EXPLICIT_BIG_ENDIAN,\n EXPLICIT_LITTLE_ENDIAN,\n IMPLICIT_LITTLE_ENDIAN,\n DEFLATED_EXPLICIT_LITTLE_ENDIAN,\n writeDataSet,\n writeTagObject\n} from \"@dcmjs-org/core\";\n\nconst FMI_GROUP_LENGTH = \"00020000\";\nconst TRANSFER_SYNTAX_UID = \"00020010\";\nconst UNDEFINED_LENGTH = 0xffffffff;\n\n/**\n * StreamingPart10Writer — plan-R2: an event-stream sink that emits DICOM\n * Part 10 bytes incrementally, as events arrive, instead of collecting the\n * whole dataset first like {@link Part10Writer}.\n *\n * Purpose: writing datasets whose Pixel Data does not fit in memory (the\n * R2 trigger — e.g. a Supplement 225 fragmentable video instance measured in\n * tens of GB). Peak memory is bounded by the largest single non-encapsulated\n * element plus the file meta group; encapsulated pixel-data fragments are\n * forwarded chunk-for-chunk and never accumulated.\n *\n * Output contract: `options.onChunk(Uint8Array)` is called zero or more times\n * per event, in file order. Absent `onChunk`, chunks accumulate on\n * `this.chunks` (testing convenience; that mode is NOT streaming). The caller\n * owns backpressure: wire the generator's `setDrain` to the sink that\n * consumes the chunks (e.g. a Node fs write stream's own drain).\n *\n * Encoding decisions (all legal Part 10, all chosen to avoid backpatching):\n * - the file meta group is buffered — it is small and its group length\n * (0002,0000) must be computed over the encoded elements, exactly as\n * DicomDict.write does;\n * - sequences and their items are written with undefined length and closed\n * with item/sequence delimitation items;\n * - encapsulated pixel data is written with undefined length, an empty\n * Basic Offset Table, one item per incoming fragment (odd fragments are\n * padded), and a sequence delimiter.\n *\n * Byte-identical round-tripping remains a non-goal (spec §4.5 / D15): output\n * is correct, semantically faithful Part 10, not a byte-for-byte copy of any\n * source.\n *\n * Not supported (throws): deflated transfer syntax, bulkDataReference events\n * (the bytes are elsewhere — materialize them first), sequences inside the\n * file meta group.\n */\nexport class StreamingPart10Writer extends EventStreamListener {\n /**\n * @param {Object} [options]\n * @param {(chunk: Uint8Array) => void} [options.onChunk] - Byte sink;\n * defaults to accumulating on `this.chunks`.\n * @param {Object} [options.writeOptions] - Forwarded to the element\n * encoders (e.g. { allowInvalidVRLength }).\n * @param {...Object} filters - Event-stream filters, as for any listener.\n */\n constructor(options = {}, ...filters) {\n super(...filters);\n this.chunks = [];\n this._onChunk = options.onChunk ?? (chunk => this.chunks.push(chunk));\n this._writeOptions = options.writeOptions ?? {\n allowInvalidVRLength: false\n };\n this.bytesWritten = 0;\n this._inMeta = false;\n this._meta = {};\n this._bodySyntax = EXPLICIT_LITTLE_ENDIAN;\n this._current = null;\n this._encapsulated = false;\n this.done = false;\n }\n\n /**\n * Endianness for every header the writer builds itself (sequence, item,\n * delimiter and encapsulated pixel-data headers). Review finding 5: these\n * were hardcoded little-endian while plain elements followed the body\n * syntax, so an Explicit VR Big Endian file disagreed with itself. File\n * Meta streams do NOT use this — the meta group is always explicit\n * little endian (PS3.10 §7.1).\n * @private\n */\n get _bodyLittleEndian() {\n return this._bodySyntax !== EXPLICIT_BIG_ENDIAN;\n }\n\n /** @param {ArrayBuffer|Uint8Array} bytes @private */\n _emit(bytes) {\n const chunk =\n bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);\n this.bytesWritten += chunk.byteLength;\n this._onChunk(chunk);\n }\n\n /** @private */\n _emitStream(stream) {\n this._emit(stream.getBuffer(0, stream.size));\n }\n\n /**\n * Writes a bare tag + 32-bit length, the form shared by item and\n * delimitation items (never a VR).\n * @private\n */\n _writeRawTag(stream, group, element, length) {\n stream.writeUint16(group);\n stream.writeUint16(element);\n stream.writeUint32(length);\n }\n\n /**\n * Writes an element header in the long (reserved + 32-bit length) form —\n * the only form needed for the headers this writer emits itself (SQ and\n * encapsulated OB/OW/UN); everything else goes through\n * core's writeTagObject.\n * @private\n */\n _writeLongHeader(stream, tag, vr, length) {\n stream.writeUint16(parseInt(tag.substring(0, 4), 16));\n stream.writeUint16(parseInt(tag.substring(4, 8), 16));\n if (this._bodySyntax !== IMPLICIT_LITTLE_ENDIAN) {\n stream.writeAsciiString(vr);\n stream.writeUint16(0);\n }\n stream.writeUint32(length);\n }\n\n _baseStartDataSet() {}\n\n _baseEndDataSet() {\n this.done = true;\n }\n\n _baseStartFileMetaInformation() {\n this._inMeta = true;\n const stream = new WriteBufferStream(160, true);\n stream.writeUint8Repeat(0, 128);\n stream.writeAsciiString(\"DICM\");\n this._emitStream(stream);\n }\n\n _baseEndFileMetaInformation() {\n this._inMeta = false;\n if (!this._meta[TRANSFER_SYNTAX_UID]) {\n this._meta[TRANSFER_SYNTAX_UID] = {\n vr: \"UI\",\n Value: [EXPLICIT_LITTLE_ENDIAN]\n };\n }\n this._bodySyntax = this._meta[TRANSFER_SYNTAX_UID].Value[0];\n if (this._bodySyntax === DEFLATED_EXPLICIT_LITTLE_ENDIAN) {\n throw new Error(\n \"StreamingPart10Writer does not support the deflated \" +\n \"transfer syntax; inflate the source or use Part10Writer\"\n );\n }\n // Group length must cover the encoded meta elements, so the group is\n // the one part of the file that cannot stream element-by-element.\n delete this._meta[FMI_GROUP_LENGTH];\n const metaStream = new WriteBufferStream(1024, true);\n writeDataSet(\n this._meta,\n metaStream,\n EXPLICIT_LITTLE_ENDIAN,\n this._writeOptions\n );\n const out = new WriteBufferStream(1024 + 16, true);\n writeTagObject(\n out,\n FMI_GROUP_LENGTH,\n \"UL\",\n metaStream.size,\n EXPLICIT_LITTLE_ENDIAN,\n this._writeOptions\n );\n out.concat(metaStream);\n this._emitStream(out);\n this._meta = {};\n }\n\n _baseStartElement(tag, info = {}) {\n this._current = { tag, vr: info.vr, values: [], emitted: false };\n }\n\n _baseValue(v) {\n this._current.values.push(v);\n }\n\n _baseEndElement() {\n const el = this._current;\n this._current = null;\n if (el.emitted) {\n return; // encapsulated path already streamed it\n }\n if (this._inMeta) {\n if (el.tag !== FMI_GROUP_LENGTH) {\n this._meta[el.tag] = { vr: el.vr, Value: el.values };\n }\n return;\n }\n const stream = new WriteBufferStream(256, this._bodyLittleEndian);\n writeTagObject(\n stream,\n el.tag,\n el.vr,\n el.values,\n this._bodySyntax,\n this._writeOptions\n );\n this._emitStream(stream);\n }\n\n _baseStartBinary(opts = {}) {\n if (opts.encapsulated && this._inMeta) {\n throw new Error(\n \"encapsulated binary is not legal in the file meta group\"\n );\n }\n if (!opts.encapsulated) {\n // Defined-length binary: fragments accumulate on the element and\n // endElement serializes it whole (bounded by that one element).\n this._encapsulated = false;\n return;\n }\n this._encapsulated = true;\n this._current.emitted = true;\n const stream = new WriteBufferStream(24, this._bodyLittleEndian);\n this._writeLongHeader(\n stream,\n this._current.tag,\n this._current.vr || \"OB\",\n UNDEFINED_LENGTH\n );\n // Empty Basic Offset Table: generators emit data fragments only (the\n // source table, if any, indexes source offsets that no longer hold).\n this._writeRawTag(stream, 0xfffe, 0xe000, 0);\n this._emitStream(stream);\n }\n\n _baseBinaryFragment(chunk) {\n const bytes =\n chunk instanceof Uint8Array\n ? chunk\n : chunk instanceof ArrayBuffer\n ? new Uint8Array(chunk)\n : new Uint8Array(\n chunk.buffer,\n chunk.byteOffset,\n chunk.byteLength\n );\n if (!this._encapsulated) {\n // Review finding 11: bytes.buffer is the WHOLE backing store, so\n // a subarray view would write (and retain) every byte of it.\n // Slice out the view's own window when they differ.\n this._current.values.push(\n bytes.byteOffset === 0 &&\n bytes.byteLength === bytes.buffer.byteLength\n ? bytes.buffer\n : bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength\n )\n );\n return;\n }\n const pad = bytes.byteLength % 2;\n const header = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(header, 0xfffe, 0xe000, bytes.byteLength + pad);\n this._emitStream(header);\n this._emit(bytes);\n if (pad) {\n this._emit(new Uint8Array(1));\n }\n }\n\n _baseEndBinary() {\n if (this._encapsulated) {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);\n this._emitStream(stream);\n this._encapsulated = false;\n }\n }\n\n _baseStartSequence(tag, info = {}) {\n if (this._inMeta) {\n throw new Error(\"sequences are not legal in the file meta group\");\n }\n // Undefined length streams without backpatching; items and the\n // delimiters below close it out (PS3.5 §7.5).\n const stream = new WriteBufferStream(16, this._bodyLittleEndian);\n this._writeLongHeader(stream, tag, info.vr || \"SQ\", UNDEFINED_LENGTH);\n this._emitStream(stream);\n }\n\n _baseStartItem() {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe000, UNDEFINED_LENGTH);\n this._emitStream(stream);\n }\n\n _baseEndItem() {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe00d, 0);\n this._emitStream(stream);\n }\n\n _baseEndSequence() {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);\n this._emitStream(stream);\n }\n\n _baseBulkDataReference(ref = {}) {\n throw new Error(\n \"StreamingPart10Writer cannot serialize a bulkDataReference \" +\n `(${ref.uri ?? \"no uri\"}); materialize bulk data before writing`\n );\n }\n\n /**\n * Testing convenience for the accumulate mode: the collected chunks as\n * one ArrayBuffer. Meaningless when onChunk was provided.\n * @returns {ArrayBuffer}\n */\n toArrayBuffer() {\n const total = this.chunks.reduce((n, c) => n + c.byteLength, 0);\n const out = new Uint8Array(total);\n let offset = 0;\n for (const chunk of this.chunks) {\n out.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return out.buffer;\n }\n}\n","import { encodeBase64 } from \"@dcmjs-org/core\";\nimport { EventStreamListener } from \"@dcmjs-org/parser\";\n\n/**\n * DicomWebJsonWriter — slice E1: an event-stream consumer that writes the\n * DICOM JSON model (DICOMweb metadata representation).\n *\n * The faithful inverse of `fromDicomWebJson`: it makes the contract a SINK as\n * well as a source, so the architecture round-trips\n * (DICOMweb JSON -> events -> DICOMweb JSON is identity) and any source can be\n * serialized to DICOMweb JSON (Part 10 -> events -> JSON).\n *\n * Output shape per tag: `{ vr, Value: [...] }`, or `{ vr, BulkDataURI }`, or\n * `{ vr, InlineBinary: base64 }`. Person Names pass through as the DICOMweb\n * `{ Alphabetic }` objects the contract carries. Binary source form is preserved\n * (§25): a `bulkDataReference` stays a `BulkDataURI`; assembled binary fragments\n * become base64 `InlineBinary`. Meta (group 0002) elements, when present, are\n * written flat alongside the dataset.\n */\nexport class DicomWebJsonWriter extends EventStreamListener {\n constructor(...filters) {\n super(...filters);\n this.result = {};\n // Stack of containers (the root object or a sequence item object) plus\n // the element/sequence currently being built.\n this._containers = [this.result];\n this._pending = null; // { tag, attr, fragments? }\n }\n\n _container() {\n return this._containers[this._containers.length - 1];\n }\n\n _baseStartDataSet() {\n this.result = {};\n this._containers = [this.result];\n this._pending = null;\n }\n\n _baseStartElement(tag, info = {}) {\n this._pending = { tag, attr: { vr: info.vr }, values: [] };\n }\n\n _baseValue(v, info) {\n this._pending.values.push(this._jsonModelValue(v, info));\n }\n\n /**\n * PS3.18 F.2.3.1: DS/IS may be encoded as JSON numbers OR strings.\n * Emit a number when the conversion is lossless (dcm4chee parity, #53);\n * fall back to the raw source string when Number() would silently lose\n * integer precision — e.g. DS/IS integers beyond 2^53 (#398). The raw\n * string is the standard's escape hatch; `_rawValue` itself never\n * appears in the JSON model (#404).\n */\n _jsonModelValue(v, info) {\n const vr = this._pending.attr.vr;\n if (\n (vr === \"DS\" || vr === \"IS\") &&\n info &&\n typeof info.rawValue === \"string\"\n ) {\n const raw = info.rawValue.trim();\n const parsed = Number(raw);\n if (\n /^[+-]?\\d+$/.test(raw) &&\n !Number.isSafeInteger(parsed) &&\n String(parsed) !== raw\n ) {\n return raw;\n }\n }\n return v;\n }\n\n _baseBulkDataReference(ref = {}) {\n this._pending.attr.BulkDataURI = ref.uri;\n this._pending.values = null; // bulk reference carries no Value\n }\n\n _baseStartBinary() {\n this._pending.fragments = [];\n this._pending.values = null;\n }\n\n _baseBinaryFragment(chunk) {\n this._pending.fragments.push(chunk);\n }\n\n _baseEndBinary() {\n this._pending.attr.InlineBinary = encodeBase64(\n concatFragments(this._pending.fragments)\n );\n }\n\n _baseEndElement() {\n const { tag, attr, values } = this._pending;\n if (values && values.length) {\n attr.Value = values;\n }\n this._container()[tag] = attr;\n this._pending = null;\n }\n\n _baseStartSequence(tag, info = {}) {\n const attr = { vr: info.vr, Value: [] };\n this._container()[tag] = attr;\n this._pending = null;\n // Items are pushed into attr.Value via a sequence marker on the stack.\n this._containers.push({ __seqValue: attr.Value });\n }\n\n _baseStartItem() {\n const item = {};\n this._container().__seqValue.push(item);\n this._containers.push(item);\n }\n\n _baseEndItem() {\n this._containers.pop();\n }\n\n _baseEndSequence() {\n this._containers.pop();\n }\n}\n\nfunction concatFragments(fragments) {\n // a view, or a buffer (ArrayBuffer or SharedArrayBuffer)\n const parts = fragments.map(f =>\n ArrayBuffer.isView(f)\n ? new Uint8Array(f.buffer, f.byteOffset, f.byteLength)\n : new Uint8Array(f)\n );\n const total = parts.reduce((n, p) => n + p.length, 0);\n const out = new Uint8Array(total);\n let off = 0;\n for (const p of parts) {\n out.set(p, off);\n off += p.length;\n }\n return out;\n}\n"],"names":["CollectorListener","writePart10","EventStreamListener","EXPLICIT_LITTLE_ENDIAN","EXPLICIT_BIG_ENDIAN","IMPLICIT_LITTLE_ENDIAN","WriteBufferStream","DEFLATED_EXPLICIT_LITTLE_ENDIAN","writeDataSet","writeTagObject","encodeBase64"],"mappings":";;;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,YAAY,SAASA,wBAAiB,CAAC;AACpD;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,YAAY,EAAE;AACxB,QAAQ,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;AAC5C;AACA;AACA,QAAQ,OAAO,IAAI,CAAC,UAAU,CAAC;;AAE/B,QAAQ,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;AACxD,QAAQ,OAAO;AACf,cAAcC,gBAAW,CAAC,OAAO,EAAE,YAAY;AAC/C,cAAcA,gBAAW,CAAC,OAAO,CAAC;AAClC,IAAI;AACJ;;AC3BA,MAAM,gBAAgB,GAAG,UAAU;AACnC,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,UAAU;AACjE,cAAc,IAAI,UAAU,CAAC,CAAC;AAC9B,KAAK;AACL,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACzD,IAAI,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC;AACrC,IAAI,IAAI,GAAG,GAAG,CAAC;AACf,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;AAC3B,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;AACvB,QAAQ,GAAG,IAAI,CAAC,CAAC,MAAM;AACvB,IAAI;AACJ,IAAI,OAAO,GAAG;AACd;;;;;;"}
package/dist/index.mjs ADDED
@@ -0,0 +1,511 @@
1
+ import { CollectorListener, EventStreamListener } from '@dcmjs-org/parser';
2
+ import { writePart10, EXPLICIT_LITTLE_ENDIAN, EXPLICIT_BIG_ENDIAN, IMPLICIT_LITTLE_ENDIAN, WriteBufferStream, DEFLATED_EXPLICIT_LITTLE_ENDIAN, writeDataSet, writeTagObject, encodeBase64 } from '@dcmjs-org/core';
3
+
4
+ /**
5
+ * Part10Writer — slice E2: an event-stream sink that produces DICOM Part 10
6
+ * bytes.
7
+ *
8
+ * Architecture: this is a thin LAYER over the canonical encoder, not a second
9
+ * encoder. It collects the event stream into a tag-keyed `{ meta, dict }` tree
10
+ * (reusing CollectorListener) and delegates serialization to core's
11
+ * `writePart10` (the proven Part 10 envelope, relocated from legacy
12
+ * `DicomDict.write()`), which handles every VR, undefined-length sequences,
13
+ * deflate, padding, Big16, and FileMetaInformationGroupLength recomputation.
14
+ * This closed the one temporary `@dcmjs-org/legacy` edge this package had.
15
+ *
16
+ * Byte-IDENTICAL Part 10 round-tripping (incl. re-emitting compressed pixel data
17
+ * verbatim) is intentionally NOT this path's job — that is a non-goal of the
18
+ * naturalized/event layer (spec §4.5) and remains served by the lazy-read +
19
+ * R4 passthrough-write path. This writer produces correct, semantically faithful
20
+ * Part 10 output from any event source.
21
+ */
22
+ class Part10Writer extends CollectorListener {
23
+ /**
24
+ * Serialize the collected dataset to a Part 10 ArrayBuffer.
25
+ * @param {Object} [writeOptions] forwarded to writePart10
26
+ * @returns {ArrayBuffer}
27
+ */
28
+ write(writeOptions) {
29
+ const meta = { ...this.result.meta };
30
+ // writePart10 recomputes the group length; drop any collected one so
31
+ // it is not double-counted.
32
+ delete meta["00020000"];
33
+
34
+ const dataSet = { meta, dict: this.result.dict };
35
+ return writeOptions
36
+ ? writePart10(dataSet, writeOptions)
37
+ : writePart10(dataSet);
38
+ }
39
+ }
40
+
41
+ const FMI_GROUP_LENGTH = "00020000";
42
+ const TRANSFER_SYNTAX_UID = "00020010";
43
+ const UNDEFINED_LENGTH = 0xffffffff;
44
+
45
+ /**
46
+ * StreamingPart10Writer — plan-R2: an event-stream sink that emits DICOM
47
+ * Part 10 bytes incrementally, as events arrive, instead of collecting the
48
+ * whole dataset first like {@link Part10Writer}.
49
+ *
50
+ * Purpose: writing datasets whose Pixel Data does not fit in memory (the
51
+ * R2 trigger — e.g. a Supplement 225 fragmentable video instance measured in
52
+ * tens of GB). Peak memory is bounded by the largest single non-encapsulated
53
+ * element plus the file meta group; encapsulated pixel-data fragments are
54
+ * forwarded chunk-for-chunk and never accumulated.
55
+ *
56
+ * Output contract: `options.onChunk(Uint8Array)` is called zero or more times
57
+ * per event, in file order. Absent `onChunk`, chunks accumulate on
58
+ * `this.chunks` (testing convenience; that mode is NOT streaming). The caller
59
+ * owns backpressure: wire the generator's `setDrain` to the sink that
60
+ * consumes the chunks (e.g. a Node fs write stream's own drain).
61
+ *
62
+ * Encoding decisions (all legal Part 10, all chosen to avoid backpatching):
63
+ * - the file meta group is buffered — it is small and its group length
64
+ * (0002,0000) must be computed over the encoded elements, exactly as
65
+ * DicomDict.write does;
66
+ * - sequences and their items are written with undefined length and closed
67
+ * with item/sequence delimitation items;
68
+ * - encapsulated pixel data is written with undefined length, an empty
69
+ * Basic Offset Table, one item per incoming fragment (odd fragments are
70
+ * padded), and a sequence delimiter.
71
+ *
72
+ * Byte-identical round-tripping remains a non-goal (spec §4.5 / D15): output
73
+ * is correct, semantically faithful Part 10, not a byte-for-byte copy of any
74
+ * source.
75
+ *
76
+ * Not supported (throws): deflated transfer syntax, bulkDataReference events
77
+ * (the bytes are elsewhere — materialize them first), sequences inside the
78
+ * file meta group.
79
+ */
80
+ class StreamingPart10Writer extends EventStreamListener {
81
+ /**
82
+ * @param {Object} [options]
83
+ * @param {(chunk: Uint8Array) => void} [options.onChunk] - Byte sink;
84
+ * defaults to accumulating on `this.chunks`.
85
+ * @param {Object} [options.writeOptions] - Forwarded to the element
86
+ * encoders (e.g. { allowInvalidVRLength }).
87
+ * @param {...Object} filters - Event-stream filters, as for any listener.
88
+ */
89
+ constructor(options = {}, ...filters) {
90
+ super(...filters);
91
+ this.chunks = [];
92
+ this._onChunk = options.onChunk ?? (chunk => this.chunks.push(chunk));
93
+ this._writeOptions = options.writeOptions ?? {
94
+ allowInvalidVRLength: false
95
+ };
96
+ this.bytesWritten = 0;
97
+ this._inMeta = false;
98
+ this._meta = {};
99
+ this._bodySyntax = EXPLICIT_LITTLE_ENDIAN;
100
+ this._current = null;
101
+ this._encapsulated = false;
102
+ this.done = false;
103
+ }
104
+
105
+ /**
106
+ * Endianness for every header the writer builds itself (sequence, item,
107
+ * delimiter and encapsulated pixel-data headers). Review finding 5: these
108
+ * were hardcoded little-endian while plain elements followed the body
109
+ * syntax, so an Explicit VR Big Endian file disagreed with itself. File
110
+ * Meta streams do NOT use this — the meta group is always explicit
111
+ * little endian (PS3.10 §7.1).
112
+ * @private
113
+ */
114
+ get _bodyLittleEndian() {
115
+ return this._bodySyntax !== EXPLICIT_BIG_ENDIAN;
116
+ }
117
+
118
+ /** @param {ArrayBuffer|Uint8Array} bytes @private */
119
+ _emit(bytes) {
120
+ const chunk =
121
+ bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
122
+ this.bytesWritten += chunk.byteLength;
123
+ this._onChunk(chunk);
124
+ }
125
+
126
+ /** @private */
127
+ _emitStream(stream) {
128
+ this._emit(stream.getBuffer(0, stream.size));
129
+ }
130
+
131
+ /**
132
+ * Writes a bare tag + 32-bit length, the form shared by item and
133
+ * delimitation items (never a VR).
134
+ * @private
135
+ */
136
+ _writeRawTag(stream, group, element, length) {
137
+ stream.writeUint16(group);
138
+ stream.writeUint16(element);
139
+ stream.writeUint32(length);
140
+ }
141
+
142
+ /**
143
+ * Writes an element header in the long (reserved + 32-bit length) form —
144
+ * the only form needed for the headers this writer emits itself (SQ and
145
+ * encapsulated OB/OW/UN); everything else goes through
146
+ * core's writeTagObject.
147
+ * @private
148
+ */
149
+ _writeLongHeader(stream, tag, vr, length) {
150
+ stream.writeUint16(parseInt(tag.substring(0, 4), 16));
151
+ stream.writeUint16(parseInt(tag.substring(4, 8), 16));
152
+ if (this._bodySyntax !== IMPLICIT_LITTLE_ENDIAN) {
153
+ stream.writeAsciiString(vr);
154
+ stream.writeUint16(0);
155
+ }
156
+ stream.writeUint32(length);
157
+ }
158
+
159
+ _baseStartDataSet() {}
160
+
161
+ _baseEndDataSet() {
162
+ this.done = true;
163
+ }
164
+
165
+ _baseStartFileMetaInformation() {
166
+ this._inMeta = true;
167
+ const stream = new WriteBufferStream(160, true);
168
+ stream.writeUint8Repeat(0, 128);
169
+ stream.writeAsciiString("DICM");
170
+ this._emitStream(stream);
171
+ }
172
+
173
+ _baseEndFileMetaInformation() {
174
+ this._inMeta = false;
175
+ if (!this._meta[TRANSFER_SYNTAX_UID]) {
176
+ this._meta[TRANSFER_SYNTAX_UID] = {
177
+ vr: "UI",
178
+ Value: [EXPLICIT_LITTLE_ENDIAN]
179
+ };
180
+ }
181
+ this._bodySyntax = this._meta[TRANSFER_SYNTAX_UID].Value[0];
182
+ if (this._bodySyntax === DEFLATED_EXPLICIT_LITTLE_ENDIAN) {
183
+ throw new Error(
184
+ "StreamingPart10Writer does not support the deflated " +
185
+ "transfer syntax; inflate the source or use Part10Writer"
186
+ );
187
+ }
188
+ // Group length must cover the encoded meta elements, so the group is
189
+ // the one part of the file that cannot stream element-by-element.
190
+ delete this._meta[FMI_GROUP_LENGTH];
191
+ const metaStream = new WriteBufferStream(1024, true);
192
+ writeDataSet(
193
+ this._meta,
194
+ metaStream,
195
+ EXPLICIT_LITTLE_ENDIAN,
196
+ this._writeOptions
197
+ );
198
+ const out = new WriteBufferStream(1024 + 16, true);
199
+ writeTagObject(
200
+ out,
201
+ FMI_GROUP_LENGTH,
202
+ "UL",
203
+ metaStream.size,
204
+ EXPLICIT_LITTLE_ENDIAN,
205
+ this._writeOptions
206
+ );
207
+ out.concat(metaStream);
208
+ this._emitStream(out);
209
+ this._meta = {};
210
+ }
211
+
212
+ _baseStartElement(tag, info = {}) {
213
+ this._current = { tag, vr: info.vr, values: [], emitted: false };
214
+ }
215
+
216
+ _baseValue(v) {
217
+ this._current.values.push(v);
218
+ }
219
+
220
+ _baseEndElement() {
221
+ const el = this._current;
222
+ this._current = null;
223
+ if (el.emitted) {
224
+ return; // encapsulated path already streamed it
225
+ }
226
+ if (this._inMeta) {
227
+ if (el.tag !== FMI_GROUP_LENGTH) {
228
+ this._meta[el.tag] = { vr: el.vr, Value: el.values };
229
+ }
230
+ return;
231
+ }
232
+ const stream = new WriteBufferStream(256, this._bodyLittleEndian);
233
+ writeTagObject(
234
+ stream,
235
+ el.tag,
236
+ el.vr,
237
+ el.values,
238
+ this._bodySyntax,
239
+ this._writeOptions
240
+ );
241
+ this._emitStream(stream);
242
+ }
243
+
244
+ _baseStartBinary(opts = {}) {
245
+ if (opts.encapsulated && this._inMeta) {
246
+ throw new Error(
247
+ "encapsulated binary is not legal in the file meta group"
248
+ );
249
+ }
250
+ if (!opts.encapsulated) {
251
+ // Defined-length binary: fragments accumulate on the element and
252
+ // endElement serializes it whole (bounded by that one element).
253
+ this._encapsulated = false;
254
+ return;
255
+ }
256
+ this._encapsulated = true;
257
+ this._current.emitted = true;
258
+ const stream = new WriteBufferStream(24, this._bodyLittleEndian);
259
+ this._writeLongHeader(
260
+ stream,
261
+ this._current.tag,
262
+ this._current.vr || "OB",
263
+ UNDEFINED_LENGTH
264
+ );
265
+ // Empty Basic Offset Table: generators emit data fragments only (the
266
+ // source table, if any, indexes source offsets that no longer hold).
267
+ this._writeRawTag(stream, 0xfffe, 0xe000, 0);
268
+ this._emitStream(stream);
269
+ }
270
+
271
+ _baseBinaryFragment(chunk) {
272
+ const bytes =
273
+ chunk instanceof Uint8Array
274
+ ? chunk
275
+ : chunk instanceof ArrayBuffer
276
+ ? new Uint8Array(chunk)
277
+ : new Uint8Array(
278
+ chunk.buffer,
279
+ chunk.byteOffset,
280
+ chunk.byteLength
281
+ );
282
+ if (!this._encapsulated) {
283
+ // Review finding 11: bytes.buffer is the WHOLE backing store, so
284
+ // a subarray view would write (and retain) every byte of it.
285
+ // Slice out the view's own window when they differ.
286
+ this._current.values.push(
287
+ bytes.byteOffset === 0 &&
288
+ bytes.byteLength === bytes.buffer.byteLength
289
+ ? bytes.buffer
290
+ : bytes.buffer.slice(
291
+ bytes.byteOffset,
292
+ bytes.byteOffset + bytes.byteLength
293
+ )
294
+ );
295
+ return;
296
+ }
297
+ const pad = bytes.byteLength % 2;
298
+ const header = new WriteBufferStream(8, this._bodyLittleEndian);
299
+ this._writeRawTag(header, 0xfffe, 0xe000, bytes.byteLength + pad);
300
+ this._emitStream(header);
301
+ this._emit(bytes);
302
+ if (pad) {
303
+ this._emit(new Uint8Array(1));
304
+ }
305
+ }
306
+
307
+ _baseEndBinary() {
308
+ if (this._encapsulated) {
309
+ const stream = new WriteBufferStream(8, this._bodyLittleEndian);
310
+ this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);
311
+ this._emitStream(stream);
312
+ this._encapsulated = false;
313
+ }
314
+ }
315
+
316
+ _baseStartSequence(tag, info = {}) {
317
+ if (this._inMeta) {
318
+ throw new Error("sequences are not legal in the file meta group");
319
+ }
320
+ // Undefined length streams without backpatching; items and the
321
+ // delimiters below close it out (PS3.5 §7.5).
322
+ const stream = new WriteBufferStream(16, this._bodyLittleEndian);
323
+ this._writeLongHeader(stream, tag, info.vr || "SQ", UNDEFINED_LENGTH);
324
+ this._emitStream(stream);
325
+ }
326
+
327
+ _baseStartItem() {
328
+ const stream = new WriteBufferStream(8, this._bodyLittleEndian);
329
+ this._writeRawTag(stream, 0xfffe, 0xe000, UNDEFINED_LENGTH);
330
+ this._emitStream(stream);
331
+ }
332
+
333
+ _baseEndItem() {
334
+ const stream = new WriteBufferStream(8, this._bodyLittleEndian);
335
+ this._writeRawTag(stream, 0xfffe, 0xe00d, 0);
336
+ this._emitStream(stream);
337
+ }
338
+
339
+ _baseEndSequence() {
340
+ const stream = new WriteBufferStream(8, this._bodyLittleEndian);
341
+ this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);
342
+ this._emitStream(stream);
343
+ }
344
+
345
+ _baseBulkDataReference(ref = {}) {
346
+ throw new Error(
347
+ "StreamingPart10Writer cannot serialize a bulkDataReference " +
348
+ `(${ref.uri ?? "no uri"}); materialize bulk data before writing`
349
+ );
350
+ }
351
+
352
+ /**
353
+ * Testing convenience for the accumulate mode: the collected chunks as
354
+ * one ArrayBuffer. Meaningless when onChunk was provided.
355
+ * @returns {ArrayBuffer}
356
+ */
357
+ toArrayBuffer() {
358
+ const total = this.chunks.reduce((n, c) => n + c.byteLength, 0);
359
+ const out = new Uint8Array(total);
360
+ let offset = 0;
361
+ for (const chunk of this.chunks) {
362
+ out.set(chunk, offset);
363
+ offset += chunk.byteLength;
364
+ }
365
+ return out.buffer;
366
+ }
367
+ }
368
+
369
+ /**
370
+ * DicomWebJsonWriter — slice E1: an event-stream consumer that writes the
371
+ * DICOM JSON model (DICOMweb metadata representation).
372
+ *
373
+ * The faithful inverse of `fromDicomWebJson`: it makes the contract a SINK as
374
+ * well as a source, so the architecture round-trips
375
+ * (DICOMweb JSON -> events -> DICOMweb JSON is identity) and any source can be
376
+ * serialized to DICOMweb JSON (Part 10 -> events -> JSON).
377
+ *
378
+ * Output shape per tag: `{ vr, Value: [...] }`, or `{ vr, BulkDataURI }`, or
379
+ * `{ vr, InlineBinary: base64 }`. Person Names pass through as the DICOMweb
380
+ * `{ Alphabetic }` objects the contract carries. Binary source form is preserved
381
+ * (§25): a `bulkDataReference` stays a `BulkDataURI`; assembled binary fragments
382
+ * become base64 `InlineBinary`. Meta (group 0002) elements, when present, are
383
+ * written flat alongside the dataset.
384
+ */
385
+ class DicomWebJsonWriter extends EventStreamListener {
386
+ constructor(...filters) {
387
+ super(...filters);
388
+ this.result = {};
389
+ // Stack of containers (the root object or a sequence item object) plus
390
+ // the element/sequence currently being built.
391
+ this._containers = [this.result];
392
+ this._pending = null; // { tag, attr, fragments? }
393
+ }
394
+
395
+ _container() {
396
+ return this._containers[this._containers.length - 1];
397
+ }
398
+
399
+ _baseStartDataSet() {
400
+ this.result = {};
401
+ this._containers = [this.result];
402
+ this._pending = null;
403
+ }
404
+
405
+ _baseStartElement(tag, info = {}) {
406
+ this._pending = { tag, attr: { vr: info.vr }, values: [] };
407
+ }
408
+
409
+ _baseValue(v, info) {
410
+ this._pending.values.push(this._jsonModelValue(v, info));
411
+ }
412
+
413
+ /**
414
+ * PS3.18 F.2.3.1: DS/IS may be encoded as JSON numbers OR strings.
415
+ * Emit a number when the conversion is lossless (dcm4chee parity, #53);
416
+ * fall back to the raw source string when Number() would silently lose
417
+ * integer precision — e.g. DS/IS integers beyond 2^53 (#398). The raw
418
+ * string is the standard's escape hatch; `_rawValue` itself never
419
+ * appears in the JSON model (#404).
420
+ */
421
+ _jsonModelValue(v, info) {
422
+ const vr = this._pending.attr.vr;
423
+ if (
424
+ (vr === "DS" || vr === "IS") &&
425
+ info &&
426
+ typeof info.rawValue === "string"
427
+ ) {
428
+ const raw = info.rawValue.trim();
429
+ const parsed = Number(raw);
430
+ if (
431
+ /^[+-]?\d+$/.test(raw) &&
432
+ !Number.isSafeInteger(parsed) &&
433
+ String(parsed) !== raw
434
+ ) {
435
+ return raw;
436
+ }
437
+ }
438
+ return v;
439
+ }
440
+
441
+ _baseBulkDataReference(ref = {}) {
442
+ this._pending.attr.BulkDataURI = ref.uri;
443
+ this._pending.values = null; // bulk reference carries no Value
444
+ }
445
+
446
+ _baseStartBinary() {
447
+ this._pending.fragments = [];
448
+ this._pending.values = null;
449
+ }
450
+
451
+ _baseBinaryFragment(chunk) {
452
+ this._pending.fragments.push(chunk);
453
+ }
454
+
455
+ _baseEndBinary() {
456
+ this._pending.attr.InlineBinary = encodeBase64(
457
+ concatFragments(this._pending.fragments)
458
+ );
459
+ }
460
+
461
+ _baseEndElement() {
462
+ const { tag, attr, values } = this._pending;
463
+ if (values && values.length) {
464
+ attr.Value = values;
465
+ }
466
+ this._container()[tag] = attr;
467
+ this._pending = null;
468
+ }
469
+
470
+ _baseStartSequence(tag, info = {}) {
471
+ const attr = { vr: info.vr, Value: [] };
472
+ this._container()[tag] = attr;
473
+ this._pending = null;
474
+ // Items are pushed into attr.Value via a sequence marker on the stack.
475
+ this._containers.push({ __seqValue: attr.Value });
476
+ }
477
+
478
+ _baseStartItem() {
479
+ const item = {};
480
+ this._container().__seqValue.push(item);
481
+ this._containers.push(item);
482
+ }
483
+
484
+ _baseEndItem() {
485
+ this._containers.pop();
486
+ }
487
+
488
+ _baseEndSequence() {
489
+ this._containers.pop();
490
+ }
491
+ }
492
+
493
+ function concatFragments(fragments) {
494
+ // a view, or a buffer (ArrayBuffer or SharedArrayBuffer)
495
+ const parts = fragments.map(f =>
496
+ ArrayBuffer.isView(f)
497
+ ? new Uint8Array(f.buffer, f.byteOffset, f.byteLength)
498
+ : new Uint8Array(f)
499
+ );
500
+ const total = parts.reduce((n, p) => n + p.length, 0);
501
+ const out = new Uint8Array(total);
502
+ let off = 0;
503
+ for (const p of parts) {
504
+ out.set(p, off);
505
+ off += p.length;
506
+ }
507
+ return out;
508
+ }
509
+
510
+ export { DicomWebJsonWriter, Part10Writer, StreamingPart10Writer };
511
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/eventStream/Part10Writer.js","../src/eventStream/StreamingPart10Writer.js","../src/eventStream/DicomWebJsonWriter.js"],"sourcesContent":["import { CollectorListener } from \"@dcmjs-org/parser\";\nimport { writePart10 } from \"@dcmjs-org/core\";\n\n/**\n * Part10Writer — slice E2: an event-stream sink that produces DICOM Part 10\n * bytes.\n *\n * Architecture: this is a thin LAYER over the canonical encoder, not a second\n * encoder. It collects the event stream into a tag-keyed `{ meta, dict }` tree\n * (reusing CollectorListener) and delegates serialization to core's\n * `writePart10` (the proven Part 10 envelope, relocated from legacy\n * `DicomDict.write()`), which handles every VR, undefined-length sequences,\n * deflate, padding, Big16, and FileMetaInformationGroupLength recomputation.\n * This closed the one temporary `@dcmjs-org/legacy` edge this package had.\n *\n * Byte-IDENTICAL Part 10 round-tripping (incl. re-emitting compressed pixel data\n * verbatim) is intentionally NOT this path's job — that is a non-goal of the\n * naturalized/event layer (spec §4.5) and remains served by the lazy-read +\n * R4 passthrough-write path. This writer produces correct, semantically faithful\n * Part 10 output from any event source.\n */\nexport class Part10Writer extends CollectorListener {\n /**\n * Serialize the collected dataset to a Part 10 ArrayBuffer.\n * @param {Object} [writeOptions] forwarded to writePart10\n * @returns {ArrayBuffer}\n */\n write(writeOptions) {\n const meta = { ...this.result.meta };\n // writePart10 recomputes the group length; drop any collected one so\n // it is not double-counted.\n delete meta[\"00020000\"];\n\n const dataSet = { meta, dict: this.result.dict };\n return writeOptions\n ? writePart10(dataSet, writeOptions)\n : writePart10(dataSet);\n }\n}\n","import { EventStreamListener } from \"@dcmjs-org/parser\";\nimport {\n WriteBufferStream,\n EXPLICIT_BIG_ENDIAN,\n EXPLICIT_LITTLE_ENDIAN,\n IMPLICIT_LITTLE_ENDIAN,\n DEFLATED_EXPLICIT_LITTLE_ENDIAN,\n writeDataSet,\n writeTagObject\n} from \"@dcmjs-org/core\";\n\nconst FMI_GROUP_LENGTH = \"00020000\";\nconst TRANSFER_SYNTAX_UID = \"00020010\";\nconst UNDEFINED_LENGTH = 0xffffffff;\n\n/**\n * StreamingPart10Writer — plan-R2: an event-stream sink that emits DICOM\n * Part 10 bytes incrementally, as events arrive, instead of collecting the\n * whole dataset first like {@link Part10Writer}.\n *\n * Purpose: writing datasets whose Pixel Data does not fit in memory (the\n * R2 trigger — e.g. a Supplement 225 fragmentable video instance measured in\n * tens of GB). Peak memory is bounded by the largest single non-encapsulated\n * element plus the file meta group; encapsulated pixel-data fragments are\n * forwarded chunk-for-chunk and never accumulated.\n *\n * Output contract: `options.onChunk(Uint8Array)` is called zero or more times\n * per event, in file order. Absent `onChunk`, chunks accumulate on\n * `this.chunks` (testing convenience; that mode is NOT streaming). The caller\n * owns backpressure: wire the generator's `setDrain` to the sink that\n * consumes the chunks (e.g. a Node fs write stream's own drain).\n *\n * Encoding decisions (all legal Part 10, all chosen to avoid backpatching):\n * - the file meta group is buffered — it is small and its group length\n * (0002,0000) must be computed over the encoded elements, exactly as\n * DicomDict.write does;\n * - sequences and their items are written with undefined length and closed\n * with item/sequence delimitation items;\n * - encapsulated pixel data is written with undefined length, an empty\n * Basic Offset Table, one item per incoming fragment (odd fragments are\n * padded), and a sequence delimiter.\n *\n * Byte-identical round-tripping remains a non-goal (spec §4.5 / D15): output\n * is correct, semantically faithful Part 10, not a byte-for-byte copy of any\n * source.\n *\n * Not supported (throws): deflated transfer syntax, bulkDataReference events\n * (the bytes are elsewhere — materialize them first), sequences inside the\n * file meta group.\n */\nexport class StreamingPart10Writer extends EventStreamListener {\n /**\n * @param {Object} [options]\n * @param {(chunk: Uint8Array) => void} [options.onChunk] - Byte sink;\n * defaults to accumulating on `this.chunks`.\n * @param {Object} [options.writeOptions] - Forwarded to the element\n * encoders (e.g. { allowInvalidVRLength }).\n * @param {...Object} filters - Event-stream filters, as for any listener.\n */\n constructor(options = {}, ...filters) {\n super(...filters);\n this.chunks = [];\n this._onChunk = options.onChunk ?? (chunk => this.chunks.push(chunk));\n this._writeOptions = options.writeOptions ?? {\n allowInvalidVRLength: false\n };\n this.bytesWritten = 0;\n this._inMeta = false;\n this._meta = {};\n this._bodySyntax = EXPLICIT_LITTLE_ENDIAN;\n this._current = null;\n this._encapsulated = false;\n this.done = false;\n }\n\n /**\n * Endianness for every header the writer builds itself (sequence, item,\n * delimiter and encapsulated pixel-data headers). Review finding 5: these\n * were hardcoded little-endian while plain elements followed the body\n * syntax, so an Explicit VR Big Endian file disagreed with itself. File\n * Meta streams do NOT use this — the meta group is always explicit\n * little endian (PS3.10 §7.1).\n * @private\n */\n get _bodyLittleEndian() {\n return this._bodySyntax !== EXPLICIT_BIG_ENDIAN;\n }\n\n /** @param {ArrayBuffer|Uint8Array} bytes @private */\n _emit(bytes) {\n const chunk =\n bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);\n this.bytesWritten += chunk.byteLength;\n this._onChunk(chunk);\n }\n\n /** @private */\n _emitStream(stream) {\n this._emit(stream.getBuffer(0, stream.size));\n }\n\n /**\n * Writes a bare tag + 32-bit length, the form shared by item and\n * delimitation items (never a VR).\n * @private\n */\n _writeRawTag(stream, group, element, length) {\n stream.writeUint16(group);\n stream.writeUint16(element);\n stream.writeUint32(length);\n }\n\n /**\n * Writes an element header in the long (reserved + 32-bit length) form —\n * the only form needed for the headers this writer emits itself (SQ and\n * encapsulated OB/OW/UN); everything else goes through\n * core's writeTagObject.\n * @private\n */\n _writeLongHeader(stream, tag, vr, length) {\n stream.writeUint16(parseInt(tag.substring(0, 4), 16));\n stream.writeUint16(parseInt(tag.substring(4, 8), 16));\n if (this._bodySyntax !== IMPLICIT_LITTLE_ENDIAN) {\n stream.writeAsciiString(vr);\n stream.writeUint16(0);\n }\n stream.writeUint32(length);\n }\n\n _baseStartDataSet() {}\n\n _baseEndDataSet() {\n this.done = true;\n }\n\n _baseStartFileMetaInformation() {\n this._inMeta = true;\n const stream = new WriteBufferStream(160, true);\n stream.writeUint8Repeat(0, 128);\n stream.writeAsciiString(\"DICM\");\n this._emitStream(stream);\n }\n\n _baseEndFileMetaInformation() {\n this._inMeta = false;\n if (!this._meta[TRANSFER_SYNTAX_UID]) {\n this._meta[TRANSFER_SYNTAX_UID] = {\n vr: \"UI\",\n Value: [EXPLICIT_LITTLE_ENDIAN]\n };\n }\n this._bodySyntax = this._meta[TRANSFER_SYNTAX_UID].Value[0];\n if (this._bodySyntax === DEFLATED_EXPLICIT_LITTLE_ENDIAN) {\n throw new Error(\n \"StreamingPart10Writer does not support the deflated \" +\n \"transfer syntax; inflate the source or use Part10Writer\"\n );\n }\n // Group length must cover the encoded meta elements, so the group is\n // the one part of the file that cannot stream element-by-element.\n delete this._meta[FMI_GROUP_LENGTH];\n const metaStream = new WriteBufferStream(1024, true);\n writeDataSet(\n this._meta,\n metaStream,\n EXPLICIT_LITTLE_ENDIAN,\n this._writeOptions\n );\n const out = new WriteBufferStream(1024 + 16, true);\n writeTagObject(\n out,\n FMI_GROUP_LENGTH,\n \"UL\",\n metaStream.size,\n EXPLICIT_LITTLE_ENDIAN,\n this._writeOptions\n );\n out.concat(metaStream);\n this._emitStream(out);\n this._meta = {};\n }\n\n _baseStartElement(tag, info = {}) {\n this._current = { tag, vr: info.vr, values: [], emitted: false };\n }\n\n _baseValue(v) {\n this._current.values.push(v);\n }\n\n _baseEndElement() {\n const el = this._current;\n this._current = null;\n if (el.emitted) {\n return; // encapsulated path already streamed it\n }\n if (this._inMeta) {\n if (el.tag !== FMI_GROUP_LENGTH) {\n this._meta[el.tag] = { vr: el.vr, Value: el.values };\n }\n return;\n }\n const stream = new WriteBufferStream(256, this._bodyLittleEndian);\n writeTagObject(\n stream,\n el.tag,\n el.vr,\n el.values,\n this._bodySyntax,\n this._writeOptions\n );\n this._emitStream(stream);\n }\n\n _baseStartBinary(opts = {}) {\n if (opts.encapsulated && this._inMeta) {\n throw new Error(\n \"encapsulated binary is not legal in the file meta group\"\n );\n }\n if (!opts.encapsulated) {\n // Defined-length binary: fragments accumulate on the element and\n // endElement serializes it whole (bounded by that one element).\n this._encapsulated = false;\n return;\n }\n this._encapsulated = true;\n this._current.emitted = true;\n const stream = new WriteBufferStream(24, this._bodyLittleEndian);\n this._writeLongHeader(\n stream,\n this._current.tag,\n this._current.vr || \"OB\",\n UNDEFINED_LENGTH\n );\n // Empty Basic Offset Table: generators emit data fragments only (the\n // source table, if any, indexes source offsets that no longer hold).\n this._writeRawTag(stream, 0xfffe, 0xe000, 0);\n this._emitStream(stream);\n }\n\n _baseBinaryFragment(chunk) {\n const bytes =\n chunk instanceof Uint8Array\n ? chunk\n : chunk instanceof ArrayBuffer\n ? new Uint8Array(chunk)\n : new Uint8Array(\n chunk.buffer,\n chunk.byteOffset,\n chunk.byteLength\n );\n if (!this._encapsulated) {\n // Review finding 11: bytes.buffer is the WHOLE backing store, so\n // a subarray view would write (and retain) every byte of it.\n // Slice out the view's own window when they differ.\n this._current.values.push(\n bytes.byteOffset === 0 &&\n bytes.byteLength === bytes.buffer.byteLength\n ? bytes.buffer\n : bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength\n )\n );\n return;\n }\n const pad = bytes.byteLength % 2;\n const header = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(header, 0xfffe, 0xe000, bytes.byteLength + pad);\n this._emitStream(header);\n this._emit(bytes);\n if (pad) {\n this._emit(new Uint8Array(1));\n }\n }\n\n _baseEndBinary() {\n if (this._encapsulated) {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);\n this._emitStream(stream);\n this._encapsulated = false;\n }\n }\n\n _baseStartSequence(tag, info = {}) {\n if (this._inMeta) {\n throw new Error(\"sequences are not legal in the file meta group\");\n }\n // Undefined length streams without backpatching; items and the\n // delimiters below close it out (PS3.5 §7.5).\n const stream = new WriteBufferStream(16, this._bodyLittleEndian);\n this._writeLongHeader(stream, tag, info.vr || \"SQ\", UNDEFINED_LENGTH);\n this._emitStream(stream);\n }\n\n _baseStartItem() {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe000, UNDEFINED_LENGTH);\n this._emitStream(stream);\n }\n\n _baseEndItem() {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe00d, 0);\n this._emitStream(stream);\n }\n\n _baseEndSequence() {\n const stream = new WriteBufferStream(8, this._bodyLittleEndian);\n this._writeRawTag(stream, 0xfffe, 0xe0dd, 0);\n this._emitStream(stream);\n }\n\n _baseBulkDataReference(ref = {}) {\n throw new Error(\n \"StreamingPart10Writer cannot serialize a bulkDataReference \" +\n `(${ref.uri ?? \"no uri\"}); materialize bulk data before writing`\n );\n }\n\n /**\n * Testing convenience for the accumulate mode: the collected chunks as\n * one ArrayBuffer. Meaningless when onChunk was provided.\n * @returns {ArrayBuffer}\n */\n toArrayBuffer() {\n const total = this.chunks.reduce((n, c) => n + c.byteLength, 0);\n const out = new Uint8Array(total);\n let offset = 0;\n for (const chunk of this.chunks) {\n out.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return out.buffer;\n }\n}\n","import { encodeBase64 } from \"@dcmjs-org/core\";\nimport { EventStreamListener } from \"@dcmjs-org/parser\";\n\n/**\n * DicomWebJsonWriter — slice E1: an event-stream consumer that writes the\n * DICOM JSON model (DICOMweb metadata representation).\n *\n * The faithful inverse of `fromDicomWebJson`: it makes the contract a SINK as\n * well as a source, so the architecture round-trips\n * (DICOMweb JSON -> events -> DICOMweb JSON is identity) and any source can be\n * serialized to DICOMweb JSON (Part 10 -> events -> JSON).\n *\n * Output shape per tag: `{ vr, Value: [...] }`, or `{ vr, BulkDataURI }`, or\n * `{ vr, InlineBinary: base64 }`. Person Names pass through as the DICOMweb\n * `{ Alphabetic }` objects the contract carries. Binary source form is preserved\n * (§25): a `bulkDataReference` stays a `BulkDataURI`; assembled binary fragments\n * become base64 `InlineBinary`. Meta (group 0002) elements, when present, are\n * written flat alongside the dataset.\n */\nexport class DicomWebJsonWriter extends EventStreamListener {\n constructor(...filters) {\n super(...filters);\n this.result = {};\n // Stack of containers (the root object or a sequence item object) plus\n // the element/sequence currently being built.\n this._containers = [this.result];\n this._pending = null; // { tag, attr, fragments? }\n }\n\n _container() {\n return this._containers[this._containers.length - 1];\n }\n\n _baseStartDataSet() {\n this.result = {};\n this._containers = [this.result];\n this._pending = null;\n }\n\n _baseStartElement(tag, info = {}) {\n this._pending = { tag, attr: { vr: info.vr }, values: [] };\n }\n\n _baseValue(v, info) {\n this._pending.values.push(this._jsonModelValue(v, info));\n }\n\n /**\n * PS3.18 F.2.3.1: DS/IS may be encoded as JSON numbers OR strings.\n * Emit a number when the conversion is lossless (dcm4chee parity, #53);\n * fall back to the raw source string when Number() would silently lose\n * integer precision — e.g. DS/IS integers beyond 2^53 (#398). The raw\n * string is the standard's escape hatch; `_rawValue` itself never\n * appears in the JSON model (#404).\n */\n _jsonModelValue(v, info) {\n const vr = this._pending.attr.vr;\n if (\n (vr === \"DS\" || vr === \"IS\") &&\n info &&\n typeof info.rawValue === \"string\"\n ) {\n const raw = info.rawValue.trim();\n const parsed = Number(raw);\n if (\n /^[+-]?\\d+$/.test(raw) &&\n !Number.isSafeInteger(parsed) &&\n String(parsed) !== raw\n ) {\n return raw;\n }\n }\n return v;\n }\n\n _baseBulkDataReference(ref = {}) {\n this._pending.attr.BulkDataURI = ref.uri;\n this._pending.values = null; // bulk reference carries no Value\n }\n\n _baseStartBinary() {\n this._pending.fragments = [];\n this._pending.values = null;\n }\n\n _baseBinaryFragment(chunk) {\n this._pending.fragments.push(chunk);\n }\n\n _baseEndBinary() {\n this._pending.attr.InlineBinary = encodeBase64(\n concatFragments(this._pending.fragments)\n );\n }\n\n _baseEndElement() {\n const { tag, attr, values } = this._pending;\n if (values && values.length) {\n attr.Value = values;\n }\n this._container()[tag] = attr;\n this._pending = null;\n }\n\n _baseStartSequence(tag, info = {}) {\n const attr = { vr: info.vr, Value: [] };\n this._container()[tag] = attr;\n this._pending = null;\n // Items are pushed into attr.Value via a sequence marker on the stack.\n this._containers.push({ __seqValue: attr.Value });\n }\n\n _baseStartItem() {\n const item = {};\n this._container().__seqValue.push(item);\n this._containers.push(item);\n }\n\n _baseEndItem() {\n this._containers.pop();\n }\n\n _baseEndSequence() {\n this._containers.pop();\n }\n}\n\nfunction concatFragments(fragments) {\n // a view, or a buffer (ArrayBuffer or SharedArrayBuffer)\n const parts = fragments.map(f =>\n ArrayBuffer.isView(f)\n ? new Uint8Array(f.buffer, f.byteOffset, f.byteLength)\n : new Uint8Array(f)\n );\n const total = parts.reduce((n, p) => n + p.length, 0);\n const out = new Uint8Array(total);\n let off = 0;\n for (const p of parts) {\n out.set(p, off);\n off += p.length;\n }\n return out;\n}\n"],"names":[],"mappings":";;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,YAAY,SAAS,iBAAiB,CAAC;AACpD;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,YAAY,EAAE;AACxB,QAAQ,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;AAC5C;AACA;AACA,QAAQ,OAAO,IAAI,CAAC,UAAU,CAAC;;AAE/B,QAAQ,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;AACxD,QAAQ,OAAO;AACf,cAAc,WAAW,CAAC,OAAO,EAAE,YAAY;AAC/C,cAAc,WAAW,CAAC,OAAO,CAAC;AAClC,IAAI;AACJ;;AC3BA,MAAM,gBAAgB,GAAG,UAAU;AACnC,MAAM,mBAAmB,GAAG,UAAU;AACtC,MAAM,gBAAgB,GAAG,UAAU;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AM,EAAE,CAAC,CAAC;AACzD,IAAI,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC;AACrC,IAAI,IAAI,GAAG,GAAG,CAAC;AACf,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;AAC3B,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;AACvB,QAAQ,GAAG,IAAI,CAAC,CAAC,MAAM;AACvB,IAAI;AACJ,IAAI,OAAO,GAAG;AACd;;;;"}
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@dcmjs-org/generator",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-beta.10",
4
+ "description": "The event-stream writing side of dcmjs: the sinks that turn contract events into DICOM Part 10 bytes (collected or streaming) and DICOMweb JSON",
5
+ "main": "./dist/index.cjs",
6
+ "files": [
7
+ "dist",
8
+ "README.md"
9
+ ],
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/dcmjs-org/dcmjs.git",
14
+ "directory": "packages/generator"
15
+ },
16
+ "dependencies": {
17
+ "@dcmjs-org/core": "1.0.0-beta.10",
18
+ "@dcmjs-org/parser": "1.0.0-beta.10"
19
+ },
20
+ "scripts": {
21
+ "build": "rollup -c ../../rollup.packages.config.mjs"
22
+ },
23
+ "module": "./dist/index.mjs",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.mjs",
27
+ "require": "./dist/index.cjs"
28
+ },
29
+ "./package.json": "./package.json"
30
+ }
6
31
  }