Skip to content

Commit

Permalink
update pako, handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
r03ert0 committed Oct 19, 2020
1 parent 0e64a35 commit dfa9fc8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions mri.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function MRI() {
//struct_url: 'http://localhost/structjs/struct.js',
//pako_url: 'http://localhost/libs/pako/1.0.5/pako.js',
struct_url: 'https://cdn.jsdelivr.net/gh/neuroanatomy/structjs@0.0.1/struct.js',
pako_url: 'https://cdn.jsdelivr.net/npm/pako@1.0.10/dist/pako.min.js',
pako_url: 'https://cdn.jsdelivr.net/npm/pako@1.0.11/dist/pako.min.js',
// script loader
loadScript: function loadScript(path, testScriptPresent) {
var pr = new Promise(function(resolve, reject) {
Expand Down Expand Up @@ -234,7 +234,14 @@ function MRI() {
// decompress data
var niigz = this.response;
var inflate = new pako.Inflate();
inflate.push(new Uint8Array(niigz), true);
try {
inflate.push(new Uint8Array(niigz), true);
} catch(err) {
return reject(err);
}
if(inflate.ended !== true) {
return reject(new Error("File ended prematurely"));
}
var nii = inflate.result.buffer;
me.parseNifti(nii);
me.mriPath = path;
Expand Down Expand Up @@ -276,7 +283,14 @@ function MRI() {
if(compressed) {
var niigz = this.result;
var inflate = new pako.Inflate();
inflate.push(new Uint8Array(niigz), true);
try {
inflate.push(new Uint8Array(niigz), true);
} catch(err) {
return reject(err);
}
if(inflate.ended !== true) {
return reject(new Error("File ended prematurely"));
}
nii = inflate.result.buffer;
} else {
nii = this.result;
Expand Down

0 comments on commit dfa9fc8

Please sign in to comment.