bin-serde 1.7.3 → 1.7.5

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/index.ts CHANGED
@@ -154,13 +154,12 @@ export class Writer {
154
154
  }
155
155
 
156
156
  toBuffer() {
157
- return this.bytes.subarray(0, this.pos);
157
+ const view = this.bytes.subarray(0, this.pos);
158
+ return typeof Buffer !== "undefined" ? Buffer.from(view) : view.slice();
158
159
  }
159
160
 
160
- reset(): this {
161
+ reset() {
161
162
  this.pos = 0;
162
- this.bytes = allocFromSlab(this.bytes.length);
163
- this._view = null;
164
163
  return this;
165
164
  }
166
165
 
package/lib/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare class Writer {
14
14
  writeStringUtf8(val: string, len?: number): this;
15
15
  writeBuffer(buf: Uint8Array): this;
16
16
  concat(other: Writer): this;
17
- toBuffer(): Uint8Array<ArrayBufferLike>;
17
+ toBuffer(): Uint8Array<ArrayBuffer> | Buffer<ArrayBuffer>;
18
18
  reset(): this;
19
19
  get size(): number;
20
20
  private ensureSize;
package/lib/index.js CHANGED
@@ -136,12 +136,11 @@ export class Writer {
136
136
  return this;
137
137
  }
138
138
  toBuffer() {
139
- return this.bytes.subarray(0, this.pos);
139
+ const view = this.bytes.subarray(0, this.pos);
140
+ return typeof Buffer !== "undefined" ? Buffer.from(view) : view.slice();
140
141
  }
141
142
  reset() {
142
143
  this.pos = 0;
143
- this.bytes = allocFromSlab(this.bytes.length);
144
- this._view = null;
145
144
  return this;
146
145
  }
147
146
  get size() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bin-serde",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "A low level library for efficiently writing and reading binary data in javascript",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",