Python: chardet.detect with a big binary object

370 Views Asked by At

I get a some big files from a web page. They're binary. I need to scan them to detect thier encode, because chardet.detect let be my script too slow. I tought to use readline but i can't 'cause i have only binary. It's possibile to do something like readline on a binary object?

1

There are 1 best solutions below

1
Marko On

You can't know when there is a newline because you don't know how is it encoded. You can simply take a small part of your binary data data[:100] and run chardet.detect on that.