Remove BOM from Google supported devices csv

78 views
Skip to first unread message

Adi Lavi

unread,
Mar 11, 2018, 12:17:46 PM3/11/18
to nodejs
Hi,
I am writing a small module that downloads Google's list of supported devices as csv, but I get it with a BOM I struggle to remove.

Here is my code snippet:


downloadFile: function(url, cb) {
unirest.get(url)
.timeout(5000)
.header('Upgrade-Insecure-Requests', '1')
.header('Accept-Encoding', 'gzip, deflate, sdch')
.end(function(response) {
let content = response.body;
            fs.writeFile('google_devices.csv', content, 'utf8', (err) => {
               ...
            return cb(null, url);
            });

});
}

file starts with 뿯붿

Tried a few bom-strip libraries, but could not make it work
Please advise

Zlatko

unread,
Mar 12, 2018, 9:42:02 AM3/12/18
to nodejs
Not sure if it helps, but here's what worked for me on a recent project:

payload = payload.replace('\ufeff', '')
    .replace(/\\\\r\\\\n/g, '')
    .replace(/\\"/g, '"');

Hope it helps?

Dave Benson

unread,
Mar 12, 2018, 11:39:35 AM3/12/18
to nod...@googlegroups.com
try using utf16le, which seems to be the format of this file (as you can see from the Content-Type headaer in the response).

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/29f3dd84-c162-4700-84a5-0602c07946ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages