Utf-8 string being saved with wrong charset to gridfs with node.js

7 views
Skip to first unread message

Stephen Lynx

unread,
Jun 26, 2015, 9:54:19 PM6/26/15
to node-mong...@googlegroups.com
I have this software that generates HTML and saves it to gridfs.
I noticed that my static pages that went through this process were having its special characters such as à and ã corrupted.
I ended fixing it by checking if the incoming data that was going to be written to gridfs was a string and converting it to a buffer using the string and indicating utf-8 as the charset.
Is that intended, is the default charset being used is not utf-8?

  if (typeof (data) === 'string') {
    data
= new Buffer(data, 'utf-8');
 
}

  gs
.write(data, true, function wroteData(error) {

    callback
(error);

 
});Enter code here...


Reply all
Reply to author
Forward
0 new messages