Paul преди 5 години
родител
ревизия
58139adac4
променени са 1 файла, в които са добавени 10 реда и са изтрити 8 реда
  1. 10
    8
      src/utils.ts

+ 10
- 8
src/utils.ts Целия файл

@@ -12,7 +12,8 @@ class Utils {
12 12
   );
13 13
 
14 14
   public static crc32(str: string): number {
15
-    let crcTable = window.crcTable || (window.crcTable = Utils.makeCRCTable());
15
+    const crcTable =
16
+      window.crcTable || (window.crcTable = Utils.makeCRCTable());
16 17
     let crc = 0 ^ -1;
17 18
 
18 19
     for (let i = 0; i < str.length; i++) {
@@ -29,9 +30,9 @@ class Utils {
29 30
       return String.fromCharCode.apply(null, new Uint8Array(buf));
30 31
     }
31 32
 
32
-    let bufView = new Uint8Array(buf);
33
-    let len = bufView.length;
34
-    let byteStr = new Array(len);
33
+    const bufView = new Uint8Array(buf);
34
+    const len = bufView.length;
35
+    const byteStr = new Array(len);
35 36
 
36 37
     for (let i = 0; i < len; i++) {
37 38
       byteStr[i] = String.fromCharCode.call(null, bufView[i]);
@@ -42,8 +43,8 @@ class Utils {
42 43
 
43 44
   // 字符串转为 ArrayBuffer 对象,参数为字符串
44 45
   public static str2ab(str: string): ArrayBuffer {
45
-    let buf = new ArrayBuffer(str.length); // 每个字符占用2个字节
46
-    let bufView = new Uint8Array(buf);
46
+    const buf = new ArrayBuffer(str.length); // 每个字符占用2个字节
47
+    const bufView = new Uint8Array(buf);
47 48
 
48 49
     for (let i = 0, strLen = str.length; i < strLen; i++) {
49 50
       bufView[i] = str.charCodeAt(i);
@@ -79,9 +80,10 @@ class Utils {
79 80
 
80 81
   // 字节数组转换为base64编码
81 82
   public static binToBase64(bitString: string): string {
83
+    const tail = bitString.length % 6;
84
+    const bitStringTemp1 = bitString.substr(0, bitString.length - tail);
85
+
82 86
     let result = '';
83
-    let tail = bitString.length % 6;
84
-    let bitStringTemp1 = bitString.substr(0, bitString.length - tail);
85 87
     let bitStringTemp2 = bitString.substr(bitString.length - tail, tail);
86 88
 
87 89
     for (let i = 0; i < bitStringTemp1.length; i += 6) {