bin-serde 1.7.3 → 1.7.4

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,13 @@ export class Writer {
154
154
  }
155
155
 
156
156
  toBuffer() {
157
- return this.bytes.subarray(0, this.pos);
157
+ return typeof Buffer !== "undefined"
158
+ ? Buffer.from(this.bytes.buffer, this.bytes.byteOffset, this.pos)
159
+ : this.bytes.slice(0, this.pos);
158
160
  }
159
161
 
160
- reset(): this {
162
+ reset() {
161
163
  this.pos = 0;
162
- this.bytes = allocFromSlab(this.bytes.length);
163
- this._view = null;
164
164
  return this;
165
165
  }
166
166
 
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<ArrayBufferLike>;
18
18
  reset(): this;
19
19
  get size(): number;
20
20
  private ensureSize;
package/lib/index.js CHANGED
@@ -136,12 +136,12 @@ export class Writer {
136
136
  return this;
137
137
  }
138
138
  toBuffer() {
139
- return this.bytes.subarray(0, this.pos);
139
+ return typeof Buffer !== "undefined"
140
+ ? Buffer.from(this.bytes.buffer, this.bytes.byteOffset, this.pos)
141
+ : this.bytes.slice(0, this.pos);
140
142
  }
141
143
  reset() {
142
144
  this.pos = 0;
143
- this.bytes = allocFromSlab(this.bytes.length);
144
- this._view = null;
145
145
  return this;
146
146
  }
147
147
  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.4",
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",