@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.1

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 (127) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/binary-encoding.js +402 -410
  3. package/dist/cjs/descriptor-registry.js +407 -449
  4. package/dist/cjs/descriptor-set.js +416 -513
  5. package/dist/cjs/field.js +30 -30
  6. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  7. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  8. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  9. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  10. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  11. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  12. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  13. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  14. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  15. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  16. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  17. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  18. package/dist/cjs/index.js +24 -122
  19. package/dist/cjs/message.js +81 -89
  20. package/dist/cjs/private/assert.js +20 -26
  21. package/dist/cjs/private/base64.js +79 -78
  22. package/dist/cjs/private/binary-format-common.js +195 -208
  23. package/dist/cjs/private/binary-format-proto2.js +75 -109
  24. package/dist/cjs/private/binary-format-proto3.js +57 -90
  25. package/dist/cjs/private/enum.js +38 -43
  26. package/dist/cjs/private/field-list.js +51 -50
  27. package/dist/cjs/private/field-wrapper.js +8 -10
  28. package/dist/cjs/private/field.js +22 -25
  29. package/dist/cjs/private/goog-varint.js +275 -0
  30. package/dist/cjs/private/json-format-common.js +414 -440
  31. package/dist/cjs/private/json-format-proto2.js +78 -89
  32. package/dist/cjs/private/json-format-proto3.js +69 -93
  33. package/dist/cjs/private/message-type.js +26 -27
  34. package/dist/cjs/private/names.js +58 -62
  35. package/dist/cjs/private/proto-runtime.js +11 -16
  36. package/dist/cjs/private/scalars.js +100 -103
  37. package/dist/cjs/private/util-common.js +180 -210
  38. package/dist/cjs/proto-int64.js +111 -112
  39. package/dist/cjs/proto2.js +50 -63
  40. package/dist/cjs/proto3.js +61 -74
  41. package/dist/cjs/service-type.js +14 -17
  42. package/dist/cjs/type-registry.js +33 -31
  43. package/dist/esm/binary-encoding.js +401 -414
  44. package/dist/esm/descriptor-registry.js +409 -458
  45. package/dist/esm/descriptor-set.js +417 -478
  46. package/dist/esm/field.js +29 -29
  47. package/dist/esm/google/protobuf/any_pb.js +122 -140
  48. package/dist/esm/google/protobuf/api_pb.js +177 -197
  49. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  50. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  51. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  52. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  53. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  54. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  55. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  56. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  57. package/dist/esm/google/protobuf/type_pb.js +401 -421
  58. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  59. package/dist/esm/index.js +1 -1
  60. package/dist/esm/message.js +81 -89
  61. package/dist/esm/private/assert.js +19 -21
  62. package/dist/esm/private/base64.js +79 -78
  63. package/dist/esm/private/binary-format-common.js +196 -207
  64. package/dist/esm/private/binary-format-proto2.js +76 -81
  65. package/dist/esm/private/binary-format-proto3.js +58 -67
  66. package/dist/esm/private/enum.js +38 -43
  67. package/dist/esm/private/field-list.js +51 -50
  68. package/dist/esm/private/field-wrapper.js +8 -10
  69. package/dist/esm/private/field.js +22 -22
  70. package/dist/esm/private/goog-varint.js +266 -0
  71. package/dist/esm/private/json-format-common.js +414 -435
  72. package/dist/esm/private/json-format-proto2.js +76 -81
  73. package/dist/esm/private/json-format-proto3.js +66 -80
  74. package/dist/esm/private/message-type.js +27 -28
  75. package/dist/esm/private/names.js +57 -57
  76. package/dist/esm/private/proto-runtime.js +11 -11
  77. package/dist/esm/private/scalars.js +99 -99
  78. package/dist/esm/private/util-common.js +180 -192
  79. package/dist/esm/proto-int64.js +111 -112
  80. package/dist/esm/proto2.js +50 -57
  81. package/dist/esm/proto3.js +61 -68
  82. package/dist/esm/service-type.js +12 -12
  83. package/dist/esm/type-registry.js +33 -31
  84. package/dist/types/binary-encoding.d.ts +398 -398
  85. package/dist/types/binary-format.d.ts +69 -91
  86. package/dist/types/descriptor-registry.d.ts +23 -29
  87. package/dist/types/descriptor-set.d.ts +107 -128
  88. package/dist/types/enum.d.ts +21 -21
  89. package/dist/types/field-list.d.ts +21 -21
  90. package/dist/types/field.d.ts +191 -231
  91. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  92. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  93. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  94. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  95. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  96. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  97. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  98. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  99. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  100. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  101. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  102. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  103. package/dist/types/index.d.ts +4 -27
  104. package/dist/types/json-format.d.ts +70 -89
  105. package/dist/types/message-type.d.ts +38 -46
  106. package/dist/types/message.d.ts +73 -99
  107. package/dist/types/private/assert.d.ts +1 -4
  108. package/dist/types/private/binary-format-common.d.ts +6 -32
  109. package/dist/types/private/enum.d.ts +4 -11
  110. package/dist/types/private/field-list.d.ts +14 -21
  111. package/dist/types/private/field-wrapper.d.ts +5 -11
  112. package/dist/types/private/field.d.ts +12 -12
  113. package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
  114. package/dist/types/private/json-format-common.d.ts +5 -27
  115. package/dist/types/private/message-type.d.ts +3 -8
  116. package/dist/types/private/names.d.ts +1 -4
  117. package/dist/types/private/options-map.d.ts +1 -1
  118. package/dist/types/private/proto-runtime.d.ts +29 -42
  119. package/dist/types/private/scalars.d.ts +5 -12
  120. package/dist/types/private/util-common.d.ts +1 -4
  121. package/dist/types/private/util.d.ts +29 -41
  122. package/dist/types/proto-int64.d.ts +42 -42
  123. package/dist/types/service-type.d.ts +37 -57
  124. package/dist/types/type-registry.d.ts +13 -15
  125. package/package.json +2 -2
  126. package/dist/cjs/google/varint.js +0 -280
  127. package/dist/esm/google/varint.js +0 -265
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { proto3 } from "./proto3.js";
2
2
  export { proto2 } from "./proto2.js";
3
3
  export { protoInt64 } from "./proto-int64.js";
4
- export { Message } from "./message.js";
4
+ export { Message, } from "./message.js";
5
5
  export { ScalarType } from "./field.js";
6
6
  export { MethodKind, MethodIdempotency } from "./service-type.js";
7
7
  export { TypeRegistry } from "./type-registry.js";
@@ -1,94 +1,86 @@
1
1
  /**
2
- * Message is the base class of every message, generated, or created at
3
- * runtime.
2
+ * Every message - generated or created at runtime - is an instance of this
3
+ * class.
4
4
  *
5
- * It is _not_ safe to extend this class. If you want to create a message at
6
- * run time, use proto3.makeMessageType().
5
+ * It is unsafe to extend this class. If you want to create a message at run
6
+ * time, use proto3.makeMessageType().
7
7
  */
8
8
  export class Message {
9
- /**
10
- * Compare with a message of the same type.
11
- */
12
- equals(other) {
13
- return this.getType().runtime.util.equals(this.getType(), this, other);
14
- }
15
- /**
16
- * Create a deep copy.
17
- */
18
- clone() {
19
- // return this.getType().runtime.util.clone(this);
20
- return this.getType().runtime.util.clone(this);
21
- }
22
- /**
23
- * Parse from binary data, merging fields.
24
- *
25
- * Repeated fields are appended. Map entries are added, overwriting
26
- * existing keys.
27
- *
28
- * If a message field is already present, it will be merged with the
29
- * new data.
30
- */
31
- fromBinary(bytes, options) {
32
- const type = this.getType(),
33
- format = type.runtime.bin,
34
- opt = format.makeReadOptions(options);
35
- format.readMessage(this, opt.readerFactory(bytes), bytes.byteLength, opt);
36
- return this;
37
- }
38
- /**
39
- * Parse a message from a JSON value.
40
- */
41
- fromJson(jsonValue, options) {
42
- const type = this.getType(),
43
- format = type.runtime.json,
44
- opt = format.makeReadOptions(options);
45
- format.readMessage(type, jsonValue, opt, this);
46
- return this;
47
- }
48
- /**
49
- * Parse a message from a JSON string.
50
- */
51
- fromJsonString(jsonString, options) {
52
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
53
- return this.fromJson(JSON.parse(jsonString), options);
54
- }
55
- /**
56
- * Serialize the message to binary data.
57
- */
58
- toBinary(options) {
59
- const type = this.getType(),
60
- bin = type.runtime.bin,
61
- opt = bin.makeWriteOptions(options),
62
- writer = opt.writerFactory();
63
- bin.writeMessage(this, writer, opt);
64
- return writer.finish();
65
- }
66
- /**
67
- * Serialize the message to a JSON value, a JavaScript value that can be
68
- * passed to JSON.stringify().
69
- */
70
- toJson(options) {
71
- const type = this.getType(),
72
- json = type.runtime.json,
73
- opt = json.makeWriteOptions(options);
74
- return json.writeMessage(this, opt);
75
- }
76
- /**
77
- * Serialize the message to a JSON string.
78
- */
79
- toJsonString(options) {
80
- const value = this.toJson(options);
81
- return JSON.stringify(value, null, options?.prettySpaces ?? 0);
82
- }
83
- /**
84
- * Retrieve the MessageType of this message - a singleton that represents
85
- * the protobuf message declaration and provides metadata for reflection-
86
- * based operations.
87
- */
88
- getType() {
89
- // Any class that extends Message _must_ provide a complete static
90
- // implementation of MessageType.
91
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
92
- return Object.getPrototypeOf(this).constructor;
93
- }
9
+ // TODO find better name to prevent field name conflicts?
10
+ /**
11
+ * Compare with a message of the same type.
12
+ */
13
+ equals(other) {
14
+ return this.getType().runtime.util.equals(this.getType(), this, other);
15
+ }
16
+ // TODO find better name to prevent field name conflicts?
17
+ /**
18
+ * Create a deep copy.
19
+ */
20
+ clone() {
21
+ return this.getType().runtime.util.clone(this);
22
+ }
23
+ /**
24
+ * Parse from binary data, merging fields.
25
+ *
26
+ * Repeated fields are appended. Map entries are added, overwriting
27
+ * existing keys.
28
+ *
29
+ * If a message field is already present, it will be merged with the
30
+ * new data.
31
+ */
32
+ fromBinary(bytes, options) {
33
+ const type = this.getType(), format = type.runtime.bin, opt = format.makeReadOptions(options);
34
+ format.readMessage(this, opt.readerFactory(bytes), bytes.byteLength, opt);
35
+ return this;
36
+ }
37
+ /**
38
+ * Parse a message from a JSON value.
39
+ */
40
+ fromJson(jsonValue, options) {
41
+ const type = this.getType(), format = type.runtime.json, opt = format.makeReadOptions(options);
42
+ format.readMessage(type, jsonValue, opt, this);
43
+ return this;
44
+ }
45
+ /**
46
+ * Parse a message from a JSON string.
47
+ */
48
+ fromJsonString(jsonString, options) {
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
50
+ return this.fromJson(JSON.parse(jsonString), options);
51
+ }
52
+ /**
53
+ * Serialize the message to binary data.
54
+ */
55
+ toBinary(options) {
56
+ const type = this.getType(), bin = type.runtime.bin, opt = bin.makeWriteOptions(options), writer = opt.writerFactory();
57
+ bin.writeMessage(this, writer, opt);
58
+ return writer.finish();
59
+ }
60
+ /**
61
+ * Serialize the message to a JSON value, a JavaScript value that can be
62
+ * passed to JSON.stringify().
63
+ */
64
+ toJson(options) {
65
+ const type = this.getType(), json = type.runtime.json, opt = json.makeWriteOptions(options);
66
+ return json.writeMessage(this, opt);
67
+ }
68
+ /**
69
+ * Serialize the message to a JSON string.
70
+ */
71
+ toJsonString(options) {
72
+ const value = this.toJson(options);
73
+ return JSON.stringify(value, null, options?.prettySpaces ?? 0);
74
+ }
75
+ /**
76
+ * Retrieve the MessageType of this message - a singleton that represents
77
+ * the protobuf message declaration and provides metadata for reflection-
78
+ * based operations.
79
+ */
80
+ getType() {
81
+ // Any class that extends Message _must_ provide a complete static
82
+ // implementation of MessageType.
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
84
+ return Object.getPrototypeOf(this).constructor;
85
+ }
94
86
  }
@@ -2,40 +2,38 @@
2
2
  * Assert that condition is truthy or throw error (with message)
3
3
  */
4
4
  export function assert(condition, msg) {
5
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
6
- if (!condition) {
7
- throw new Error(msg);
8
- }
5
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
6
+ if (!condition) {
7
+ throw new Error(msg);
8
+ }
9
9
  }
10
- const FLOAT32_MAX = 3.4028234663852886e38,
11
- FLOAT32_MIN = -3.4028234663852886e38,
12
- UINT32_MAX = 0xffffffff,
13
- INT32_MAX = 0x7fffffff,
14
- INT32_MIN = -0x80000000;
10
+ const FLOAT32_MAX = 3.4028234663852886e38, FLOAT32_MIN = -3.4028234663852886e38, UINT32_MAX = 0xffffffff, INT32_MAX = 0x7fffffff, INT32_MIN = -0x80000000;
15
11
  /**
16
12
  * Assert a valid signed protobuf 32-bit integer.
17
13
  */
18
14
  export function assertInt32(arg) {
19
- if (typeof arg !== "number") throw new Error("invalid int 32: " + typeof arg);
20
- if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
21
- throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
15
+ if (typeof arg !== "number")
16
+ throw new Error("invalid int 32: " + typeof arg);
17
+ if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
18
+ throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
22
19
  }
23
20
  /**
24
21
  * Assert a valid unsigned protobuf 32-bit integer.
25
22
  */
26
23
  export function assertUInt32(arg) {
27
- if (typeof arg !== "number")
28
- throw new Error("invalid uint 32: " + typeof arg);
29
- if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
30
- throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
24
+ if (typeof arg !== "number")
25
+ throw new Error("invalid uint 32: " + typeof arg);
26
+ if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
27
+ throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
31
28
  }
32
29
  /**
33
30
  * Assert a valid protobuf float value.
34
31
  */
35
32
  export function assertFloat32(arg) {
36
- if (typeof arg !== "number")
37
- throw new Error("invalid float 32: " + typeof arg);
38
- if (!Number.isFinite(arg)) return;
39
- if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
40
- throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
33
+ if (typeof arg !== "number")
34
+ throw new Error("invalid float 32: " + typeof arg);
35
+ if (!Number.isFinite(arg))
36
+ return;
37
+ if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
38
+ throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
41
39
  }
@@ -1,11 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
2
2
  // lookup table from base64 character to byte
3
- let encTable =
4
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
3
+ let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
5
4
  // lookup table from base64 character *code* to byte because lookup by number is fast
6
5
  let decTable = [];
7
6
  for (let i = 0; i < encTable.length; i++)
8
- decTable[encTable[i].charCodeAt(0)] = i;
7
+ decTable[encTable[i].charCodeAt(0)] = i;
9
8
  // support base64url variants
10
9
  decTable["-".charCodeAt(0)] = encTable.indexOf("+");
11
10
  decTable["_".charCodeAt(0)] = encTable.indexOf("/");
@@ -21,57 +20,59 @@ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
21
20
  * no padding
22
21
  */
23
22
  export function base64decode(base64Str) {
24
- // estimate byte size, not accounting for inner padding and whitespace
25
- let es = (base64Str.length * 3) / 4;
26
- // if (es % 3 !== 0)
27
- // throw new Error("invalid base64 string");
28
- if (base64Str[base64Str.length - 2] == "=") es -= 2;
29
- else if (base64Str[base64Str.length - 1] == "=") es -= 1;
30
- let bytes = new Uint8Array(es),
31
- bytePos = 0, // position in byte array
23
+ // estimate byte size, not accounting for inner padding and whitespace
24
+ let es = (base64Str.length * 3) / 4;
25
+ // if (es % 3 !== 0)
26
+ // throw new Error("invalid base64 string");
27
+ if (base64Str[base64Str.length - 2] == "=")
28
+ es -= 2;
29
+ else if (base64Str[base64Str.length - 1] == "=")
30
+ es -= 1;
31
+ let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
32
32
  groupPos = 0, // position in base64 group
33
33
  b, // current byte
34
34
  p = 0; // previous byte
35
- for (let i = 0; i < base64Str.length; i++) {
36
- b = decTable[base64Str.charCodeAt(i)];
37
- if (b === undefined) {
38
- switch (base64Str[i]) {
39
- // @ts-ignore TS7029: Fallthrough case in switch
40
- case "=":
41
- groupPos = 0; // reset state when padding found
42
- // @ts-ignore TS7029: Fallthrough case in switch
43
- case "\n":
44
- case "\r":
45
- case "\t":
46
- case " ":
47
- continue; // skip white-space, and padding
48
- default:
49
- throw Error("invalid base64 string.");
50
- }
35
+ for (let i = 0; i < base64Str.length; i++) {
36
+ b = decTable[base64Str.charCodeAt(i)];
37
+ if (b === undefined) {
38
+ switch (base64Str[i]) {
39
+ // @ts-ignore TS7029: Fallthrough case in switch
40
+ case "=":
41
+ groupPos = 0; // reset state when padding found
42
+ // @ts-ignore TS7029: Fallthrough case in switch
43
+ case "\n":
44
+ case "\r":
45
+ case "\t":
46
+ case " ":
47
+ continue; // skip white-space, and padding
48
+ default:
49
+ throw Error("invalid base64 string.");
50
+ }
51
+ }
52
+ switch (groupPos) {
53
+ case 0:
54
+ p = b;
55
+ groupPos = 1;
56
+ break;
57
+ case 1:
58
+ bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
59
+ p = b;
60
+ groupPos = 2;
61
+ break;
62
+ case 2:
63
+ bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
64
+ p = b;
65
+ groupPos = 3;
66
+ break;
67
+ case 3:
68
+ bytes[bytePos++] = ((p & 3) << 6) | b;
69
+ groupPos = 0;
70
+ break;
71
+ }
51
72
  }
52
- switch (groupPos) {
53
- case 0:
54
- p = b;
55
- groupPos = 1;
56
- break;
57
- case 1:
58
- bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
59
- p = b;
60
- groupPos = 2;
61
- break;
62
- case 2:
63
- bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
64
- p = b;
65
- groupPos = 3;
66
- break;
67
- case 3:
68
- bytes[bytePos++] = ((p & 3) << 6) | b;
69
- groupPos = 0;
70
- break;
71
- }
72
- }
73
- if (groupPos == 1) throw Error("invalid base64 string.");
74
- return bytes.subarray(0, bytePos);
73
+ if (groupPos == 1)
74
+ throw Error("invalid base64 string.");
75
+ return bytes.subarray(0, bytePos);
75
76
  }
76
77
  /**
77
78
  * Encodes a byte array to a base64 string.
@@ -79,35 +80,35 @@ export function base64decode(base64Str) {
79
80
  * Does not insert newlines.
80
81
  */
81
82
  export function base64encode(bytes) {
82
- let base64 = "",
83
- groupPos = 0, // position in base64 group
83
+ let base64 = "", groupPos = 0, // position in base64 group
84
84
  b, // current byte
85
85
  p = 0; // carry over from previous byte
86
- for (let i = 0; i < bytes.length; i++) {
87
- b = bytes[i];
88
- switch (groupPos) {
89
- case 0:
90
- base64 += encTable[b >> 2];
91
- p = (b & 3) << 4;
92
- groupPos = 1;
93
- break;
94
- case 1:
95
- base64 += encTable[p | (b >> 4)];
96
- p = (b & 15) << 2;
97
- groupPos = 2;
98
- break;
99
- case 2:
100
- base64 += encTable[p | (b >> 6)];
101
- base64 += encTable[b & 63];
102
- groupPos = 0;
103
- break;
86
+ for (let i = 0; i < bytes.length; i++) {
87
+ b = bytes[i];
88
+ switch (groupPos) {
89
+ case 0:
90
+ base64 += encTable[b >> 2];
91
+ p = (b & 3) << 4;
92
+ groupPos = 1;
93
+ break;
94
+ case 1:
95
+ base64 += encTable[p | (b >> 4)];
96
+ p = (b & 15) << 2;
97
+ groupPos = 2;
98
+ break;
99
+ case 2:
100
+ base64 += encTable[p | (b >> 6)];
101
+ base64 += encTable[b & 63];
102
+ groupPos = 0;
103
+ break;
104
+ }
105
+ }
106
+ // padding required?
107
+ if (groupPos) {
108
+ base64 += encTable[p];
109
+ base64 += "=";
110
+ if (groupPos == 1)
111
+ base64 += "=";
104
112
  }
105
- }
106
- // padding required?
107
- if (groupPos) {
108
- base64 += encTable[p];
109
- base64 += "=";
110
- if (groupPos == 1) base64 += "=";
111
- }
112
- return base64;
113
+ return base64;
113
114
  }