0

im trying to execute a sample script that reads a CSV file. and then make the data into SHA1 hash. I copied the sample from this git:

https://gist.github.com/cdurth/6735c82cd11c5a057bd4

I get this error:

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

The sample code:

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");
 });

the fast-csv version is 4.1.3

0

2 Answers 2

1

for 'fast-csv' version >= 3.0.0 :- fromPath deprecated

https://github.com/C2FO/fast-csv/blob/master/History.md#v300

Sign up to request clarification or add additional context in comments.

2 Comments

so what should i do?
csv.fromPath() change to csv.parseFile()
0

so i have changed csv.fromPath() to csv.parseFile()

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
 .parseFile()(inputFile)
 .on("data", function(data){
   var hashed = sha1(data[0])
   csvStream.write([hashed]);
 })
 .on("end", function(){
     csvStream.end();
     console.log("done");
 });

and now i get this:

internal/fs/utils.js:535
    throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at Object.open (fs.js:424:10)
    at ReadStream.open (internal/fs/streams.js:127:6)
    at new ReadStream (internal/fs/streams.js:115:10)
    at Object.createReadStream (fs.js:1820:10)
    at Object.exports.parseFile (C:\Users\Nope\node_modules\@fast-csv\parse\build\src\index.js:24:52)
    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) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.