dcmjs 0.49.3 → 0.50.0

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.
Files changed (55) hide show
  1. package/README.md +50 -0
  2. package/build/dcmjs.es.js +1071 -112
  3. package/build/dcmjs.es.js.map +1 -1
  4. package/build/dcmjs.js +1071 -112
  5. package/build/dcmjs.js.map +1 -1
  6. package/build/dcmjs.min.js +2 -2
  7. package/build/dcmjs.min.js.map +1 -1
  8. package/generate/dictionary.mjs +56029 -0
  9. package/package.json +18 -2
  10. package/.babelrc +0 -9
  11. package/.github/workflows/lint-and-format.yml +0 -27
  12. package/.github/workflows/publish-package.yml +0 -45
  13. package/.github/workflows/tests.yml +0 -24
  14. package/.prettierrc +0 -5
  15. package/.vscode/extensions.json +0 -7
  16. package/.vscode/settings.json +0 -8
  17. package/changelog.md +0 -31
  18. package/docs/ArrayBufferExpanderListener.md +0 -303
  19. package/docs/AsyncDicomReader-skill.md +0 -730
  20. package/eslint.config.mjs +0 -30
  21. package/generate-dictionary.js +0 -145
  22. package/jest.setup.js +0 -39
  23. package/netlify.toml +0 -22
  24. package/rollup.config.mjs +0 -57
  25. package/test/ArrayBufferExpanderListener.test.js +0 -365
  26. package/test/DICOMWEB.test.js +0 -1
  27. package/test/DicomMetaDictionary.test.js +0 -73
  28. package/test/SequenceOfItems.test.js +0 -86
  29. package/test/adapters.test.js +0 -43
  30. package/test/anonymizer.test.js +0 -176
  31. package/test/arrayItem.json +0 -351
  32. package/test/async-data.test.js +0 -575
  33. package/test/data-encoding.test.js +0 -59
  34. package/test/data-options.test.js +0 -199
  35. package/test/data.test.js +0 -1776
  36. package/test/derivations.test.js +0 -1
  37. package/test/helper/DicomDataReadBufferStreamBuilder.js +0 -89
  38. package/test/information-filter.test.js +0 -165
  39. package/test/integration/DicomMessage.readFile.test.js +0 -50
  40. package/test/lossless-read-write.test.js +0 -1407
  41. package/test/mocks/minimal_fields_dataset.json +0 -17
  42. package/test/mocks/null_number_vrs_dataset.json +0 -102
  43. package/test/normalizers.test.js +0 -38
  44. package/test/odd-frame-bit-data.js +0 -138
  45. package/test/rawTags.js +0 -170
  46. package/test/readBufferStream.test.js +0 -158
  47. package/test/sample-dicom.json +0 -904
  48. package/test/sample-op.lei +0 -0
  49. package/test/sample-sr.json +0 -997
  50. package/test/sr-tid.test.js +0 -251
  51. package/test/testUtils.js +0 -85
  52. package/test/utilities/deepEqual.test.js +0 -87
  53. package/test/utilities.test.js +0 -205
  54. package/test/video-test-dict.js +0 -40
  55. package/test/writeBufferStream.test.js +0 -149
@@ -1,17 +0,0 @@
1
- {
2
- "StudyDate": "20200924",
3
- "StudyTime": "114538",
4
- "AccessionNumber": "1234",
5
- "ReferringPhysicianName": "Test Physician",
6
- "PatientName": "Patient^Test",
7
- "PatientID": "EM-12123123-123123",
8
- "PatientBirthDate": "20200924",
9
- "PatientSex": null,
10
- "PatientAge": "000Y",
11
- "StudyInstanceUID": "1.2.276.0.123.849752024.12300924094123.637365375382409123",
12
- "SeriesInstanceUID": "1.2.276.0.123.2119584848.12300924095444.123365380848527123",
13
- "StudyID": "2",
14
- "SeriesNumber": 1,
15
- "AcquisitionNumber": 8,
16
- "InstanceNumber": null
17
- }
@@ -1,102 +0,0 @@
1
- {
2
- "_vrMap": {
3
- "PixelData": "OW"
4
- },
5
- "PresentationLUTShape": "IDENTITY",
6
- "ImageType": [
7
- "ORIGINAL",
8
- "PRIMARY"
9
- ],
10
- "PixelData": [],
11
- "SOPClassUID": "1.2.123.10123.5.1.4.1.1.1.1",
12
- "SOPInstanceUID": "1.2.123.0.119.1239584848.20200924095444.123365380848926641",
13
- "StudyDate": "20200924",
14
- "SeriesDate": "20200924",
15
- "AcquisitionDate": "20200924",
16
- "StudyTime": "114538",
17
- "SeriesTime": "115437",
18
- "AcquisitionTime": "115437",
19
- "AccessionNumber": null,
20
- "Modality": "DX",
21
- "PresentationIntentType": "FOR PRESENTATION",
22
- "Manufacturer": "TEST MEDICAL SYSTEMS",
23
- "InstitutionName": null,
24
- "ReferringPhysicianName": null,
25
- "StationName": null,
26
- "StudyDescription": null,
27
- "SeriesDescription": "HAND_DP",
28
- "OperatorsName": "superuser",
29
- "ManufacturerModelName": "PRIXM",
30
- "AnatomicRegionSequence": {
31
- "_vrMap": {},
32
- "CodeValue": "85562004",
33
- "CodingSchemeDesignator": "SCT",
34
- "CodeMeaning": "Hand"
35
- },
36
- "IrradiationEventUID": "1.2.123.0.119.2119584123.20200924095434.637365380746371234",
37
- "PatientName": "Patient^Test",
38
- "PatientID": "EM-12123123-123123",
39
- "PatientBirthDate": "20200924",
40
- "PatientSex": null,
41
- "PatientAge": "000Y",
42
- "AdditionalPatientHistory": null,
43
- "PregnancyStatus": null,
44
- "BodyPartExamined": "HAND",
45
- "KVP": 44.9,
46
- "DeviceSerialNumber": "TEST",
47
- "SoftwareVersions": "1.0.0.0",
48
- "ProtocolName": "HAND_DP",
49
- "ExposureTime": 2,
50
- "XRayTubeCurrent": 1000,
51
- "Exposure": 2,
52
- "ImageAndFluoroscopyAreaDoseProduct": null,
53
- "ImagerPixelSpacing": [
54
- 0.14,
55
- 0.14
56
- ],
57
- "ExposureIndex": 39.78965,
58
- "TargetExposureIndex": 500,
59
- "DeviationIndex": -9.9,
60
- "PositionerType": null,
61
- "ViewPosition": "DP",
62
- "DetectorType": "SCINTILLATOR",
63
- "DetectorManufacturerName": "Test Co.,Ltd",
64
- "DetectorManufacturerModelName": "FXRD-171123",
65
- "StudyInstanceUID": "1.2.276.0.123.849752024.12300924094123.637365375382409123",
66
- "SeriesInstanceUID": "1.2.276.0.123.2119584848.12300924095444.123365380848527123",
67
- "StudyID": "2",
68
- "SeriesNumber": 1,
69
- "AcquisitionNumber": 8,
70
- "InstanceNumber": null,
71
- "ImageLaterality": "B",
72
- "ImagesInAcquisition": 1,
73
- "SamplesPerPixel": 1,
74
- "PhotometricInterpretation": "MONOCHROME2",
75
- "NumberOfFrames": 1,
76
- "Rows": 3072,
77
- "Columns": 3072,
78
- "PixelSpacing": [
79
- 0.14,
80
- 0.14
81
- ],
82
- "BitsAllocated": 16,
83
- "BitsStored": 16,
84
- "HighBit": 15,
85
- "PixelRepresentation": 0,
86
- "BurnedInAnnotation": "NO",
87
- "PixelIntensityRelationship": "LIN",
88
- "PixelIntensityRelationshipSign": -1,
89
- "WindowCenter": 36451,
90
- "WindowWidth": 21422,
91
- "RescaleIntercept": 0,
92
- "RescaleSlope": 1,
93
- "RescaleType": "US",
94
- "LossyImageCompression": "00",
95
- "AcquisitionContextSequence": null,
96
- "ViewCodeSequence": {
97
- "_vrMap": {},
98
- "CodeValue": "399335002",
99
- "CodingSchemeDesignator": "SCT",
100
- "CodeMeaning": "dorsoplantar"
101
- }
102
- }
@@ -1,38 +0,0 @@
1
- import fs from "fs";
2
- import { jest } from "@jest/globals";
3
- import { getTestDataset } from "./testUtils";
4
- import { DicomMessage } from "../src/DicomMessage";
5
- import { DicomMetaDictionary } from "../src/DicomMetaDictionary";
6
- import dcmjs from "../src";
7
-
8
- // The asset downloads in this file might take some time on a slower connection
9
- jest.setTimeout(60000);
10
-
11
- it("test_normalizer_op", async () => {
12
- const file = fs.readFileSync("test/sample-op.dcm");
13
- const dicomDict = DicomMessage.readFile(file.buffer);
14
-
15
- const dataset = DicomMetaDictionary.naturalizeDataset(dicomDict.dict);
16
- const multiframe = dcmjs.normalizers.Normalizer.normalizeToDataset([
17
- dataset
18
- ]);
19
-
20
- expect(dataset.NumberOfFrames).toEqual(1);
21
- expect(multiframe.NumberOfFrames).toEqual(1);
22
- });
23
-
24
- it("test_normalizer_oct", async () => {
25
- const url =
26
- "https://github.com/dcmjs-org/data/releases/download/oct/oct.dcm";
27
- const dcmPath = await getTestDataset(url, "oct.dcm");
28
- const file = fs.readFileSync(dcmPath);
29
- const dicomDict = DicomMessage.readFile(file.buffer);
30
-
31
- const dataset = DicomMetaDictionary.naturalizeDataset(dicomDict.dict);
32
- const multiframe = dcmjs.normalizers.Normalizer.normalizeToDataset([
33
- dataset
34
- ]);
35
-
36
- expect(dataset.NumberOfFrames).toEqual(97);
37
- expect(multiframe.NumberOfFrames).toEqual(97);
38
- });
@@ -1,138 +0,0 @@
1
- /**
2
- * Test data for odd frame length frames.
3
- * Contains 3 frames with 7 bits each, totaling 21 bits (2 bytes + 5 bits, odd total).
4
- *
5
- * Frame structure:
6
- * - bitsAllocated = 1 (single bit per pixel)
7
- * - rows * cols * samplesPerPixel = 7 (not a multiple of 8)
8
- * - Frame 1: 7 bits (bits 0-6)
9
- * - Frame 2: 7 bits (bits 7-13, continuing from frame 1)
10
- * - Frame 3: 7 bits (bits 14-20, continuing from frame 2)
11
- *
12
- * Total: 21 bits = 2 bytes + 5 bits (not even byte-aligned, requires 3 bytes)
13
- *
14
- * Packed data: frames are packed sequentially bit-by-bit without byte alignment
15
- * Unpacked: each frame is extracted starting at byte 0
16
- */
17
-
18
- export const oddFrameBitData = {
19
- // Number of frames
20
- numberOfFrames: 3,
21
-
22
- // Frame configuration
23
- rows: 7,
24
- columns: 1,
25
- samplesPerPixel: 1,
26
- bitsAllocated: 1, // Single bit per pixel (required for odd-length bit frames)
27
-
28
- // Bits per frame: 1 * 1 * 1 * 7 = 7 bits
29
- bitsPerFrame: 7,
30
-
31
- // Total bits: 3 * 7 = 21 bits (odd, not even byte-aligned)
32
- totalBits: 21,
33
-
34
- // Bytes needed: Math.ceil(21 / 8) = 3 bytes
35
- totalBytes: 3,
36
-
37
- /**
38
- * Gets the packed pixel data as it would appear in a DICOM file.
39
- * Frames are packed sequentially: Frame 1 (7 bits) + Frame 2 (7 bits) + Frame 3 (7 bits)
40
- * Total: 21 bits stored in 3 bytes
41
- *
42
- * Byte 0: Frame 1 (7 bits: 01111111) + Frame 2 bit 0 (1 bit: 0) = 01111111 0 = 0xFE
43
- * Byte 1: Frame 2 bits 1-6 (6 bits: 111111) + Frame 3 bits 0-1 (2 bits: 00) = 111111 00 = 0xFC
44
- * Byte 2: Frame 3 bits 2-6 (5 bits: 11111) + padding (3 bits: 000) = 11111 000 = 0xF8
45
- *
46
- * However, for simplicity in testing, we'll use a representation where
47
- * each frame's data is more clearly identifiable. We'll use:
48
- * - Frame 1: 0x7F (01111111) - 7 bits
49
- * - Frame 2: 0x3F (00111111) - 7 bits
50
- * - Frame 3: 0x1F (00011111) - 7 bits
51
- */
52
- getPackedData() {
53
- // Create a buffer to hold all frames (3 bytes for 21 bits)
54
- const buffer = new ArrayBuffer(3);
55
- const view = new DataView(buffer);
56
-
57
- // Pack frames sequentially:
58
- // Frame 1: 0x7F = 01111111 (7 bits)
59
- // Frame 2: 0x3F = 00111111 (7 bits)
60
- // Frame 3: 0x1F = 00011111 (7 bits)
61
-
62
- // Packed representation (21 bits in 3 bytes):
63
- // Byte 0: Frame 1 (7 bits: 01111111) + Frame 2 bit 0 (1 bit: 0) = 01111111 0 = 11111110 = 0xFE
64
- // Byte 1: Frame 2 bits 1-6 (6 bits: 011111) + Frame 3 bits 0-1 (2 bits: 00) = 011111 00 = 01111100 = 0x7C
65
- // Byte 2: Frame 3 bits 2-6 (5 bits: 11111) + padding (3 bits: 000) = 11111 000 = 11111000 = 0xF8
66
-
67
- // But wait, Frame 2 is 0x3F = 00111111, so bits 1-6 are 011111, not 111111
68
- // Let me recalculate:
69
- // Frame 1: 0x7F = 01111111 (bits 0-6)
70
- // Frame 2: 0x3F = 00111111 (bits 7-13)
71
- // Frame 3: 0x1F = 00011111 (bits 14-20)
72
-
73
- // Byte 0: Frame 1 (01111111) + Frame 2 bit 7 (0) = 01111111 0 = 11111110 = 0xFE
74
- // Byte 1: Frame 2 bits 8-13 (011111) + Frame 3 bits 14-15 (00) = 011111 00 = 01111100 = 0x7C
75
- // Byte 2: Frame 3 bits 16-20 (11111) + padding (000) = 11111 000 = 11111000 = 0xF8
76
-
77
- view.setUint8(0, 0xfe);
78
- view.setUint8(1, 0x7c);
79
- view.setUint8(2, 0xf8);
80
-
81
- return buffer;
82
- },
83
-
84
- /**
85
- * Gets the expected unpacked frame data (each frame starting at byte 0)
86
- *
87
- * Packed data:
88
- * - Byte 0: 0xFE = 11111110
89
- * - Byte 1: 0x7C = 01111100
90
- * - Byte 2: 0xF8 = 11111000
91
- *
92
- * Frame 1 (bits 0-6 from packed):
93
- * - Bits 0-6 from byte 0: 1111111
94
- * - Unpacked to byte 0: 11111110 = 0xFE
95
- *
96
- * Frame 2 (bits 7-13 from packed):
97
- * - Bit 7 from byte 0: 0
98
- * - Bits 8-13 from byte 1: 011111
99
- * - Unpacked to byte 0: 00111110 = 0x3E
100
- *
101
- * Frame 3 (bits 14-20 from packed):
102
- * - Bit 14 from byte 1: 0
103
- * - Bit 15 from byte 1: 0
104
- * - Bits 16-20 from byte 2: 11111
105
- * - Unpacked to byte 0: 00111110 = 0x3E
106
- */
107
- getExpectedFrames() {
108
- // Frame 1: 1111111 (7 bits) -> byte 0: 11111110 = 0xFE
109
- // Frame 2: 0011111 (7 bits) -> byte 0: 00111110 = 0x3E
110
- // Frame 3: 0011111 (7 bits) -> byte 0: 00111110 = 0x3E
111
-
112
- // Actually, let me recalculate Frame 3 more carefully:
113
- // Bit 14 (byte 1, bit 6) = 0
114
- // Bit 15 (byte 1, bit 7) = 0
115
- // Bit 16 (byte 2, bit 0) = 1
116
- // Bit 17 (byte 2, bit 1) = 1
117
- // Bit 18 (byte 2, bit 2) = 1
118
- // Bit 19 (byte 2, bit 3) = 1
119
- // Bit 20 (byte 2, bit 4) = 1
120
- // So Frame 3 = 0 0 1 1 1 1 1 = 0011111
121
- // Unpacked: 00111110 = 0x3E
122
-
123
- return [
124
- new Uint8Array([0xfe]), // Frame 1: 11111110
125
- new Uint8Array([0x3e]), // Frame 2: 00111110
126
- new Uint8Array([0x3e]) // Frame 3: 00111110
127
- ];
128
- },
129
-
130
- // Expected individual frame data (each frame read as bytes, but only 7 bits are valid)
131
- // Note: The method will read Math.ceil(7/8) = 1 byte per frame
132
- // Each frame is unpacked starting at byte 0
133
- expectedFrameBytes: [
134
- 1, // Frame 1: 1 byte (7 bits, unpacked to start at byte 0)
135
- 1, // Frame 2: 1 byte (7 bits, unpacked to start at byte 0)
136
- 1 // Frame 3: 1 byte (7 bits, unpacked to start at byte 0)
137
- ]
138
- };
package/test/rawTags.js DELETED
@@ -1,170 +0,0 @@
1
- export const rawTags = {
2
- 60030010: { vr: "LO", Value: ["Some tag"] },
3
- 60031010: {
4
- vr: "SQ",
5
- Value: [
6
- {
7
- 60030010: { vr: "LO", Value: ["Some tag"] },
8
- "00080008": { vr: "CS", Value: ["DERIVED", "SECONDARY"] },
9
- "00082111": { vr: "ST", Value: ["SmallPreview"] },
10
- "00280002": { vr: "US", Value: [3] },
11
- "00280004": { vr: "CS", Value: ["RGB"] },
12
- "00280006": { vr: "US", Value: [0] },
13
- "00280010": { vr: "US", Value: [64] },
14
- "00280011": { vr: "US", Value: [64] },
15
- "00280014": { vr: "US", Value: [0] },
16
- "00280100": { vr: "US", Value: [8] },
17
- "00280101": { vr: "US", Value: [8] },
18
- "00280102": { vr: "US", Value: [7] },
19
- "00280103": { vr: "US", Value: [0] }
20
- }
21
- ]
22
- },
23
- "00020002": { vr: "UI", Value: ["1.2.840.10008.5.1.4.1.1.6.1"] },
24
- "00020003": {
25
- vr: "UI",
26
- Value: ["1.2.276.0.7230010.3.1.4.891503823.1496.1569971389.200"]
27
- },
28
- "00020010": { vr: "UI", Value: ["1.2.840.10008.1.2.4.50"] },
29
- "00020012": { vr: "UI", Value: ["1.2.276.0.7230010.3.0.3.6.4"] },
30
- "00020013": { vr: "SH", Value: ["OFFIS_DCMTK_364"] },
31
- "00020016": { vr: "AE", Value: ["VIVIDS70-210420"] },
32
- "00080005": { vr: "CS", Value: ["ISO_IR 6"] },
33
- "00080008": { vr: "CS", Value: ["DERIVED", "PRIMARY", "", "0003"] },
34
- "00080016": { vr: "UI", Value: ["1.2.840.10008.5.1.4.1.1.6.1"] },
35
- "00080018": {
36
- vr: "UI",
37
- Value: ["1.2.276.0.7230010.3.1.4.891503823.1496.1569971389.200"]
38
- },
39
- "00080050": { vr: "SH" },
40
- "00080060": { vr: "CS", Value: ["US"] },
41
- "00080070": { vr: "LO", Value: ["GE Healthcare Ultrasound"] },
42
- "00080090": { vr: "PN" },
43
- "00081010": { vr: "SH", Value: ["VIVIDS70-210420"] },
44
- "00081070": { vr: "PN", Value: [{ Alphabetic: "CC" }] },
45
- "00081090": { vr: "LO", Value: ["Vivid S70"] },
46
- "00082111": {
47
- vr: "ST",
48
- Value: [
49
- "Lossy compression with JPEG baseline, IJG quality factor 90, compression ratio 13.52"
50
- ]
51
- },
52
- "00082112": {
53
- vr: "SQ",
54
- Value: [
55
- {
56
- "00081150": {
57
- vr: "UI",
58
- Value: ["1.2.840.10008.5.1.4.1.1.6.1"]
59
- },
60
- "00081155": {
61
- vr: "UI",
62
- Value: ["1.2.840.113619.2.394.210420.1570005923.6.1"]
63
- },
64
- "0040A170": {
65
- vr: "SQ",
66
- Value: [
67
- {
68
- "00080100": { vr: "SH", Value: ["121320"] },
69
- "00080102": { vr: "SH", Value: ["DCM"] },
70
- "00080104": {
71
- vr: "LO",
72
- Value: ["Uncompressed predecessor"]
73
- }
74
- }
75
- ]
76
- }
77
- }
78
- ]
79
- },
80
- "00089215": {
81
- vr: "SQ",
82
- Value: [
83
- {
84
- "00080100": { vr: "SH", Value: ["113040"] },
85
- "00080102": { vr: "SH", Value: ["DCM"] },
86
- "00080104": { vr: "LO", Value: ["Lossy Compression"] }
87
- }
88
- ]
89
- },
90
- "00100040": { vr: "CS", Value: ["M"] },
91
- "00101020": { vr: "DS", Value: [1.6] },
92
- "00101030": { vr: "DS", Value: [68] },
93
- "00181020": { vr: "LO", Value: ["Vivid S70:203.66.0"] },
94
- "00181088": { vr: "IS", Value: [72] },
95
- "00186011": {
96
- vr: "SQ",
97
- Value: [
98
- {
99
- "00186012": { vr: "US", Value: [1] },
100
- "00186014": { vr: "US", Value: [1] },
101
- "00186016": { vr: "UL", Value: [0] },
102
- "00186018": { vr: "UL", Value: [375] },
103
- "0018601A": { vr: "UL", Value: [0] },
104
- "0018601C": { vr: "UL", Value: [639] },
105
- "0018601E": { vr: "UL", Value: [204] },
106
- "00186020": { vr: "SL", Value: [133] },
107
- "00186022": { vr: "SL", Value: [0] },
108
- "00186024": { vr: "US", Value: [3] },
109
- "00186026": { vr: "US", Value: [3] },
110
- "0018602C": { vr: "FD", Value: [0.07326203434437528] },
111
- "0018602E": { vr: "FD", Value: [0.07326203434437525] },
112
- "00186030": { vr: "UL", Value: [1670] }
113
- },
114
- {
115
- "00186012": { vr: "US", Value: [2] },
116
- "00186014": { vr: "US", Value: [1] },
117
- "00186016": { vr: "UL", Value: [2] },
118
- "00186018": { vr: "UL", Value: [50] },
119
- "0018601A": { vr: "UL", Value: [212] },
120
- "0018601C": { vr: "UL", Value: [913] },
121
- "0018601E": { vr: "UL", Value: [671] },
122
- "00186020": { vr: "SL", Value: [864] },
123
- "00186022": { vr: "SL", Value: [0] },
124
- "00186024": { vr: "US", Value: [4] },
125
- "00186026": { vr: "US", Value: [3] },
126
- "00186028": { vr: "FD", Value: [4.230744000000016] },
127
- "0018602A": { vr: "FD", Value: [0] },
128
- "0018602C": { vr: "FD", Value: [0.0023148148148148147] },
129
- "0018602E": { vr: "FD", Value: [0.03260869694792706] },
130
- "00186030": { vr: "UL", Value: [1670] }
131
- }
132
- ]
133
- },
134
- "0020000D": {
135
- vr: "UI",
136
- Value: ["1.2.840.113619.2.394.210420.1570005757.1.1"]
137
- },
138
- "0020000E": {
139
- vr: "UI",
140
- Value: ["1.2.840.113619.2.394.210420.1570005757.2.1"]
141
- },
142
- "00200010": { vr: "SH" },
143
- "00200011": { vr: "IS", Value: [1] },
144
- "00200013": { vr: "IS", Value: [4] },
145
- "00200020": { vr: "CS" },
146
- "00280002": { vr: "US", Value: [3] },
147
- "00280004": { vr: "CS", Value: ["YBR_FULL_422"] },
148
- "00280006": { vr: "US", Value: [0] },
149
- "00280010": { vr: "US", Value: [708] },
150
- "00280011": { vr: "US", Value: [1016] },
151
- "00280014": { vr: "US", Value: [0] },
152
- "00280100": { vr: "US", Value: [8] },
153
- "00280101": { vr: "US", Value: [8] },
154
- "00280102": { vr: "US", Value: [7] },
155
- "00280103": { vr: "US", Value: [0] },
156
- "00282110": { vr: "CS", Value: ["01"] },
157
- "00282112": { vr: "DS", Value: [10, 13.52] },
158
- "00282114": { vr: "CS", Value: ["", "ISO_10918_1"] },
159
- "00400275": {
160
- vr: "SQ",
161
- Value: [
162
- {
163
- "0020000D": {
164
- vr: "UI",
165
- Value: ["1.2.840.113619.2.394.210420.1570005757.1.1"]
166
- }
167
- }
168
- ]
169
- }
170
- };
@@ -1,158 +0,0 @@
1
- import { ReadBufferStream } from "../src/BufferStream";
2
-
3
- const size = 128;
4
- const buffer = new ArrayBuffer(size);
5
- const dataView = new DataView(buffer);
6
- for (let i = 0; i < size; i++) {
7
- dataView.setUint8(i, i % 256);
8
- }
9
-
10
- describe("ReadBufferStream Tests", () => {
11
- it("reads single buffer", () => {
12
- const stream = new ReadBufferStream(buffer, true);
13
- expect(stream).toBeDefined();
14
- const view = new DataView(stream.getBuffer(0, size));
15
- expect(view.getUint8(1)).toBe(1);
16
- expect(view.getUint16(0)).toBe(1);
17
- expect(view.getUint32(0)).toBe(66051);
18
- });
19
-
20
- describe("multi-buffer", () => {
21
- it("slices multi buffer", () => {
22
- const stream = new ReadBufferStream(buffer, true);
23
- stream.addBuffer(buffer);
24
- expect(stream.size).toBe(size * 2);
25
- const view = new DataView(stream.getBuffer(size - 4, size + 4));
26
- expect(view.getUint8(3)).toBe(127);
27
- expect(view.getUint8(4)).toBe(0);
28
- expect(view.getUint8(5)).toBe(1);
29
- expect(view.getUint16(5)).toBe(258);
30
- expect(view.getUint32(3)).toBe(2130706690);
31
- });
32
-
33
- it("gets multi buffer", () => {
34
- const stream = new ReadBufferStream(buffer, true);
35
- stream.addBuffer(buffer);
36
- expect(stream.size).toBe(size * 2);
37
- stream.increment(size - 1);
38
- expect(stream.readUint8()).toBe(127);
39
- expect(stream.readUint8()).toBe(0);
40
- expect(stream.readUint8()).toBe(1);
41
- stream.reset();
42
- stream.increment(size + 1);
43
- expect(stream.readUint16()).toBe(513);
44
- stream.reset();
45
- stream.increment(size - 1);
46
- expect(stream.readUint32(size - 1)).toBe(33620095);
47
- });
48
- });
49
-
50
- describe("substream", () => {
51
- it("gets range of buffer", () => {
52
- const stream = new ReadBufferStream(buffer, false, {
53
- start: 32,
54
- stop: 64
55
- });
56
- expect(stream.available).toBe(32);
57
- expect(stream.startOffset).toBe(32);
58
- expect(stream.endOffset).toBe(64);
59
- const buf = stream.slice();
60
- expect(buf.byteLength).toBe(32);
61
- const dv = new DataView(buf);
62
- expect(dv.getUint8(0)).toBe(32);
63
- });
64
-
65
- it("creates subranges on buffer", () => {
66
- const stream = new ReadBufferStream(buffer, false, {
67
- start: 32,
68
- stop: 64
69
- });
70
- const subStream = new ReadBufferStream(
71
- stream.buffer,
72
- stream.isLittleEndian,
73
- { start: stream.offset, stop: stream.size }
74
- );
75
- expect(subStream.startOffset).toBe(32);
76
- expect(subStream.endOffset).toBe(64);
77
- expect(subStream.size).toBe(64);
78
- });
79
-
80
- it("creates subranges on stream", () => {
81
- const stream = new ReadBufferStream(buffer, false, {
82
- start: 32,
83
- stop: 64
84
- });
85
- // This is the recommended way of creating
86
- // a sub-stream as it allows either copying
87
- // or referencing the incoming stream data.
88
- const subStream = new ReadBufferStream(
89
- stream,
90
- stream.isLittleEndian,
91
- { stop: 48 }
92
- );
93
- expect(subStream.available).toBe(16);
94
- expect(subStream.readUint8()).toBe(32);
95
- });
96
- });
97
-
98
- describe("isAvailable", () => {
99
- it("determines when data is correctly available", () => {
100
- const stream = new ReadBufferStream(null, false, {
101
- clearBuffers: true
102
- });
103
- expect(stream.isAvailable(0)).toBe(true);
104
- expect(stream.isAvailable(1)).toBe(false);
105
- stream.addBuffer(buffer.slice(0, 7));
106
- expect(stream.isAvailable(7)).toBe(true);
107
- expect(stream.isAvailable(8)).toBe(false);
108
-
109
- // Read all 4 available/in position
110
- expect(stream.readUint32()).toBe(dataView.getUint32(0));
111
- expect(stream.hasData(7, 8)).toBe(false);
112
- expect(stream.isAvailable(3)).toBe(true);
113
- expect(stream.isAvailable(4)).toBe(false);
114
-
115
- // Read 3 in one buffer, 1 in next
116
- stream.addBuffer(buffer.slice(7, 8));
117
- expect(stream.readUint32()).toBe(dataView.getUint32(4));
118
- expect(stream.hasData(0, 8)).toBe(true);
119
- expect(stream.isAvailable(1)).toBe(false);
120
- expect(stream.isAvailable(0)).toBe(true);
121
-
122
- stream.addBuffer(buffer.slice(8, 10));
123
- stream.addBuffer(buffer.slice(10, 12));
124
- expect(stream.readUint32()).toBe(dataView.getUint32(8));
125
-
126
- stream.addBuffer(buffer.slice(12, 13));
127
- stream.addBuffer(buffer.slice(13, 16));
128
- expect(stream.readUint32()).toBe(dataView.getUint32(12));
129
-
130
- // Check that buffers can get consumed
131
- stream.consume();
132
- expect(stream.hasData(0, 7)).toBe(false);
133
- expect(stream.hasData(7)).toBe(false);
134
- expect(stream.hasData(15)).toBe(false);
135
- expect(stream.hasData(16)).toBe(false);
136
-
137
- // Every byte from a different buffer
138
- stream.addBuffer(buffer.slice(16, 17));
139
- expect(stream.hasData(16)).toBe(true);
140
- stream.addBuffer(buffer.slice(17, 18));
141
- stream.addBuffer(buffer.slice(18, 19));
142
- stream.addBuffer(buffer.slice(19, 20));
143
- expect(stream.readUint32()).toBe(dataView.getUint32(16));
144
- expect(stream.isAvailable(1)).toBe(false);
145
-
146
- // Now read the rest and check isAvailable
147
- stream.addBuffer(buffer.slice(20, buffer.byteLength));
148
- const remaining = buffer.byteLength - 20;
149
- expect(stream.isAvailable(remaining)).toBe(true);
150
- expect(stream.isAvailable(remaining + 1)).toBe(false);
151
-
152
- stream.setComplete();
153
- expect(stream.isAvailable(remaining + 1)).toBe(true);
154
- expect(stream.isAvailable(remaining, false)).toBe(true);
155
- expect(stream.isAvailable(remaining + 1, false)).toBe(false);
156
- });
157
- });
158
- });