-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (39 loc) · 1.22 KB
/
index.js
File metadata and controls
47 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
let fs = require('fs');
function processToFile(array, fileName, loadSize, installPath, options){
let tempString = '';
let numOfLoads = parseInt(array.length / loadSize);
let currentLoadNum = 0;
let install = `${installPath}/${fileName}.csv`;
for(let m = 0; m <= numOfLoads; m++) {
if(options.logs) {
console.clear();
console.log(`Load ${m} out of ${numOfLoads}`);
}
for (let i = 0+(currentLoadNum*loadSize); i <= parseInt((array.length/numOfLoads)+(currentLoadNum*loadSize)); i++) {
if(array[i]){
tempString = tempString + array[i]+'\n';
}
}
currentLoadNum++;
if(m === 0){
fs.writeFile(install, tempString.toString(), err => {
if (err) {
console.error(err)
}
})
}
else{
fs.appendFile(install,tempString.toString(),err => {
if (err) {
console.error(err)
}
});
}
tempString = 0;
}
if(options.logs) {
console.clear();
console.log(`File created at ${installPath}`);
}
}
module.exports = { processToFile };