Skip to content

Commit 4dc1b9b

Browse files
committed
Merge pull request bids-standard#59 from INCF/nii
Setup header reading to support compressed and uncompressed scans.
2 parents 1bb2105 + 2e58e6d commit 4dc1b9b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

utils/files.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ function getFiles (dir, files_){
109109
* header without reading any extra bytes.
110110
*/
111111
function readNiftiHeader (file, callback) {
112-
113112
var bytesRead = 500;
114113

115114
if (fs) {
@@ -126,7 +125,11 @@ function readNiftiHeader (file, callback) {
126125
fs.createReadStream(file.path, {start: 0, end: bytesRead, chunkSize: bytesRead + 1})
127126
.on('data', function (chunk) {
128127
fileBuffer = chunk;
129-
decompressStream.write(chunk);
128+
if (file.name.endsWith('.nii')) {
129+
callback(nifti.parseNIfTIHeader(chunk));
130+
} else {
131+
decompressStream.write(chunk);
132+
}
130133
});
131134

132135
} else {
@@ -144,12 +147,16 @@ function readNiftiHeader (file, callback) {
144147
var buffer = new Uint8Array(fileReader.result);
145148
var unzipped;
146149

147-
try {
148-
unzipped = pako.inflate(buffer);
149-
}
150-
catch (err) {
151-
callback(handleGunzipError(buffer, file));
152-
return;
150+
if (file.name.endsWith('.nii')) {
151+
unzipped = buffer;
152+
} else {
153+
try {
154+
unzipped = pako.inflate(buffer);
155+
}
156+
catch (err) {
157+
callback(handleGunzipError(buffer, file));
158+
return;
159+
}
153160
}
154161

155162
callback(nifti.parseNIfTIHeader(unzipped));

0 commit comments

Comments
 (0)