-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require('fs'); | ||
const fsextra = require('fs-extra'); | ||
const dvpl = require('./dvpl_convert.js'); | ||
|
||
async function recursionOnFolders (passFun, dir, outDir){ | ||
let fileCount = 0; | ||
let dirList = await fsextra.readdir(dir); | ||
dirList.map(async x => { | ||
if(fs.statSync(`${dir}\\${x}`).isDirectory()){ | ||
fsextra.mkdirs(`${outDir}\\${x}`); | ||
fileCount += await recursionOnFolders(passFun,`${dir}\\${x}`,`${outDir}\\${x}`); | ||
} | ||
else { | ||
passFun(`${dir}\\${x}`,`${outDir}\\${x}`); | ||
fileCount += 1; | ||
} | ||
}); | ||
return fileCount | ||
} | ||
|
||
async function compress (fileIn, fileOut){ | ||
let fileData = await fsextra.readFile(fileIn); | ||
try{ | ||
fsextra.writeFile(fileOut + '.dvpl', dvpl.compressDVPl(fileData)); | ||
console.log(`File ${fileIn} has been successfully compressed into ${fileOut}.dvpl`) | ||
} catch (err){ | ||
console.log("\x1b[41m%\x1b[0m", `File ${fileIn} Failed to convert due to ${err}`) | ||
} | ||
} | ||
|
||
async function decompress (fileIn, fileOut){ | ||
let fileData = await fsextra.readFile(fileIn); | ||
try{ | ||
fsextra.writeFile(fileOut.replace(".dvpl",""), dvpl.decompressDVPL(fileData)); | ||
console.log(`File ${fileIn} has been successfully decompressed into ${fileOut.replace(".dvpl","")}`) | ||
} | ||
catch(err){ | ||
console.log("\x1b[41m%\x1b[0m", `File ${fileIn} Failed to convert due to ${err}`) | ||
} | ||
} | ||
|
||
exports.recursionOnFolders = recursionOnFolders; | ||
exports.compress = compress; | ||
exports.decompress = decompress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const reFS = require('./fileSystem.js'); | ||
|
||
reFS.recursionOnFolders(reFS.decompress(),'./fromDVPL','output_fromDVPL'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const reFS = require('./fileSystem.js'); | ||
|
||
reFS.recursionOnFolders(reFS.compress,'./toDVPL','output_toDVPL'); |