From abc698a826854d7cf621b0cbc4168c2bd25e4606 Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Sat, 11 Jun 2022 10:41:00 +0700 Subject: [PATCH] update index.js -> coder.js Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- index.js => coder.js | 13 ++++++------- package.json | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) rename index.js => coder.js (85%) diff --git a/index.js b/coder.js similarity index 85% rename from index.js rename to coder.js index 5ad78a0..9fd34fa 100644 --- a/index.js +++ b/coder.js @@ -2,7 +2,7 @@ const chalk = require('chalk'); const yargs = require('yargs/yargs') const { hideBin } = require('yargs/helpers') const fs = require('fs'); -const fse = require('fs-extra') +// const fse = require('fs-extra') const path = require('path'); const ora = require('ora'); 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('md5').update(argv.pass).digest('hex').substring(0, 16); const data = fs.readFileSync(file); - let array = []; + let encoded = []; 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 try { fs.accessSync(newFilePath); - //fs.rmSync(newFilePath); - fs.ftruncateSync(newFilePath); + fs.rmSync(newFilePath); } catch (err) { // console.log("access err: " + err); } let fd = fs.openSync(newFilePath, 'a+'); // Open file - fs.writeSync(fd, array.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, 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.closeSync(fd); // Close file // fse.removeSync(file); // Remove original non-encoded file diff --git a/package.json b/package.json index 1c2f928..7bf70a1 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "MTA model encoder", "version": "1.0.0", - "main": "index.js", + "main": "coder.js", "private": "true", "scripts": { - "build": "pkg --target node16-win-x64 --compress GZip index.js" + "buildc": "pkg --target node16-win-x64 --compress GZip coder.js" }, "dependencies": { "chalk": "^4.1.2",