steamutils 1.5.39 → 1.5.41

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.
package/_steamproto.js CHANGED
@@ -1,51 +1,53 @@
1
- import path from "path";
2
- import { fileURLToPath } from "url";
3
- import Protobuf from "protobufjs";
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
-
8
- export class SteamProto {
9
- constructor(proto) {
10
- this._proto = proto;
11
- }
12
-
13
- toProto() {
14
- const root = new Protobuf.Root().loadSync(path.join(`${__dirname}/protos/`, this._proto.filename), {
15
- keepCase: true,
16
- });
17
- return root[this._proto.name];
18
- }
19
-
20
- protoEncode(obj) {
21
- const protobuf = this.toProto();
22
- return protobuf.encode(protobuf.create(obj)).finish();
23
- }
24
-
25
- protoEncodeBase64(obj) {
26
- return this.protoEncode(obj).toString("base64");
27
- }
28
-
29
- protoDecode(obj) {
30
- if (isBase64(obj)) {
31
- obj = Buffer.from(obj, "base64");
32
- }
33
-
34
- const protobuf = this.toProto();
35
- try {
36
- return protobuf.toObject(protobuf.decode(obj), { defaults: true });
37
- } catch (e) {
38
- console.error(`[${this._proto.name}] protoDecode 1`, typeof obj, obj);
39
- console.error(`[${this._proto.name}] protoDecode 2`, e);
40
- return null;
41
- }
42
- }
43
- }
44
-
45
- function isBase64(str) {
46
- if (typeof str !== "string") return false;
47
- // remove whitespace and check
48
- str = str.trim();
49
- // base64 should only contain A-Z, a-z, 0-9, +, /, and possibly = at the end
50
- return /^[A-Za-z0-9+/]+={0,2}$/.test(str) && str.length % 4 === 0;
51
- }
1
+ import path from "path";
2
+ import { fileURLToPath } from "url";
3
+ import Protobuf from "protobufjs";
4
+ import gpf from "google-proto-files";
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ export class SteamProto {
10
+ constructor(proto) {
11
+ this._proto = proto;
12
+ }
13
+
14
+ toProto() {
15
+ const filePath = path.join(`${__dirname}/protos/`, this._proto.filename);
16
+ const root = new Protobuf.Root().loadSync([gpf.getProtoPath("protobuf/descriptor.proto"), filePath], {
17
+ keepCase: true,
18
+ });
19
+ return root.lookupType(this._proto.name);
20
+ }
21
+
22
+ protoEncode(obj) {
23
+ const protobuf = this.toProto();
24
+ return protobuf.encode(protobuf.create(obj)).finish();
25
+ }
26
+
27
+ protoEncodeBase64(obj) {
28
+ return this.protoEncode(obj).toString("base64");
29
+ }
30
+
31
+ protoDecode(obj) {
32
+ if (isBase64(obj)) {
33
+ obj = Buffer.from(obj, "base64");
34
+ }
35
+
36
+ const protobuf = this.toProto();
37
+ try {
38
+ return protobuf.toObject(protobuf.decode(obj), { defaults: true });
39
+ } catch (e) {
40
+ console.error(`[${this._proto.name}] protoDecode 1`, typeof obj, obj);
41
+ console.error(`[${this._proto.name}] protoDecode 2`, e);
42
+ return null;
43
+ }
44
+ }
45
+ }
46
+
47
+ function isBase64(str) {
48
+ if (typeof str !== "string") return false;
49
+ // remove whitespace and check
50
+ str = str.trim();
51
+ // base64 should only contain A-Z, a-z, 0-9, +, /, and possibly = at the end
52
+ return /^[A-Za-z0-9+/]+={0,2}$/.test(str) && str.length % 4 === 0;
53
+ }