我试图执行一个读取 CSV 文件的示例脚本。然后将数据变成SHA1哈希。我从这个 git 复制了样本:
https://gist.github.com/cdurth/6735c82cd11c5a057bd4
我收到此错误:
C:\Users\test\Desktop\convert\csvParseToSha1.js:14
.fromPath(inputFile)
^
TypeError: csv.fromPath is not a function
at Object.<anonymous> (C:\Users\Nope\Desktop\convert\csvParseToSha1.js:14:3)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
示例代码:
var fs = require('fs');
var csv = require("fast-csv");
var sha1 = require('sha1');
var inputFile = 'emailList.csv';
var outputFile = 'sha1List.csv';
var csvStream = csv.format({headers: false}),
writableStream = fs.createWriteStream(outputFile);
csvStream.pipe(writableStream);
csv
.fromPath(inputFile)
.on("data", function(data){
var hashed = sha1(data[0])
csvStream.write([hashed]);
})
.on("end", function(){
csvStream.end();
console.log("done");
});
fast-csv 版本是 4.1.3