1
所以我解析一個大的csv文件並將結果推送到mongo中。從nodejs中包含重音字符的文件中讀取
該文件是maxminds city database。它有各種有趣的utf8字符。我仍然在某些城市名稱中使用(?)符號。這裏是我正在讀文件:
(使用CSV節點模塊)
csv().from.stream(fs.createReadStream(path.join(__dirname, 'datafiles', 'cities.csv'), {
flags: 'r',
encoding: 'utf8'
})).on('record', function(row,index){
.. uninteresting code to add it to mongodb
});
什麼可能我做錯了嗎? 我得到這樣的事情在蒙戈:Chteauguay,加拿大
編輯:
我試着用不同的LIB來讀取文件:
lazy(fs.createReadStream(path.join(__dirname, 'datafiles', 'cities.csv'), {
flags: 'r',
encoding: 'utf8',
autoClose: true
}))
.lines
.map(String)
.skip(1) // skips the two lines that are iptables header
.map(function (line) {
console.log(line);
});
它產生同樣糟糕結果: 154252「PA」「03」「Capellan a」「」8.3000「-80.5500」「 」154220「AR」「01」「VillaEspa a」 34.7667,-58.2000 ,,
如果你只是讀'fs.createReadStream'文件與'UTF-8',是不是腐敗? csv模塊可以改變它嗎? – Joe
很好的問題。我會看看 – mkoryak