1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.hexToBase64 = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function intValue(charCode) {
|
20 |
|
21 | if (charCode >= 48 && charCode <= 57) {
|
22 | return charCode - 48;
|
23 | }
|
24 |
|
25 | if (charCode >= 97 && charCode <= 102) {
|
26 | return charCode - 87;
|
27 | }
|
28 |
|
29 | return charCode - 55;
|
30 | }
|
31 | const buf8 = Buffer.alloc(8);
|
32 | const buf16 = Buffer.alloc(16);
|
33 | function hexToBase64(hexStr) {
|
34 | let buf;
|
35 | if (hexStr.length === 16) {
|
36 | buf = buf8;
|
37 | }
|
38 | else if (hexStr.length === 32) {
|
39 | buf = buf16;
|
40 | }
|
41 | else {
|
42 | buf = Buffer.alloc(hexStr.length / 2);
|
43 | }
|
44 | let offset = 0;
|
45 | for (let i = 0; i < hexStr.length; i += 2) {
|
46 | const hi = intValue(hexStr.charCodeAt(i));
|
47 | const lo = intValue(hexStr.charCodeAt(i + 1));
|
48 | buf.writeUInt8((hi << 4) | lo, offset++);
|
49 | }
|
50 | return buf.toString('base64');
|
51 | }
|
52 | exports.hexToBase64 = hexToBase64;
|
53 |
|
\ | No newline at end of file |