bin-serde 1.7.5 → 1.7.6
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 +3 -2
- package/lib/index.js +2 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ let slabOffset = 0;
|
|
|
9
9
|
|
|
10
10
|
const f32 = new Float32Array(1);
|
|
11
11
|
const f32u8 = new Uint8Array(f32.buffer);
|
|
12
|
+
const copyBuffer =
|
|
13
|
+
typeof Buffer !== "undefined" ? (buf: Uint8Array) => Buffer.from(buf) : (buf: Uint8Array) => buf.slice();
|
|
12
14
|
|
|
13
15
|
function allocFromSlab(size: number): Uint8Array {
|
|
14
16
|
if (size > MAX_POOLED) {
|
|
@@ -154,8 +156,7 @@ export class Writer {
|
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
toBuffer() {
|
|
157
|
-
|
|
158
|
-
return typeof Buffer !== "undefined" ? Buffer.from(view) : view.slice();
|
|
159
|
+
return copyBuffer(this.bytes.subarray(0, this.pos));
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
reset() {
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ let slab = allocUint8Array(SLAB_SIZE);
|
|
|
6
6
|
let slabOffset = 0;
|
|
7
7
|
const f32 = new Float32Array(1);
|
|
8
8
|
const f32u8 = new Uint8Array(f32.buffer);
|
|
9
|
+
const copyBuffer = typeof Buffer !== "undefined" ? (buf) => Buffer.from(buf) : (buf) => buf.slice();
|
|
9
10
|
function allocFromSlab(size) {
|
|
10
11
|
if (size > MAX_POOLED) {
|
|
11
12
|
// Too large for pool, allocate directly
|
|
@@ -136,8 +137,7 @@ export class Writer {
|
|
|
136
137
|
return this;
|
|
137
138
|
}
|
|
138
139
|
toBuffer() {
|
|
139
|
-
|
|
140
|
-
return typeof Buffer !== "undefined" ? Buffer.from(view) : view.slice();
|
|
140
|
+
return copyBuffer(this.bytes.subarray(0, this.pos));
|
|
141
141
|
}
|
|
142
142
|
reset() {
|
|
143
143
|
this.pos = 0;
|