node-chardet icon indicating copy to clipboard operation
node-chardet copied to clipboard

Chardet is locking main-thread in browser (electron) context without errors?

Open thrnd opened this issue 4 years ago • 3 comments

Hello there!

I am trying to use chardet while parsing big (20-30k+ rows) csv files. When i am calling chardet.detect() it returns result for first 10-14 elements and then main thread just dies and nothing happenning. Same thing in web-worker context (still inside electron).

My code (it is working in electron app in browser main thread context):

const chardet = require("chardet");

hugeArrayOfRowsParsedFromCSVFile.forEach((row, index) => {
    if (index > 100 && index < 200) {
        console.log( chardet.detect( row[0] ) ); //  row[0] is always a String
    }
}

Can the problem be in bad implemented electron's API (require)? I din't yet try chardet in non-electron browser context.

thrnd avatar Apr 05 '21 13:04 thrnd

Ok... i've found out that value to detect was not always a String - sometimes it is a Number, sometimes undefined... But why there is no error message then? I've got once an error something like: "Argument must be a ArrayBuffer or a String"

thrnd avatar Apr 05 '21 14:04 thrnd

Sorry for the 11 months delay 😬

Would you be able to share a test data for this case?

runk avatar Mar 24 '22 09:03 runk

I've run into this as well. It's easy to replicate in the Node repl:

$ node
const chardet = require('chardet');
chardet.detect(123);

andrew-pledge-io avatar Sep 27 '23 14:09 andrew-pledge-io

This should be fixed now via #90

runk avatar Aug 07 '24 06:08 runk