简体   繁体   English

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

[英]Uncaught incorrect header check using pako.js

function loadFileAsBinary()
{
    var fileToLoad = document.getElementById("fileToLoad").files[0];

    var fileReader = new FileReader();

    fileReader.onload = function(fileLoadedEvent) 
    {
        var textFromFileLoaded = fileLoadedEvent.target.result;

        var rs       = textFromFileLoaded;

        var charData = rs.split('').map(function(x){return x.charCodeAt(0);}); 
        console.log(charData);

        var bindata  = new Uint8Array(charData);
        console.log(bindata);

        var plain    = pako.inflate(bindata, {to: 'string' });

        var strData  = String.fromCharCode.apply(null, new Uint16Array(plain));

        document.getElementById("inputTextToSave").value = strData;

    };

    fileReader.readAsBinaryString(fileToLoad);
}

I want to inflate upload file but this function gives an error: 我想要上传文件,但此函数会出错:

Uncaught incorrect header check 未捕获的错误标题检查

I was able to solve the same issue by using r.readAsArrayBuffer(f); 我能够通过使用r.readAsArrayBuffer(f);来解决同样的问题r.readAsArrayBuffer(f); and pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"}) pako.inflate(new Uint8Array( e.target.result ) , {"to":"string"})

Here my code: 这是我的代码:

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");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM