使用pako.js检查不正确的标头

时间:2015-06-25 02:44:09

标签: javascript zlib

.render()

我想要上传文件,但此功能会出错:

  

未捕获错误的标题检查

1 个答案:

答案 0 :(得分:0)

我能够使用r.readAsArrayBuffer(f);和来解决同样的问题 pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"})

这是我的代码:

function changeInputFile(evt){
    // Retrieve the first (and only!) File from the FileList object
    var f = evt.target.files[0];
    if (f) {
        let r = new FileReader();
        r.onload = function(e) {
            var contents = e.target.result;
            console.debug( "User layout file:\n"
                         + "name: " + f.name + "\n"
                         + "type: " + f.type + "\n"
                         + "size: " + f.size + " bytes\n"
                         )
            );
            try {
                let jsonContent = null;
                if ( f.type == "application/gzip" ) {
                    jsonContent=pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"});
                } else {
                   // ...
                }
                // ...
            } catch(e) {
                console.error(e)
            }
        }
        r.readAsArrayBuffer(f); 
    } else {
        console.error("Failed to load file");
    }
}