Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add untilTag option to readFile #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/DicomMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ const encapsulatedSyntaxes = [
];

class DicomMessage {
static read(bufferStream, syntax, ignoreErrors) {
static read(bufferStream, syntax, ignoreErrors, untilTag) {
var dict = {};
try {
while (!bufferStream.end()) {
var readInfo = DicomMessage.readTag(bufferStream, syntax);
const readInfo = DicomMessage.readTag(bufferStream, syntax);
const cleanTagString = readInfo.tag.toCleanString();

dict[readInfo.tag.toCleanString()] = {
if (untilTag && untilTag === cleanTagString) {
break;
}

dict[cleanTagString] = {
vr: readInfo.vr.type,
Value: readInfo.values
};
Expand Down Expand Up @@ -67,8 +72,8 @@ class DicomMessage {
return encapsulatedSyntaxes.indexOf(syntax) != -1;
}

static readFile(buffer, options = { ignoreErrors: false }) {
const { ignoreErrors } = options;
static readFile(buffer, options = { ignoreErrors: false, untilTag: null }) {
const { ignoreErrors, untilTag } = options;
var stream = new ReadBufferStream(buffer),
useSyntax = EXPLICIT_LITTLE_ENDIAN;
stream.reset();
Expand All @@ -86,7 +91,12 @@ class DicomMessage {
//get the syntax
var mainSyntax = metaHeader["00020010"].Value[0];
mainSyntax = DicomMessage._normalizeSyntax(mainSyntax);
var objects = DicomMessage.read(stream, mainSyntax, ignoreErrors);
var objects = DicomMessage.read(
stream,
mainSyntax,
ignoreErrors,
untilTag
);

var dicomDict = new DicomDict(metaHeader);
dicomDict.dict = objects;
Expand Down