Closed KaKi87 closed 5 years ago
Are you looking to directly detect the encoding of a variable or to directly convert a string to UTF-8? As for the latter, I’m not sure how detect-character-encoding can be of much help.
Closing due to lack of response.
Hey, I wanted to do both, and it would have been great if your module could do the first thing, but I was actually downloading a file and the encoding was specified in the HTTP response header, I didn't knew it before I posted that issue. Thanks !
Using the HTTP header is definitely a better idea but just in case you might need it again: You can download a file to a Buffer
which you can then directly pass to detect-character-encoding.
Thanks !
The Buffer.from
method takes encoding as second parameter, and it is default to UTF-8, but I don't know the encoding, and that's why I would like to use your library, then how could I pass a variable to Buffer without knowing the encoding and then detect it using your library ?
https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding
Buffer.from(array)
accepts an array
of octets which you could then pass to detect-character-encoding. If you’d like to download a file, though, various HTTP request libraries (such as Got) already support returning a Buffer
.
Hello.
I am wondering if it is possible to directly convert a string to UTF8 without saving it in a file ?
Thanks.