protobufjs 8.7.0 → 8.7.2

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.
@@ -2,14 +2,6 @@ syntax = "proto2";
2
2
 
3
3
  package google.protobuf;
4
4
 
5
- option go_package = "google.golang.org/protobuf/types/descriptorpb";
6
- option java_package = "com.google.protobuf";
7
- option java_outer_classname = "DescriptorProtos";
8
- option csharp_namespace = "Google.Protobuf.Reflection";
9
- option objc_class_prefix = "GPB";
10
- option cc_enable_arenas = true;
11
- option optimize_for = "SPEED";
12
-
13
5
  message FileDescriptorSet {
14
6
 
15
7
  repeated FileDescriptorProto file = 1;
@@ -8,7 +8,8 @@
8
8
  "fields": {
9
9
  "fileName": {
10
10
  "type": "string",
11
- "id": 1
11
+ "id": 1,
12
+ "protoName": "file_name"
12
13
  }
13
14
  }
14
15
  }
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "sourceContext": {
29
29
  "type": "SourceContext",
30
- "id": 5
30
+ "id": 5,
31
+ "protoName": "source_context"
31
32
  },
32
33
  "syntax": {
33
34
  "type": "Syntax",
@@ -55,11 +56,13 @@
55
56
  },
56
57
  "typeUrl": {
57
58
  "type": "string",
58
- "id": 6
59
+ "id": 6,
60
+ "protoName": "type_url"
59
61
  },
60
62
  "oneofIndex": {
61
63
  "type": "int32",
62
- "id": 7
64
+ "id": 7,
65
+ "protoName": "oneof_index"
63
66
  },
64
67
  "packed": {
65
68
  "type": "bool",
@@ -72,11 +75,13 @@
72
75
  },
73
76
  "jsonName": {
74
77
  "type": "string",
75
- "id": 10
78
+ "id": 10,
79
+ "protoName": "json_name"
76
80
  },
77
81
  "defaultValue": {
78
82
  "type": "string",
79
- "id": 11
83
+ "id": 11,
84
+ "protoName": "default_value"
80
85
  }
81
86
  },
82
87
  "nested": {
@@ -131,7 +136,8 @@
131
136
  },
132
137
  "sourceContext": {
133
138
  "type": "SourceContext",
134
- "id": 4
139
+ "id": 4,
140
+ "protoName": "source_context"
135
141
  },
136
142
  "syntax": {
137
143
  "type": "Syntax",
@@ -190,7 +196,8 @@
190
196
  "fields": {
191
197
  "fileName": {
192
198
  "type": "string",
193
- "id": 1
199
+ "id": 1,
200
+ "protoName": "file_name"
194
201
  }
195
202
  }
196
203
  }
package/index.d.ts CHANGED
@@ -2918,6 +2918,9 @@ export class Writer {
2918
2918
  /** Stack of forked length-prefix positions. */
2919
2919
  states: (number[]|null);
2920
2920
 
2921
+ /** Initial backing buffer size in bytes. Defaults to 128. */
2922
+ static initialBufferSize: number;
2923
+
2921
2924
  /**
2922
2925
  * Current write position.
2923
2926
  * @deprecated Use {@link Writer#pos} instead.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "8.7.0",
3
+ "version": "8.7.2",
4
4
  "description": "Protocol Buffers for JavaScript & TypeScript.",
5
5
  "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
6
6
  "license": "BSD-3-Clause",
@@ -49,11 +49,11 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@eslint/js": "^10.0.0",
52
- "@types/node": ">=13.7.0",
52
+ "@types/node": "^18.19.130",
53
53
  "browserify": "^17.0.0",
54
54
  "browserify-wrap": "^1.0.2",
55
55
  "bundle-collapser": "^1.3.0",
56
- "escodegen": "^1.13.0",
56
+ "escodegen": "^2.0.0",
57
57
  "eslint": "^10.0.0",
58
58
  "eslint-plugin-jsdoc": "^63.0.0",
59
59
  "espree": "^9.0.0",
@@ -71,7 +71,7 @@
71
71
  "reflect-metadata": "^0.2.0",
72
72
  "tape": "^5.0.0",
73
73
  "tslint": "^6.0.0",
74
- "typescript": "^3.7.5",
74
+ "typescript": "^4.9.5",
75
75
  "vinyl-buffer": "^1.0.1",
76
76
  "vinyl-fs": "^4.0.0",
77
77
  "vinyl-source-stream": "^2.0.0"
package/src/common.js CHANGED
@@ -163,27 +163,33 @@ common("struct", {
163
163
  fields: {
164
164
  nullValue: {
165
165
  type: "NullValue",
166
- id: 1
166
+ id: 1,
167
+ protoName: "null_value"
167
168
  },
168
169
  numberValue: {
169
170
  type: "double",
170
- id: 2
171
+ id: 2,
172
+ protoName: "number_value"
171
173
  },
172
174
  stringValue: {
173
175
  type: "string",
174
- id: 3
176
+ id: 3,
177
+ protoName: "string_value"
175
178
  },
176
179
  boolValue: {
177
180
  type: "bool",
178
- id: 4
181
+ id: 4,
182
+ protoName: "bool_value"
179
183
  },
180
184
  structValue: {
181
185
  type: "Struct",
182
- id: 5
186
+ id: 5,
187
+ protoName: "struct_value"
183
188
  },
184
189
  listValue: {
185
190
  type: "ListValue",
186
- id: 6
191
+ id: 6,
192
+ protoName: "list_value"
187
193
  }
188
194
  }
189
195
  },
package/src/converter.js CHANGED
@@ -298,12 +298,16 @@ converter.toObject = function toObject(mtype) {
298
298
  else if (field.bytes) {
299
299
  var arrayDefault = Array.prototype.slice.call(field.typeDefault);
300
300
  gen
301
- ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
301
+ ("if(o.bytes===String)d%s=%j", prop, util.base64.encode(field.typeDefault, 0, field.typeDefault.length))
302
302
  ("else{")
303
303
  ("d%s=%j", prop, arrayDefault)
304
304
  ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
305
305
  ("}");
306
- } else gen
306
+ } else if ((field.type === "double" || field.type === "float") && typeof field.typeDefault === "number"
307
+ && (!isFinite(field.typeDefault) || Object.is(field.typeDefault, -0))) gen
308
+ ("d%s=%f", prop, field.typeDefault)
309
+ ("if(o.json&&!isFinite(d%s))d%s=String(d%s)", prop, prop, prop);
310
+ else gen
307
311
  ("d%s=%j", prop, field.typeDefault); // also messages (=null)
308
312
  } gen
309
313
  ("}");
package/src/decoder.js CHANGED
@@ -102,7 +102,7 @@ function decoder(mtype) {
102
102
  ("break");
103
103
 
104
104
  if (types.basic[type] === undefined) gen
105
- ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
105
+ ("v=types[%i].decode(r,r.uint32(),undefined,q+1,v)", i); // can't be groups
106
106
  else gen
107
107
  ("v=r.%s()", type === "string" ? stringMethod(field) : type);
108
108
 
package/src/enum.js CHANGED
@@ -82,8 +82,11 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
82
82
 
83
83
  if (values)
84
84
  for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
85
- if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
86
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
85
+ if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") { // use forward entries only
86
+ this.values[keys[i]] = values[keys[i]];
87
+ if (this.valuesById[values[keys[i]]] === undefined)
88
+ this.valuesById[values[keys[i]]] = keys[i];
89
+ }
87
90
  }
88
91
 
89
92
  /**
package/src/field.js CHANGED
@@ -371,12 +371,17 @@ Field.prototype.resolve = function resolve() {
371
371
 
372
372
  // convert to internal data type if necesssary
373
373
  if (this.long) {
374
- this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type === "uint64" || this.type === "fixed64");
374
+ var unsigned = this.type === "uint64" || this.type === "fixed64";
375
+ this.typeDefault = typeof this.typeDefault === "string"
376
+ ? util.Long.fromString(this.typeDefault, unsigned)
377
+ : util.Long.fromNumber(this.typeDefault, unsigned);
375
378
 
376
379
  /* istanbul ignore else */
377
380
  if (Object.freeze)
378
381
  Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
379
382
 
383
+ } else if (types.long[this.type] !== undefined && typeof this.typeDefault === "string") {
384
+ this.typeDefault = parseInt(this.typeDefault, 10);
380
385
  } else if (this.bytes && typeof this.typeDefault === "string") {
381
386
  var buf;
382
387
  if (util.base64.test(this.typeDefault))
@@ -26,6 +26,7 @@ exports.configure = configure;
26
26
  * @returns {undefined}
27
27
  */
28
28
  function configure() {
29
+ exports.util.LongBits._configure(exports.util.Long);
29
30
  exports.Writer._configure(exports.BufferWriter);
30
31
  exports.Reader._configure(exports.BufferReader);
31
32
  }
package/src/parse.js CHANGED
@@ -23,6 +23,8 @@ var base10Re = /^[1-9][0-9]*$/,
23
23
  base16NegRe = /^-?0[x][0-9a-fA-F]+$/,
24
24
  base8Re = /^0[0-7]+$/,
25
25
  base8NegRe = /^-?0[0-7]+$/,
26
+ integerTypeRe = /^(?:u?int|sint|s?fixed)(?:32|64)$/,
27
+ unsignedTypeRe = /^(?:uint|fixed)(?:32|64)$/,
26
28
  numberRe = util.patterns.numberRe,
27
29
  nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
28
30
  typeRefRe = util.patterns.typeRefRe;
@@ -202,7 +204,7 @@ function parse(source, root, options) {
202
204
  case "nan": case "NAN": case "Nan": case "NaN":
203
205
  return NaN;
204
206
  case "0":
205
- return 0;
207
+ return sign * 0;
206
208
  }
207
209
  if (base10Re.test(token))
208
210
  return sign * parseInt(token, 10);
@@ -219,32 +221,31 @@ function parse(source, root, options) {
219
221
  throw illegal(token, "number", insideTryCatch);
220
222
  }
221
223
 
222
- function parseId(token, acceptNegative, max) {
223
- if (token === null) {
224
+ function parseInteger(token, acceptNegative, name) {
225
+ if (token === null)
224
226
  throw illegal(token, "end of input");
225
- }
227
+ if (!acceptNegative && token.charAt(0) === "-")
228
+ throw illegal(token, name || "integer");
229
+ if (token === "0" || token === "-0")
230
+ return 0;
231
+ var value;
232
+ if (base10NegRe.test(token))
233
+ value = parseInt(token, 10);
234
+ else if (base16NegRe.test(token))
235
+ value = parseInt(token, 16);
236
+ else if (base8NegRe.test(token))
237
+ value = parseInt(token, 8);
238
+ else
239
+ throw illegal(token, name || "integer");
240
+ return value || 0;
241
+ }
242
+
243
+ function parseId(token, acceptNegative, max) {
226
244
  switch (token) {
227
245
  case "max": case "MAX": case "Max":
228
246
  return max || maxFieldId;
229
- case "0":
230
- return 0;
231
247
  }
232
-
233
- /* istanbul ignore if */
234
- if (!acceptNegative && token.charAt(0) === "-")
235
- throw illegal(token, "id");
236
-
237
- if (base10NegRe.test(token))
238
- return parseInt(token, 10);
239
- if (base16NegRe.test(token))
240
- return parseInt(token, 16);
241
-
242
- /* istanbul ignore else */
243
- if (base8NegRe.test(token))
244
- return parseInt(token, 8);
245
-
246
- /* istanbul ignore next */
247
- throw illegal(token, "id");
248
+ return parseInteger(token, acceptNegative, "id");
248
249
  }
249
250
 
250
251
  function parsePackage() {
@@ -559,6 +560,10 @@ function parse(source, root, options) {
559
560
  case ";":
560
561
  break;
561
562
 
563
+ case "map":
564
+ parseMapField(type);
565
+ break;
566
+
562
567
  case "option":
563
568
  parseOption(type, token);
564
569
  skip(";");
@@ -688,7 +693,8 @@ function parse(source, root, options) {
688
693
  if ((token = next()) === null || !nameRe.test(token))
689
694
  throw illegal(token, "name");
690
695
 
691
- var enm = new Enum(token);
696
+ var enm = new Enum(token),
697
+ values = [];
692
698
  ifBlock(enm, function parseEnum_block(token) {
693
699
  switch(token) {
694
700
  case ";":
@@ -705,16 +711,18 @@ function parse(source, root, options) {
705
711
  break;
706
712
 
707
713
  default:
708
- parseEnumValue(enm, token);
714
+ values.push(parseEnumValue(token));
709
715
  }
710
716
  });
717
+ for (var i = 0; i < values.length; ++i)
718
+ enm.add(values[i].name, values[i].id, values[i].comment, values[i].options);
711
719
  parent.add(enm);
712
720
  if (parent === ptr) {
713
721
  topLevelObjects.push(enm);
714
722
  }
715
723
  }
716
724
 
717
- function parseEnumValue(parent, token) {
725
+ function parseEnumValue(token) {
718
726
 
719
727
  /* istanbul ignore if */
720
728
  if (!nameRe.test(token))
@@ -746,7 +754,12 @@ function parse(source, root, options) {
746
754
  }, function parseEnumValue_line() {
747
755
  parseInlineOptions(dummy); // skip
748
756
  });
749
- parent.add(token, value, dummy.comment, dummy.parsedOptions || dummy.options);
757
+ return {
758
+ name: token,
759
+ id: value,
760
+ comment: dummy.comment,
761
+ options: dummy.parsedOptions || dummy.options
762
+ };
750
763
  }
751
764
 
752
765
  function parseOption(parent, token) {
@@ -797,16 +810,27 @@ function parse(source, root, options) {
797
810
  var objectResult = {};
798
811
 
799
812
  while (!skip("}", true)) {
800
- /* istanbul ignore if */
801
- if (!nameRe.test(token = next())) {
802
- throw illegal(token, "name");
803
- }
804
- if (token === null) {
805
- throw illegal(token, "end of input");
813
+ token = next();
814
+ var propName;
815
+ if (token === null)
816
+ throw illegal(token, "end of input");
817
+ if (token === "[") {
818
+ token = next();
819
+ // Extension name or, for Any, a type URL: "<prefix>/<fully.qualified.Type>".
820
+ var slash = token === null ? -1 : token.lastIndexOf("/");
821
+ if (token === null || !typeRefRe.test(slash < 0 ? token : token.slice(slash + 1)))
822
+ throw illegal(token, "name");
823
+ propName = "[" + token + "]";
824
+ skip("]");
825
+ } else {
826
+ /* istanbul ignore if */
827
+ if (!nameRe.test(token)) {
828
+ throw illegal(token, "name");
829
+ }
830
+ propName = token;
806
831
  }
807
832
 
808
833
  var value;
809
- var propName = token;
810
834
 
811
835
  skip(":", true);
812
836
 
@@ -814,25 +838,30 @@ function parse(source, root, options) {
814
838
  // option (my_option) = {
815
839
  // repeated_value: [ "foo", "bar" ]
816
840
  // };
817
- value = parseOptionValue(parent, name + "." + token, depth + 1);
841
+ value = parseOptionValue(parent, name + "." + propName, depth + 1);
818
842
  } else if (peek() === "[") {
819
843
  value = [];
820
- var lastValue;
844
+ var lastValue,
845
+ lastValueIsAggregate;
821
846
  if (skip("[", true)) {
822
847
  if (!skip("]", true)) {
823
848
  do {
824
- lastValue = readValue(true);
849
+ lastValueIsAggregate = peek() === "{";
850
+ lastValue = lastValueIsAggregate
851
+ ? parseOptionValue(parent, name + "." + propName, depth + 1)
852
+ : readValue(true);
825
853
  value.push(lastValue);
826
854
  } while (skip(",", true));
827
855
  skip("]");
828
856
  if (typeof lastValue !== "undefined") {
829
- setOption(parent, name + "." + token, lastValue);
857
+ if (!lastValueIsAggregate)
858
+ setOption(parent, name + "." + propName, lastValue);
830
859
  }
831
860
  }
832
861
  }
833
862
  } else {
834
863
  value = readValue(true);
835
- setOption(parent, name + "." + token, value);
864
+ setOption(parent, name + "." + propName, value);
836
865
  }
837
866
 
838
867
  var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
@@ -853,7 +882,9 @@ function parse(source, root, options) {
853
882
  return objectResult;
854
883
  }
855
884
 
856
- var simpleValue = readValue(true);
885
+ var simpleValue = name === "default" && parent instanceof Field && integerTypeRe.test(parent.type)
886
+ ? parseInteger(next(), !unsignedTypeRe.test(parent.type))
887
+ : readValue(true);
857
888
  setOption(parent, name, simpleValue);
858
889
  return simpleValue;
859
890
  // Does not enforce a delimiter to be universal
package/src/reader.js CHANGED
@@ -395,9 +395,18 @@ Reader.prototype.double = function read_double() {
395
395
  */
396
396
  Reader.prototype.uint32s = function read_uint32s(array) {
397
397
  if (array === undefined) array = [];
398
- var end = this.uint32() + this.pos;
399
- while (this.pos < end)
400
- array.push(this.uint32());
398
+ var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
399
+ while (pos < end) {
400
+ value = buf[pos++];
401
+ if (value < 128)
402
+ array.push(value);
403
+ else {
404
+ this.pos = pos - 1;
405
+ array.push(this.uint32());
406
+ pos = this.pos;
407
+ }
408
+ }
409
+ this.pos = pos;
401
410
  return array;
402
411
  };
403
412
 
@@ -408,9 +417,18 @@ Reader.prototype.uint32s = function read_uint32s(array) {
408
417
  */
409
418
  Reader.prototype.int32s = function read_int32s(array) {
410
419
  if (array === undefined) array = [];
411
- var end = this.uint32() + this.pos;
412
- while (this.pos < end)
413
- array.push(this.int32());
420
+ var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
421
+ while (pos < end) {
422
+ value = buf[pos++];
423
+ if (value < 128)
424
+ array.push(value);
425
+ else {
426
+ this.pos = pos - 1;
427
+ array.push(this.int32());
428
+ pos = this.pos;
429
+ }
430
+ }
431
+ this.pos = pos;
414
432
  return array;
415
433
  };
416
434
 
@@ -434,9 +452,18 @@ Reader.prototype.sint32s = function read_sint32s(array) {
434
452
  */
435
453
  Reader.prototype.bools = function read_bools(array) {
436
454
  if (array === undefined) array = [];
437
- var end = this.uint32() + this.pos;
438
- while (this.pos < end)
439
- array.push(this.bool());
455
+ var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
456
+ while (pos < end) {
457
+ value = buf[pos++];
458
+ if (value < 128)
459
+ array.push(value !== 0);
460
+ else {
461
+ this.pos = pos - 1;
462
+ array.push(this.bool());
463
+ pos = this.pos;
464
+ }
465
+ }
466
+ this.pos = pos;
440
467
  return array;
441
468
  };
442
469
 
@@ -64,7 +64,9 @@ function codegen(functionParams, functionName) {
64
64
  formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
65
65
  var value = formatParams[formatOffset++];
66
66
  switch ($1) {
67
- case "d": case "f": return String(Number(value));
67
+ case "d": case "f":
68
+ value = Number(value);
69
+ return Object.is(value, -0) ? "-0" : String(value);
68
70
  case "i": return String(Math.floor(value));
69
71
  case "j": return JSON.stringify(value);
70
72
  case "s": return String(value);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  module.exports = LongBits;
3
3
 
4
- var util = require("../util/minimal");
4
+ var Long;
5
5
 
6
6
  /**
7
7
  * Constructs new long bits.
@@ -80,10 +80,10 @@ LongBits.fromNumber = function fromNumber(value) {
80
80
  LongBits.from = function from(value) {
81
81
  if (typeof value === "number")
82
82
  return LongBits.fromNumber(value);
83
- if (util.isString(value)) {
83
+ if (typeof value === "string" || value instanceof String) {
84
84
  /* istanbul ignore else */
85
- if (util.Long)
86
- value = util.Long.fromString(value);
85
+ if (Long)
86
+ value = Long.fromString(value);
87
87
  else
88
88
  return LongBits.fromNumber(parseInt(value, 10));
89
89
  }
@@ -112,8 +112,8 @@ LongBits.prototype.toNumber = function toNumber(unsigned) {
112
112
  * @returns {Long} Long
113
113
  */
114
114
  LongBits.prototype.toLong = function toLong(unsigned) {
115
- return util.Long
116
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
115
+ return Long
116
+ ? new Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
117
117
  /* istanbul ignore next */
118
118
  : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
119
119
  };
@@ -198,3 +198,7 @@ LongBits.prototype.length = function length() {
198
198
  : part1 < 2097152 ? 7 : 8
199
199
  : part2 < 128 ? 9 : 10;
200
200
  };
201
+
202
+ LongBits._configure = function(Long_) {
203
+ Long = Long_;
204
+ };
package/src/util/utf8.js CHANGED
@@ -6,7 +6,6 @@
6
6
  * @namespace
7
7
  */
8
8
  var utf8 = exports,
9
- replacementChar = "\ufffd",
10
9
  looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
11
10
  strictDecoder;
12
11
  var TEXT_DECODER_MIN_LENGTH = 64;
@@ -41,31 +40,6 @@ utf8.length = function utf8_length(string) {
41
40
  return len;
42
41
  };
43
42
 
44
- function utf8_read_js(buffer, start, end, str) {
45
- for (var i = start; i < end;) {
46
- var t = buffer[i++];
47
- if (t <= 0x7F) {
48
- str += String.fromCharCode(t);
49
- } else if (t >= 0xC0 && t < 0xE0) {
50
- var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
51
- str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
52
- } else if (t >= 0xE0 && t < 0xF0) {
53
- var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
54
- str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
55
- } else if (t >= 0xF0) {
56
- var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
57
- if (t2 < 0x10000 || t2 > 0x10FFFF)
58
- str += replacementChar;
59
- else {
60
- t2 -= 0x10000;
61
- str += String.fromCharCode(0xD800 + (t2 >> 10));
62
- str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
63
- }
64
- }
65
- }
66
- return str;
67
- }
68
-
69
43
  function utf8_read_decoder(decoder, buffer, start, end) {
70
44
  var source = start === 0 && end === buffer.length
71
45
  ? buffer
@@ -100,14 +74,14 @@ utf8.read = function utf8_read_loose(buffer, start, end) {
100
74
  c7 = buffer[i + 6];
101
75
  c8 = buffer[i + 7];
102
76
  if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
103
- return utf8_read_js(buffer, i, end, str);
77
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
104
78
  str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
105
79
  }
106
80
 
107
81
  for (; i < end; ++i) {
108
82
  c1 = buffer[i];
109
83
  if (c1 & 0x80)
110
- return utf8_read_js(buffer, i, end, str);
84
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
111
85
  str += String.fromCharCode(c1);
112
86
  }
113
87
 
package/src/writer.js CHANGED
@@ -26,7 +26,7 @@ function Writer() {
26
26
  * Backing buffer.
27
27
  * @type {Uint8Array}
28
28
  */
29
- this.buf = this.constructor.alloc(64);
29
+ this.buf = this.constructor.alloc(Writer.initialBufferSize);
30
30
 
31
31
  /**
32
32
  * Cached DataView over {@link Writer#buf}.
@@ -41,6 +41,12 @@ function Writer() {
41
41
  this.states = null;
42
42
  }
43
43
 
44
+ /**
45
+ * Initial backing buffer size in bytes. Defaults to 128.
46
+ * @type {number}
47
+ */
48
+ Writer.initialBufferSize = 128;
49
+
44
50
  /**
45
51
  * Current write position.
46
52
  * @name Writer#len