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

how do i load a img from zip? #24

Closed
ezshine opened this issue Oct 31, 2012 · 0 comments
Closed

how do i load a img from zip? #24

ezshine opened this issue Oct 31, 2012 · 0 comments

Comments

@ezshine
Copy link

ezshine commented Oct 31, 2012

i'm followed the " reading sample "to open zip file and read a text file success! but i can't do it success with load a img file! could you help me? and if i do load zip file from XHR with my self , should i use any API to open the zip , i try to use the TextReader(XHR.responseText) , but the result isn't the same as HttpReader.

here is my code:

var reqeust=new XMLHttpRequest();
reqeust.onreadystatechange=onZipFileLoaded;
reqeust.onprogress = onZipFileLoadProgress;
reqeust.open("GET",zipFilePath);
reqeust.send();
zip.workerScriptsPath="js/";
var zipReader;
var zipEntries;
function onZipFileLoaded(){
    if(reqeust.readyState==4 && reqeust.status==200){
        zipReader=zip.createReader(new zip.HttpReader(zipFilePath),onZipFileOpened);
}else if(reqeust.readyState==4 && reqeust.status==404){
        //alert(reqeust.readyState "没有找到相关的数据");
        setDocumentTitle("访问数据失败");
    }
}
function setDocumentTitle(str){
    document.title =str;
}
function onZipFileLoadProgress(event){
    if (event.lengthComputable) {
        setDocumentTitle( "已初始化..." (Math.floor(event.loaded / event.total*100)) "%");
    }
}
function onZipFileOpened(reader){
    reader.getEntries(patseEntries);
}
function patseEntries(entries){//filename
    zipEntries=entries;
    getEntryByName(Request("code") "/owcfg.data",new zip.TextWriter(),function(text){
                var obj= text.parseJSON();
                setDocumentTitle(obj.husbandName "和" obj.wifeName "的婚礼");
            });

    getEntryByName(Request("code") "/[email protected]",new zip.BlobWriter(),function(blob){
            //trace(blob);
            var reader = new FileReader();
            reader.onload = function(e){  
                var imgData = e.target.result;
                document.getElementById("logo").src=imgData;
            }  
            reader.readAsDataURL(blob);  
        });
}
function getEntryByName(filename,writer,callback){
    for(var i=0;i<zipEntries.length;i  ){
        var entry=zipEntries[i];
        if(entry.filename==filename){

            entry.getData(writer, callback);

            break;
        }
    }
}
function trace(str){
    document.getElementById("content").innerText=str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants