tonyc726
5/17/2014 - 9:58 AM

nodeJS小记

nodeJS小记

var fs = require('fs');
var iconv = require('iconv-lite');

fs.readFile('./a_uft8.md', function(err, data) {
    if (err) {
        console.error(err);
    } else {
        var str = iconv.decode(data, 'utf-8'); 
        var str2 = iconv.encode(str, 'gbk')
        var str3 = iconv.decode(str2, 'gbk')

        console.log(data)

        fs.writeFile('./b_gbk.md', str2, null, function (err) {
            if (err) throw err;
            console.log('It\'s saved!');
        });
    }
});