extended-buffer 7.1.2 → 7.2.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.
- package/dist/ExtendedBuffer.d.ts +5 -4
- package/dist/ExtendedBuffer.js +12 -10
- package/package.json +1 -1
package/dist/ExtendedBuffer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ExtendedBufferOptions } from './ExtendedBufferOptions';
|
|
3
|
-
export declare class ExtendedBuffer {
|
|
3
|
+
export declare class ExtendedBuffer<EBO extends ExtendedBufferOptions = ExtendedBufferOptions> {
|
|
4
4
|
protected _pointer: number;
|
|
5
5
|
protected _pointerEnd: number;
|
|
6
6
|
protected _pointerStart: number;
|
|
@@ -10,7 +10,8 @@ export declare class ExtendedBuffer {
|
|
|
10
10
|
protected readonly _nativeAllocSlow?: boolean;
|
|
11
11
|
protected readonly _nativeReallocSlow?: boolean;
|
|
12
12
|
constructor(options?: ExtendedBufferOptions);
|
|
13
|
-
protected
|
|
13
|
+
protected createInstanceOptions(options?: ExtendedBufferOptions): ExtendedBufferOptions;
|
|
14
|
+
protected createInstance(options?: EBO): this;
|
|
14
15
|
get length(): number;
|
|
15
16
|
get capacity(): number;
|
|
16
17
|
get pointer(): number;
|
|
@@ -33,7 +34,7 @@ export declare class ExtendedBuffer {
|
|
|
33
34
|
getPointer(): number;
|
|
34
35
|
offset(offset: number): this;
|
|
35
36
|
isReadable(size: number): boolean;
|
|
36
|
-
writeBuffer(value: Buffer | ExtendedBuffer
|
|
37
|
+
writeBuffer(value: Buffer | ExtendedBuffer<ExtendedBufferOptions>, unshift?: boolean): this;
|
|
37
38
|
writeString(string: string, encoding?: BufferEncoding, unshift?: boolean): this;
|
|
38
39
|
writeIntBE(value: number, size: number, unshift?: boolean): this;
|
|
39
40
|
writeIntLE(value: number, size: number, unshift?: boolean): this;
|
|
@@ -55,7 +56,7 @@ export declare class ExtendedBuffer {
|
|
|
55
56
|
writeDoubleLE(value: number, unshift?: boolean): this;
|
|
56
57
|
readBuffer(size: number): this;
|
|
57
58
|
readBuffer(size: number, asNative: true): Buffer;
|
|
58
|
-
readBuffer(size: number, asNative: false, bufferOptions?:
|
|
59
|
+
readBuffer(size: number, asNative: false, bufferOptions?: EBO): this;
|
|
59
60
|
readString(size: number, encoding?: BufferEncoding): string;
|
|
60
61
|
readIntBE(size: number): number;
|
|
61
62
|
readIntLE(size: number): number;
|
package/dist/ExtendedBuffer.js
CHANGED
|
@@ -27,28 +27,30 @@ exports.ExtendedBuffer = void 0;
|
|
|
27
27
|
const buffer_1 = require("buffer");
|
|
28
28
|
const utils = __importStar(require("./utils"));
|
|
29
29
|
const errors_1 = require("./errors");
|
|
30
|
-
const
|
|
31
|
-
const
|
|
30
|
+
const DEFAULT_CAPACITY = 16 * 1024;
|
|
31
|
+
const DEFAULT_CAPACITY_STEP = DEFAULT_CAPACITY;
|
|
32
32
|
class ExtendedBuffer {
|
|
33
33
|
constructor(options) {
|
|
34
34
|
var _a, _b;
|
|
35
35
|
this._nativeAllocSlow = options === null || options === void 0 ? void 0 : options.nativeAllocSlow;
|
|
36
36
|
this._nativeReallocSlow = options === null || options === void 0 ? void 0 : options.nativeReallocSlow;
|
|
37
|
-
this._capacity = (_a = options === null || options === void 0 ? void 0 : options.capacity) !== null && _a !== void 0 ? _a :
|
|
38
|
-
this._capacityStep = (_b = options === null || options === void 0 ? void 0 : options.capacityStep) !== null && _b !== void 0 ? _b :
|
|
37
|
+
this._capacity = (_a = options === null || options === void 0 ? void 0 : options.capacity) !== null && _a !== void 0 ? _a : DEFAULT_CAPACITY;
|
|
38
|
+
this._capacityStep = (_b = options === null || options === void 0 ? void 0 : options.capacityStep) !== null && _b !== void 0 ? _b : DEFAULT_CAPACITY_STEP;
|
|
39
39
|
utils.assertUnsignedInteger(this._capacity);
|
|
40
40
|
utils.assertUnsignedInteger(this._capacityStep);
|
|
41
41
|
this.initExtendedBuffer();
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
createInstanceOptions(options) {
|
|
44
|
+
return Object.assign({
|
|
45
45
|
capacity: this._capacity,
|
|
46
46
|
capacityStep: this._capacityStep,
|
|
47
47
|
nativeAllocSlow: this._nativeAllocSlow,
|
|
48
48
|
nativeReallocSlow: this._nativeReallocSlow
|
|
49
49
|
}, options !== null && options !== void 0 ? options : {});
|
|
50
|
+
}
|
|
51
|
+
createInstance(options) {
|
|
50
52
|
const ThisClass = this.constructor;
|
|
51
|
-
return new ThisClass(options);
|
|
53
|
+
return new ThisClass(this.createInstanceOptions(options));
|
|
52
54
|
}
|
|
53
55
|
get length() {
|
|
54
56
|
return this._pointerEnd - this._pointerStart;
|
|
@@ -195,10 +197,10 @@ class ExtendedBuffer {
|
|
|
195
197
|
return this.getReadableSize() >= size;
|
|
196
198
|
}
|
|
197
199
|
writeBuffer(value, unshift) {
|
|
198
|
-
if (value instanceof
|
|
199
|
-
return this.writeNativeBuffer(value, unshift);
|
|
200
|
+
if (value instanceof ExtendedBuffer) {
|
|
201
|
+
return this.writeNativeBuffer(value.nativeBufferView, unshift);
|
|
200
202
|
}
|
|
201
|
-
return this.writeNativeBuffer(value
|
|
203
|
+
return this.writeNativeBuffer(value, unshift);
|
|
202
204
|
}
|
|
203
205
|
writeString(string, encoding, unshift) {
|
|
204
206
|
const bytes = buffer_1.Buffer.from(string, encoding);
|