-
Notifications
You must be signed in to change notification settings - Fork 599
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
how to load an JSZip uncompressed file to DWV? #332
Comments
The What would need to be done is more like what you can find in io/file.js, which is not that well designed... If you know of a better one, I'm interested! |
Hi, I have done it successfully as follows:
this.loadImagesFromMemory = function (files)
{
// clear variables
self.reset();
nSlicesToLoad = files.length;
// create IO
var memIO = new dwv.io.Memory();
memIO.setDefaultCharacterSet(defaultCharacterSet);
memIO.onload = function (data) {
if ( image ) {
view.append( data.view );
if ( drawStage ) {
appendDrawLayer(image.getNumberOfFrames());
}
}
postLoadInit(data);
};
memIO.onerror = function (error) { handleError(error); };
memIO.onloadend = function (/*event*/) {
if ( drawStage ) {
activateDrawLayer();
}
fireEvent({ 'type': 'load-end' });
};
memIO.onprogress = onLoadProgress;
// main load (asynchronous)
fireEvent({ 'type': 'load-start' });
memIO.load(files);
};
var filename = "";
var files = [];
var zobjs = null;
/**
* JSZip.async callback
* @param {ArrayBuffer} content unzipped file image
* @return {}
*/
var prefixUnzip = "Unzipping... ";
function zipAsyncCallback(content)
{
files.push({"filename": filename, "data": content});
dwv.gui.displayProgress(Math.round(files.length*100/zobjs.length), prefixUnzip);
if (files.length < zobjs.length){
var num = files.length;
filename = zobjs[num].name;
zobjs[num].async("arrayBuffer").then(zipAsyncCallback);
}
else
TheApp.loadImagesFromMemory(files);
}
/**
* JSZip.loadAsync callback
* @param {JSZip} zip JSZip object
* @return {}
*/
function loadAsyncCallback(zip)
{
files = [];
zobjs = zip.file(/.*\.dcm/);
var num = files.length;
filename = zobjs[num].name;
zobjs[num].async("arrayBuffer").then(zipAsyncCallback);
dwv.gui.displayProgress(0, prefixUnzip);
}
/**
* Load images in DMX file after download from URL
* @param {String} url URL to download
* @return {}
*/
var prefixDownload = "Downloading... ";
function loadFromDmxFile( url )
{
dwv.gui.displayProgress(0, prefixDownload);
JSZipUtils.getBinaryContent(url, function(err, data) {
if(err) {
alert(err.name+": "+err.message+".");
}
dwv.gui.displayProgress(100);
JSZip.loadAsync(data).then(loadAsyncCallback);
}, function( event ) {
if (event.lengthComputable){
dwv.gui.displayProgress(Math.round(event.loaded*100.0/event.total), prefixDownload);
}
});
} |
I adapted your code to the new design, see #339. One difference is the zipped file extension, you use |
Thank you for your adaptation. I am glad to make some contribution to this software. |
Thanks to you! Closing this issue for now, feel free to reopen if you see a problem. |
I'm trying this but it doesn't seem to work
I think it has something to do with the file format.
The text was updated successfully, but these errors were encountered: