Skip to content

Commit 710bcc0

Browse files
committed
[ISSUE]: working on it
Signed-off-by: ashish <[email protected]>
1 parent 433b187 commit 710bcc0

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"axios": "^0.19.0",
2020
"chalk": "^3.0.0",
2121
"crypto-js": "^3.1.9-1",
22+
"detect-character-encoding": "^0.8.0",
23+
"encoding-japanese": "^1.0.30",
2224
"jshashes": "^1.0.7",
2325
"minify": "^4.1.3",
2426
"moment": "^2.24.0",

src/utilities/utilities.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// tslint:disable-next-line:file-name-casing
22
import * as fs from 'fs'
33

4+
const detectCharacterEncoding = require('detect-character-encoding')
5+
const Encoding = require('encoding-japanese')
6+
47
import Logger from './logger'
58
// tslint:disable-next-line:no-unnecessary-class
69
export default class Utilities {
@@ -9,7 +12,27 @@ export default class Utilities {
912
if (!fs.existsSync(filePath)) {
1013
Logger.error(thisRef, `Could not find file: ${filePath}`) // this will output error and exit command
1114
} else {
12-
fileStr = fs.readFileSync(filePath, 'utf8')
15+
let fileBuffer = fs.readFileSync(filePath)
16+
17+
// let detected = Encoding.detect(fileBuffer)
18+
let charsetMatch = detectCharacterEncoding(fileBuffer)
19+
20+
// thisRef.log('BUFFER:'+detected)
21+
// thisRef.log(charsetMatch.encoding)
22+
//
23+
fileStr = fileBuffer.toString()
24+
// fileStr = fileBuffer.toString('utf8') //converting to utf8
25+
26+
thisRef.log('BEFORE:' + Encoding.detect(fileStr))
27+
28+
thisRef.log(fileStr.length)
29+
fileStr = Encoding.convert(fileStr, {
30+
to: 'UTF8', // to_encoding
31+
from: charsetMatch.encoding, // from_encoding
32+
})
33+
thisRef.log('AFTER:' + Encoding.detect(fileStr))
34+
35+
thisRef.log(fileStr.length)
1336

1437
// TODO: fix this Issue #3
1538
if (fileStr.charAt(fileStr.length - 1) === '\n') {

test/commands/hash.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ describe('hash', () => {
2222
.stdout()
2323
.command(['hash', '-t', 'md5'])
2424
.exit(0)
25-
.it("Empty Input String -> cdt hash -t md5", ctx => {
25+
.it('Empty Input String -> cdt hash -t md5', ctx => {
2626
expect(ctx.stdout).to.contain('Input string is empty or undefined')
2727
})
2828

29-
3029
// passing sha1 as option
3130
test
3231
.stdout()
@@ -99,4 +98,12 @@ describe('hash', () => {
9998
.it("If File not found ->cdt hash -f 'test/resources/filenotfound.txt'", ctx => {
10099
expect(ctx.stdout).to.contain('Could not find file')
101100
})
101+
//installer file - checksum check
102+
test
103+
.stdout()
104+
.command(['hash', '-t', 'sha512', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
105+
.it('Installer checksum validation', ctx => {
106+
expect(ctx.stdout).to.contain('14eef64ad13c1f689f2ab0d2b2b66c9273bf336e557d81d5c22ddb001c47cf51f03bb1465d6059ce9fdc2e43180ceb0638ce914af1f53af9c2398f5d429f114c')
107+
})
108+
102109
})
2.63 MB
Binary file not shown.
2.63 MB
Binary file not shown.

0 commit comments

Comments
 (0)