diff --git a/utils/files.js b/utils/files.js index a5b5d5efe..2ff066592 100644 --- a/utils/files.js +++ b/utils/files.js @@ -247,14 +247,19 @@ function readNiftiHeader (file, callback) { callback(handleGunzipError(buffer, file)); }); - fs.open(file.path, 'r', function(status, fd) { - fs.read(fd, buffer, 0, bytesRead, 0, function() { - if (file.name.endsWith('.nii')) { - callback(parseNIfTIHeader(buffer, file)); - } else { - decompressStream.write(buffer); - } - }); + fs.open(file.path, 'r', function(err, fd) { + if (err){ + callback({error: new Issue({code: 44, file: file})}); + return; + } else { + fs.read(fd, buffer, 0, bytesRead, 0, function () { + if (file.name.endsWith('.nii')) { + callback(parseNIfTIHeader(buffer, file)); + } else { + decompressStream.write(buffer); + } + }); + } }); }); } else {