@nxtedition/slice 1.1.7 → 1.1.9
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/lib/index.d.ts +1 -0
- package/lib/index.js +10 -14
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class Slice {
|
|
|
10
10
|
byteLength: number;
|
|
11
11
|
maxByteLength: number;
|
|
12
12
|
static get EMPTY_BUF(): Buffer;
|
|
13
|
+
static from(buffer: Buffer, byteOffset?: number, byteLength?: number): Slice;
|
|
13
14
|
constructor(buffer?: Buffer<ArrayBufferLike>, byteOffset?: number, byteLength?: number, maxByteLength?: number);
|
|
14
15
|
reset(): void;
|
|
15
16
|
get length(): number;
|
package/lib/index.js
CHANGED
|
@@ -18,12 +18,7 @@ export class Slice {
|
|
|
18
18
|
return EMPTY_BUF
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
buffer = Slice.EMPTY_BUF,
|
|
23
|
-
byteOffset = 0,
|
|
24
|
-
byteLength = buffer.byteLength,
|
|
25
|
-
maxByteLength = byteLength,
|
|
26
|
-
) {
|
|
21
|
+
static from(buffer , byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
27
22
|
if (!(buffer instanceof Buffer)) {
|
|
28
23
|
throw new TypeError('buffer must be a Buffer')
|
|
29
24
|
}
|
|
@@ -36,20 +31,21 @@ export class Slice {
|
|
|
36
31
|
throw new RangeError(`Invalid byteLength: ${byteLength}`)
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
if (
|
|
40
|
-
maxByteLength < byteLength ||
|
|
41
|
-
maxByteLength > buffer.byteLength ||
|
|
42
|
-
!Number.isInteger(maxByteLength)
|
|
43
|
-
) {
|
|
44
|
-
throw new RangeError(`Invalid maxByteLength: ${maxByteLength}`)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
34
|
if (byteOffset + byteLength > buffer.byteLength) {
|
|
48
35
|
throw new RangeError(
|
|
49
36
|
`byteOffset + byteLength (${byteOffset + byteLength}) exceeds buffer size (${buffer.byteLength})`,
|
|
50
37
|
)
|
|
51
38
|
}
|
|
52
39
|
|
|
40
|
+
return new Slice(buffer, byteOffset, byteLength)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
constructor(
|
|
44
|
+
buffer = Slice.EMPTY_BUF,
|
|
45
|
+
byteOffset = 0,
|
|
46
|
+
byteLength = buffer.byteLength,
|
|
47
|
+
maxByteLength = byteLength,
|
|
48
|
+
) {
|
|
53
49
|
this.buffer = buffer
|
|
54
50
|
this.byteOffset = byteOffset
|
|
55
51
|
this.byteLength = byteLength
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/slice",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"tsd": "^0.33.0",
|
|
31
31
|
"typescript": "^5.9.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2c131da7ca8ea328fd681e975dd7caf57f9f4896"
|
|
34
34
|
}
|