update index.js -> coder.js

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2022-06-11 10:41:00 +07:00
parent dfaafa1b3f
commit abc698a826
2 changed files with 8 additions and 9 deletions

View File

@@ -2,7 +2,7 @@ const chalk = require('chalk');
const yargs = require('yargs/yargs') const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers') const { hideBin } = require('yargs/helpers')
const fs = require('fs'); const fs = require('fs');
const fse = require('fs-extra') // const fse = require('fs-extra')
const path = require('path'); const path = require('path');
const ora = require('ora'); const ora = require('ora');
const glob = require("glob"); const glob = require("glob");
@@ -56,22 +56,21 @@ getDirectories(argv.res, (err, res) => {
// const key = crypto.createHash('sha256').update(argv.pass).digest('hex').toUpperCase(); // const key = crypto.createHash('sha256').update(argv.pass).digest('hex').toUpperCase();
const key = crypto.createHash('md5').update(argv.pass).digest('hex').substring(0, 16); const key = crypto.createHash('md5').update(argv.pass).digest('hex').substring(0, 16);
const data = fs.readFileSync(file); const data = fs.readFileSync(file);
let array = []; let encoded = [];
for (let i = 0; i < encodeSize; i++) for (let i = 0; i < encodeSize; i++)
array.push(tea.encode(data[i].toString(), key)); encoded.push(tea.encode(data[i].toString(), key));
// Checking file for existing, if exists - deleting it // Checking file for existing, if exists - deleting it
try { try {
fs.accessSync(newFilePath); fs.accessSync(newFilePath);
//fs.rmSync(newFilePath); fs.rmSync(newFilePath);
fs.ftruncateSync(newFilePath);
} catch (err) { } catch (err) {
// console.log("access err: " + err); // console.log("access err: " + err);
} }
let fd = fs.openSync(newFilePath, 'a+'); // Open file let fd = fs.openSync(newFilePath, 'a+'); // Open file
fs.writeSync(fd, array.join(""), 0); // Writing encoded part in start of file fs.writeSync(fd, encoded.join(""), 0); // Writing encoded part in start of file
fs.writeSync(fd, data, encodeSize, data.length-encodeSize); // Writing original part after encoded part fs.writeSync(fd, data, encodeSize, data.length - encodeSize); // Writing original part after encoded part
fs.closeSync(fd); // Close file fs.closeSync(fd); // Close file
// fse.removeSync(file); // Remove original non-encoded file // fse.removeSync(file); // Remove original non-encoded file

View File

@@ -1,10 +1,10 @@
{ {
"name": "MTA model encoder", "name": "MTA model encoder",
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "coder.js",
"private": "true", "private": "true",
"scripts": { "scripts": {
"build": "pkg --target node16-win-x64 --compress GZip index.js" "buildc": "pkg --target node16-win-x64 --compress GZip coder.js"
}, },
"dependencies": { "dependencies": {
"chalk": "^4.1.2", "chalk": "^4.1.2",