sdc-cli 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cli.js +88 -11
  2. package/package.json +3 -2
package/cli.js CHANGED
@@ -6,6 +6,7 @@ import fs from 'fs/promises';
6
6
  import path from 'path';
7
7
  import { spawn } from 'child_process';
8
8
  import { fileURLToPath } from 'url';
9
+ import cliProgress from 'cli-progress';
9
10
 
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const __dirname = path.dirname(__filename);
@@ -19,7 +20,7 @@ class CryptCLI {
19
20
  program
20
21
  .name('sdc-cli')
21
22
  .description('A useful CLI in Node.js to use simple-data-crypto library')
22
- .version('1.0.0');
23
+ .version('1.1.0');
23
24
 
24
25
  // Encrypt command
25
26
  program
@@ -213,9 +214,9 @@ class CryptCLI {
213
214
  }
214
215
  ]);
215
216
 
216
- const password = await this.getPassword(options, 'password');
217
- if (password === '') {
218
- process.stderr.write('Warning: Using empty passwords is dangerous')
217
+ const password = await this.getPassword(options, 'password') || '';
218
+ if ('' === password) {
219
+ process.stderr.write('Warning: Using empty passwords is dangerous\n')
219
220
  }
220
221
  const encrypted = await encrypt_data(answers.inputData, password);
221
222
 
@@ -231,9 +232,46 @@ class CryptCLI {
231
232
  const fileReader = await this.createFileReader(inputFile);
232
233
  const fileWriter = await this.createFileWriter(outputFile || '-');
233
234
  if (inputFile === '-' && (!options.passwordScript)) options.passwordScript = 'sdc-askpass';
234
- const password = await this.getPassword(options, 'password');
235
+ const password = await this.getPassword(options, 'password') || '';
236
+ if ('' === password) {
237
+ process.stderr.write('Warning: Using empty passwords is dangerous\n')
238
+ }
239
+
240
+ // Get file size for progress calculation
241
+ let totalBytes = 0;
242
+ if (inputFile !== '-') {
243
+ try {
244
+ const stats = await fs.stat(inputFile);
245
+ totalBytes = stats.size;
246
+ } catch (error) {
247
+ // If can't get file size, use unknown total
248
+ totalBytes = 0;
249
+ }
250
+ }
235
251
 
236
- const success = await encrypt_file(fileReader, fileWriter, password);
252
+ // Create progress bar for file encryption
253
+ const progressBar = new cliProgress.SingleBar({
254
+ format: 'Encrypting |{bar}| {percentage}% | {value}/{total} bytes',
255
+ barCompleteChar: '\u2588',
256
+ barIncompleteChar: '\u2591',
257
+ hideCursor: true
258
+ });
259
+
260
+ progressBar.start(totalBytes, 0);
261
+
262
+ const success = await encrypt_file(
263
+ fileReader,
264
+ fileWriter,
265
+ password,
266
+ (processedBytes) => {
267
+ progressBar.update(processedBytes);
268
+ }
269
+ );
270
+
271
+ if (totalBytes > 0) {
272
+ progressBar.update(totalBytes);
273
+ }
274
+ progressBar.stop();
237
275
 
238
276
  if (success) {
239
277
  if (outputFile) {
@@ -263,7 +301,7 @@ class CryptCLI {
263
301
  waitUserInput: false
264
302
  }
265
303
  ]);
266
- const password = await this.getPassword(options, 'password');
304
+ const password = await this.getPassword(options, 'password') || '';
267
305
 
268
306
  const decrypted = await decrypt_data(answers.inputData, password);
269
307
 
@@ -278,9 +316,44 @@ class CryptCLI {
278
316
  const fileReader = await this.createFileReader(inputFile);
279
317
  const fileWriter = await this.createFileWriter(outputFile || '-');
280
318
  if (inputFile === '-' && (!options.passwordScript)) options.passwordScript = 'sdc-askpass';
281
- const password = await this.getPassword(options, 'password');
319
+ const password = await this.getPassword(options, 'password') || '';
282
320
 
283
- const success = await decrypt_file(fileReader, fileWriter, password);
321
+ // Get file size for progress calculation
322
+ let totalBytes = 0;
323
+ if (inputFile !== '-') {
324
+ try {
325
+ const stats = await fs.stat(inputFile);
326
+ totalBytes = stats.size;
327
+ } catch (error) {
328
+ // If can't get file size, use unknown total
329
+ totalBytes = 0;
330
+ }
331
+ }
332
+
333
+ // Create progress bar for file decryption
334
+ const progressBar = new cliProgress.SingleBar({
335
+ format: 'Decrypting |{bar}| {percentage}% | {value}/{total} bytes',
336
+ barCompleteChar: '\u2588',
337
+ barIncompleteChar: '\u2591',
338
+ hideCursor: true
339
+ });
340
+
341
+ progressBar.start(totalBytes, 0);
342
+
343
+ const success = await decrypt_file(
344
+ fileReader,
345
+ fileWriter,
346
+ password,
347
+ (decryptedBytes, processedBytes) => {
348
+ // Use processedBytes (the bytes actually read from encrypted file)
349
+ progressBar.update(processedBytes || decryptedBytes);
350
+ }
351
+ );
352
+
353
+ if (totalBytes > 0) {
354
+ progressBar.update(totalBytes);
355
+ }
356
+ progressBar.stop();
284
357
 
285
358
  if (success) {
286
359
  if (outputFile) {
@@ -307,7 +380,7 @@ class CryptCLI {
307
380
  password: options.password,
308
381
  passwordFile: options.passwordFile,
309
382
  passwordScript: options.passwordScript
310
- }, 'current password');
383
+ }, 'current password') || '';
311
384
 
312
385
  // Get new password
313
386
  const newPassword = await this.getPassword({
@@ -315,7 +388,11 @@ class CryptCLI {
315
388
  passwordFile: options.newPasswordFile,
316
389
  passwordScript: options.newPasswordScript,
317
390
  skipConfirm: true
318
- }, 'new password');
391
+ }, 'new password') || '';
392
+
393
+ if ('' === newPassword) {
394
+ process.stderr.write('Warning: Using empty passwords is dangerous\n')
395
+ }
319
396
 
320
397
  // Read file header (first 5KB as recommended)
321
398
  let fileBuffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-cli",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "A useful CLI in Node.js to use simple-data-crypto library",
5
5
  "keywords": [
6
6
  "encryption",
@@ -22,8 +22,9 @@
22
22
  "cli": "node cli.js"
23
23
  },
24
24
  "dependencies": {
25
+ "cli-progress": "^3.12.0",
25
26
  "commander": "^14.0.2",
26
27
  "inquirer": "^13.0.1",
27
- "simple-data-crypto": "^1.56.11"
28
+ "simple-data-crypto": "^1.100.0"
28
29
  }
29
30
  }