@nsnanocat/util 1.8.4 → 1.8.7

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 (3) hide show
  1. package/index.js +0 -1
  2. package/package.json +1 -5
  3. package/gRPC.mjs +0 -66
package/index.js CHANGED
@@ -8,5 +8,4 @@ export * from "./polyfill/fetch.mjs";
8
8
  export * from "./polyfill/Lodash.mjs";
9
9
  export * from "./polyfill/StatusTexts.mjs";
10
10
  export * from "./polyfill/Storage.mjs";
11
- export * from "./gRPC.mjs";
12
11
  export * from "./getStorage.mjs";
package/package.json CHANGED
@@ -23,18 +23,14 @@
23
23
  "type": "git",
24
24
  "url": "https://github.com/NSNanoCat/util.git"
25
25
  },
26
- "dependencies": {
27
- "pako": "^2.1.0"
28
- },
29
26
  "files": [
30
27
  "index.js",
31
28
  "lib",
32
29
  "polyfill",
33
- "gRPC.mjs",
34
30
  "getStorage.mjs"
35
31
  ],
36
32
  "devDependencies": {
37
33
  "typescript": "^5.6.3"
38
34
  },
39
- "version": "1.8.4"
35
+ "version": "1.8.7"
40
36
  }
package/gRPC.mjs DELETED
@@ -1,66 +0,0 @@
1
- import { $app } from "./lib/app.mjs";
2
- import { Console } from "./polyfill/Console.mjs";
3
- import pako from "pako";
4
-
5
- /* https://grpc.io/ */
6
- export class gRPC {
7
- static decode(bytesBody = new Uint8Array([])) {
8
- Console.log("☑️ gRPC.decode");
9
- // 先拆分gRPC校验头和protobuf数据体
10
- const Header = bytesBody.slice(0, 5);
11
- let body = bytesBody.slice(5);
12
- switch (Header[0]) {
13
- case 0: // unGzip
14
- default:
15
- break;
16
- case 1: // Gzip
17
- switch ($app) {
18
- case "Loon":
19
- case "Surge":
20
- case "Egern":
21
- body = $utils.ungzip(body);
22
- break;
23
- default:
24
- body = pako.ungzip(body); // 解压缩protobuf数据体
25
- break;
26
- }
27
- Header[0] = 0; // unGzip
28
- break;
29
- }
30
- Console.log("✅ gRPC.decode");
31
- return body;
32
- }
33
-
34
- static encode(body = new Uint8Array([]), encoding = "identity") {
35
- Console.log("☑️ gRPC.encode");
36
- // Header: 1位:是否校验数据 (0或者1) + 4位:校验值(数据长度)
37
- const Header = new Uint8Array(5);
38
- const Checksum = gRPC.#Checksum(body.length); // 校验值为未压缩情况下的数据长度, 不是压缩后的长度
39
- Header.set(Checksum, 1); // 1-4位: 校验值(4位)
40
- switch (encoding) {
41
- case "gzip":
42
- Header.set([1], 0); // 0位:Encoding类型,当为1的时候, app会校验1-4位的校验值是否正确
43
- body = pako.gzip(body);
44
- break;
45
- case "identity":
46
- case undefined:
47
- default:
48
- Header.set([0], 0); // 0位:Encoding类型,当为1的时候, app会校验1-4位的校验值是否正确
49
- break;
50
- }
51
- const BytesBody = new Uint8Array(Header.length + body.length);
52
- BytesBody.set(Header, 0); // 0-4位:gRPC校验头
53
- BytesBody.set(body, 5); // 5-end位:protobuf数据
54
- Console.log("✅ gRPC.encode");
55
- return BytesBody;
56
- }
57
-
58
- // 计算校验和 (B站为数据本体字节数)
59
- static #Checksum = (num = 0) => {
60
- const array = new ArrayBuffer(4); // an Int32 takes 4 bytes
61
- const view = new DataView(array);
62
- // 首位填充计算过的新数据长度
63
- view.setUint32(0, num, false); // byteOffset = 0; litteEndian = false
64
- return new Uint8Array(array);
65
- };
66
- }