Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
let dataArray = new Array();
var csv = require("fast-csv");
var stream = fs.createReadStream(path);
let csvstream = csv.parseStream(stream, {headers : true, delimiter: options.delimiter, quote: options.quote}).on("data", async function(data:any){
if(!isQuestionAsked){
csvstream.pause();
await toGeoJsonFeature(data, options, true);//calling this to ask Lat Lon question to the user for only one time
isQuestionAsked = true;
csvstream.resume();
}
dataArray.push(data);
if(dataArray.length >=chunckSize){
//console.log('dataArray '+chunckSize);
csvstream.pause();
(async()=>{
await streamFuntion(dataArray);
csvstream.resume();
dataArray=new Array();
})();
}
const pr = new Promise((resolve, reject) => {
const csvDataArray = []
stream = fs.createReadStream(uploadFile.file)
csv.parseStream(stream)
.on('data', (data) => {
csvDataArray.push(data)
})
.on('end', async () => {
try {
const response = await onCSVReadComplete(csvDataArray, school)
const pupilRegisterRedisKey = redisKeyService.getPupilRegisterViewDataKey(school.id)
await redisCacheService.drop(pupilRegisterRedisKey)
return resolve(response)
} catch (error) {
reject(error)
}
})
})
return pr
new Promise((resolve, reject) => {
if (!_args.template) resolve(null)
let isFirstRow = true
csv
.parseStream(_args.template, {
delimiter: _args.delimiter,
})
.on('data', function(data) {
if (isFirstRow) {
resolve(data)
isFirstRow = false
}
_args.template.destroy()
})
.on('end', function() {
if (isFirstRow) {
reject(new Error('Template file does not contain any header row'))
}
})
.on('error', reject)