-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractData.js
More file actions
36 lines (29 loc) · 1.18 KB
/
extractData.js
File metadata and controls
36 lines (29 loc) · 1.18 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
const fs = require('fs');
const {cleanUp} = require("./cleanUp");
const {unzipArchive} = require('./unzip');
const {copyFiles} = require('./copyFiles');
const extractData = pathToDirectory => {
//Check The directory path
if(!pathToDirectory) throw new Error('You must provide a path');
if(!(typeof pathToDirectory == "string")) throw new Error('Path must be a string');
fs.readdir(pathToDirectory, 'utf8', async (err, files) => {
//Handle error while reading the directory
if (err) console.error('Process failed due to: ', err.message);
const resultsArray = [];
const errorsArray = [];
//copy files to new directory
copyFiles(pathToDirectory, files);
for (let i = 0; i <files.length; i++){
const res = await unzipArchive(pathToDirectory, files[i]);
if(!res.status) {
errorsArray.push(res);
}
resultsArray.push(res);
}
// fix bad archive error
//sort data --> sort images, sort text per file
//clean up --> delete redundant data
await cleanUp(pathToDirectory); //
});
};
module.exports = extractData;