Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove the printf module file and replace it with the process.stderr.write() function #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const checknet = require("@barudakrosul/internet-available");
const millify = require("millify");
const { program } = require("commander");
const gcrypt = require("../index");
const printf = require("../lib/printf");
const latestVersion = require("../lib/latest-version");
const packageJsonPath = path.join(__dirname, "../package.json");
const packageJson = require(packageJsonPath);

const __program = String(process.argv.slice(1,2)).replace(/.+\//g, "").replace(/(\.[^.]+)?$/, "");
const __program = String(process.argv.slice(1, 2)).replace(/.+\//g, "").replace(/(\.[^.]+)?$/, "");
const url = "https://raw.githubusercontent.com/BarudakRosul/go-crypt/master/package.json";

try {
program
.name(__program)
.version(`Go-crypt v${packageJson.version}`)
.description("Go-crypt is simple encryption and decryption using PBKDF2, zlib, and AES-256-GCM.")
.option("-f, --file <file_name>", "input file name for encryption or decryption")
Expand Down Expand Up @@ -59,11 +59,11 @@ try {
}

if (verbose) {
printf("Buffer size : 8192");
printf(`Original bytes : ${originalBytes} bytes`);
printf(`Output bytes : ${outputBytes} bytes`);
printf(`Timeout : ${timeout} sec`);
printf(`Decrypted : ${millify.millify(percentDecrypted, { precision: 2})}%`);
process.stderr.write("Buffer size : 8192\n");
process.stderr.write(`Original bytes : ${originalBytes} bytes\n`);
process.stderr.write(`Output bytes : ${outputBytes} bytes\n`);
process.stderr.write(`Timeout : ${timeout} sec\n`);
process.stderr.write(`Decrypted : ${millify.millify(percentDecrypted, { precision: 2})}%\n`);
}

if (stdout) {
Expand All @@ -75,8 +75,8 @@ try {
}
fs.unlinkSync(file);
fs.writeFileSync(output, decrypted);
printf(`${__program}: decryption successfully`);
printf(`File saved as '${output}'`);
console.log(`${__program}: decryption successfully`);
console.log(`File saved as '${output}'`);
process.exit(0);
}
} else {
Expand All @@ -90,8 +90,8 @@ try {

process.stdin.on("end", () => {
if (inputText === null || inputText === "") {
printf(`${__program}: missing operand`);
printf(`Try '${__program} --help' for more information`);
process.stderr.write(`${__program}: missing operand\n`);
process.stderr.write(`Try '${__program} --help' for more information\n`);
process.exit(1);
}

Expand All @@ -113,20 +113,20 @@ try {
}

if (verbose) {
printf("Buffer size : 8192");
printf(`Original bytes : ${originalBytes} bytes`);
printf(`Output bytes : ${outputBytes} bytes`);
printf(`Timeout : ${timeout} sec`);
printf(`Decrypted : ${millify.millify(percentDecrypted, { precision: 2})}%`);
process.stderr.write("Buffer size : 8192\n");
process.stderr.write(`Original bytes : ${originalBytes} bytes\n`);
process.stderr.write(`Output bytes : ${outputBytes} bytes\n`);
process.stderr.write(`Timeout : ${timeout} sec\n`);
process.stderr.write(`Decrypted : ${millify.millify(percentDecrypted, { precision: 2})}%\n`);
}

if (! output) {
process.stdout.write(decrypted);
process.exit(0);
} else {
fs.writeFileSync(output, decrypted);
printf(`${__program}: decryption successfully`);
printf(`File saved as '${output}'`);
console.log(`${__program}: decryption successfully`);
console.log(`File saved as '${output}'`);
process.exit(0);
}
});
Expand All @@ -147,11 +147,11 @@ try {
}

if (verbose) {
printf("Buffer size : 8192");
printf(`Original bytes : ${originalBytes} bytes`);
printf(`Output bytes : ${outputBytes} bytes`);
printf(`Timeout : ${timeout} sec`);
printf(`Encrypted : ${millify.millify(percentEncrypted, { precision: 2})}%`);
process.stderr.write("Buffer size : 8192\n");
process.stderr.write(`Original bytes : ${originalBytes} bytes\n`);
process.stderr.write(`Output bytes : ${outputBytes} bytes\n`);
process.stderr.write(`Timeout : ${timeout} sec\n`);
process.stderr.write(`Encrypted : ${millify.millify(percentEncrypted, { precision: 2})}%\n`);
}

if (stdout) {
Expand All @@ -163,8 +163,8 @@ try {
}
fs.unlinkSync(file);
fs.writeFileSync(output, encrypted);
printf(`${__program}: encryption successfully`);
printf(`File saved as '${output}'`);
console.log(`${__program}: encryption successfully`);
console.log(`File saved as '${output}'`);
process.exit(0);
}
} else {
Expand All @@ -178,8 +178,8 @@ try {

process.stdin.on("end", () => {
if (inputText === null || inputText === "") {
printf(`${__program}: missing operand`);
printf(`Try '${__program} --help' for more information`);
process.stderr.write(`${__program}: missing operand`);
process.stderr.write(`Try '${__program} --help' for more information`);
process.exit(1);
}

Expand All @@ -196,20 +196,20 @@ try {
}

if (verbose) {
printf("Buffer size : 8192");
printf(`Original bytes : ${originalBytes} bytes`);
printf(`Output bytes : ${outputBytes} bytes`);
printf(`Timeout : ${timeout} sec`);
printf(`Encrypted : ${millify.millify(percentEncrypted, { precision: 2})}%`);
process.stderr.write("Buffer size : 8192\n");
process.stderr.write(`Original bytes : ${originalBytes} bytes\n`);
process.stderr.write(`Output bytes : ${outputBytes} bytes\n`);
process.stderr.write(`Timeout : ${timeout} sec\n`);
process.stderr.write(`Encrypted : ${millify.millify(percentEncrypted, { precision: 2})}%\n`);
}

if (! output) {
process.stdout.write(encrypted);
process.exit(0);
} else {
fs.writeFileSync(output, encrypted);
printf(`${__program}: encryption successfully`);
printf(`File saved as '${output}'`);
console.log(`${__program}: encryption successfully`);
console.log(`File saved as '${output}'`);
process.exit(0);
}
});
Expand All @@ -223,7 +223,7 @@ try {
})
.parse(process.argv);
} catch (error) {
printf(`${__program}: ${error.message}`);
process.stderr.write(`${__program}: ${error.message}\n`);
const errorCode = typeof error.code === "number" ? error.code : 1;
process.exit(errorCode);
}
18 changes: 0 additions & 18 deletions lib/printf.d.ts

This file was deleted.

22 changes: 0 additions & 22 deletions lib/printf.js

This file was deleted.