简体   繁体   中英

SyntaxError: missing ) after argument list while using LZMA-js

I am trying to compress a string using the LZMA-JS library found here . Here is my javascript:

var reader  = new FileReader();

reader.addEventListener("load", function () {
    var big_code = reader.result;
    console.log(big_code.length);
    var my_lzma = new LZMA();
    my_lzma.compress(my_lzma, 1, on_finish(result, error) {
        code = result;
    });
    console.log(code.length);
}, false);

The error occurs on this line

my_lzma.compress(my_lzma, 1, on_finish(result, error) { //the rest occurs below

However, when I change this line by removing the {} brackets like this

my_lzma.compress(my_lzma, 1, on_finish(result, error));

the error goes away. Unfortunately this makes the code useless because I need the result .

I have looked around the internet for over an hour trying to find a solution to this error. I don't believe this is a duplicate because I have not found anything related.

Why am I getting this error?

The documentation is perhaps confusing - the function's role, not name, is on_finish , so use this instead to indicate you are creating an in-line function:

my_lzma.compress(my_lzma, 1, function (result, error) {
    code = result;
});

See the example usage here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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