@nuintun/buffer 0.7.0 → 0.7.2
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/cjs/binary.cjs +1 -1
- package/cjs/encoding.cjs +1 -1
- package/cjs/enum.cjs +1 -1
- package/cjs/errors.cjs +4 -1
- package/cjs/index.cjs +12 -10
- package/cjs/utils.cjs +1 -1
- package/esm/binary.js +1 -1
- package/esm/encoding.js +1 -1
- package/esm/enum.js +1 -1
- package/esm/errors.js +4 -2
- package/esm/index.js +13 -11
- package/esm/utils.js +1 -1
- package/package.json +3 -3
package/cjs/binary.cjs
CHANGED
package/cjs/encoding.cjs
CHANGED
package/cjs/enum.cjs
CHANGED
package/cjs/errors.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package @nuintun/buffer
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.7.
|
|
4
|
+
* @version 0.7.2
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A buffer tool for javascript.
|
|
7
7
|
* @see https://github.com/nuintun/Buffer#readme
|
|
@@ -30,10 +30,13 @@ const unknownEndianness = 'unknown endianness';
|
|
|
30
30
|
const readLengthInvalid = 'invalid read length';
|
|
31
31
|
// 数据读取溢出
|
|
32
32
|
const readOverflow = 'read is outside the bounds of the Buffer';
|
|
33
|
+
// 读写指针溢出
|
|
34
|
+
const offsetOverflow = 'offset is outside the bounds of the Buffer';
|
|
33
35
|
|
|
34
36
|
exports.encodingInvalid = encodingInvalid;
|
|
35
37
|
exports.lengthInvalid = lengthInvalid;
|
|
36
38
|
exports.offsetInvalid = offsetInvalid;
|
|
39
|
+
exports.offsetOverflow = offsetOverflow;
|
|
37
40
|
exports.readLengthInvalid = readLengthInvalid;
|
|
38
41
|
exports.readOverflow = readOverflow;
|
|
39
42
|
exports.unknownEndianness = unknownEndianness;
|
package/cjs/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package @nuintun/buffer
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.7.
|
|
4
|
+
* @version 0.7.2
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A buffer tool for javascript.
|
|
7
7
|
* @see https://github.com/nuintun/Buffer#readme
|
|
@@ -84,9 +84,6 @@ class Buffer {
|
|
|
84
84
|
* @param {number} offset 指针位置
|
|
85
85
|
*/
|
|
86
86
|
#seek(offset) {
|
|
87
|
-
if (offset > this.#length) {
|
|
88
|
-
this.#length = offset;
|
|
89
|
-
}
|
|
90
87
|
this.#offset = offset;
|
|
91
88
|
}
|
|
92
89
|
/**
|
|
@@ -102,10 +99,10 @@ class Buffer {
|
|
|
102
99
|
* @private
|
|
103
100
|
* @method assertRead
|
|
104
101
|
* @description 读取断言,防止越界读取
|
|
105
|
-
* @param {number}
|
|
102
|
+
* @param {number} offset 断言字节长度
|
|
106
103
|
*/
|
|
107
|
-
#assertRead(
|
|
108
|
-
if (
|
|
104
|
+
#assertRead(offset) {
|
|
105
|
+
if (offset > this.#length) {
|
|
109
106
|
throw new RangeError(errors.readOverflow);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
@@ -123,6 +120,9 @@ class Buffer {
|
|
|
123
120
|
this.#bytes = newBytes;
|
|
124
121
|
this.#dataView = new DataView(newBytes.buffer);
|
|
125
122
|
}
|
|
123
|
+
if (length > this.#length) {
|
|
124
|
+
this.#length = length;
|
|
125
|
+
}
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* @public
|
|
@@ -134,6 +134,9 @@ class Buffer {
|
|
|
134
134
|
if (!utils.isNaturalNumber(offset)) {
|
|
135
135
|
throw new RangeError(errors.offsetInvalid);
|
|
136
136
|
}
|
|
137
|
+
if (offset > this.#length) {
|
|
138
|
+
throw new RangeError(errors.offsetOverflow);
|
|
139
|
+
}
|
|
137
140
|
this.#offset = offset;
|
|
138
141
|
}
|
|
139
142
|
/**
|
|
@@ -156,9 +159,8 @@ class Buffer {
|
|
|
156
159
|
if (!utils.isNaturalNumber(length)) {
|
|
157
160
|
throw new RangeError(errors.lengthInvalid);
|
|
158
161
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.#alloc(length - currentLength);
|
|
162
|
+
if (length > this.#length) {
|
|
163
|
+
this.#alloc(length);
|
|
162
164
|
} else {
|
|
163
165
|
this.#length = length;
|
|
164
166
|
// 重置多余字节
|
package/cjs/utils.cjs
CHANGED
package/esm/binary.js
CHANGED
package/esm/encoding.js
CHANGED
package/esm/enum.js
CHANGED
package/esm/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package @nuintun/buffer
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.7.
|
|
4
|
+
* @version 0.7.2
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A buffer tool for javascript.
|
|
7
7
|
* @see https://github.com/nuintun/Buffer#readme
|
|
@@ -28,5 +28,7 @@ const unknownEndianness = 'unknown endianness';
|
|
|
28
28
|
const readLengthInvalid = 'invalid read length';
|
|
29
29
|
// 数据读取溢出
|
|
30
30
|
const readOverflow = 'read is outside the bounds of the Buffer';
|
|
31
|
+
// 读写指针溢出
|
|
32
|
+
const offsetOverflow = 'offset is outside the bounds of the Buffer';
|
|
31
33
|
|
|
32
|
-
export { encodingInvalid, lengthInvalid, offsetInvalid, readLengthInvalid, readOverflow, unknownEndianness };
|
|
34
|
+
export { encodingInvalid, lengthInvalid, offsetInvalid, offsetOverflow, readLengthInvalid, readOverflow, unknownEndianness };
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package @nuintun/buffer
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.7.
|
|
4
|
+
* @version 0.7.2
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A buffer tool for javascript.
|
|
7
7
|
* @see https://github.com/nuintun/Buffer#readme
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { unknownEndianness, readOverflow, offsetInvalid, lengthInvalid, readLengthInvalid } from './errors.js';
|
|
10
|
+
import { unknownEndianness, readOverflow, offsetInvalid, offsetOverflow, lengthInvalid, readLengthInvalid } from './errors.js';
|
|
11
11
|
import { mapping } from './binary.js';
|
|
12
12
|
import { Endian } from './enum.js';
|
|
13
13
|
import { encode, decode } from './encoding.js';
|
|
@@ -82,9 +82,6 @@ class Buffer {
|
|
|
82
82
|
* @param {number} offset 指针位置
|
|
83
83
|
*/
|
|
84
84
|
#seek(offset) {
|
|
85
|
-
if (offset > this.#length) {
|
|
86
|
-
this.#length = offset;
|
|
87
|
-
}
|
|
88
85
|
this.#offset = offset;
|
|
89
86
|
}
|
|
90
87
|
/**
|
|
@@ -100,10 +97,10 @@ class Buffer {
|
|
|
100
97
|
* @private
|
|
101
98
|
* @method assertRead
|
|
102
99
|
* @description 读取断言,防止越界读取
|
|
103
|
-
* @param {number}
|
|
100
|
+
* @param {number} offset 断言字节长度
|
|
104
101
|
*/
|
|
105
|
-
#assertRead(
|
|
106
|
-
if (
|
|
102
|
+
#assertRead(offset) {
|
|
103
|
+
if (offset > this.#length) {
|
|
107
104
|
throw new RangeError(readOverflow);
|
|
108
105
|
}
|
|
109
106
|
}
|
|
@@ -121,6 +118,9 @@ class Buffer {
|
|
|
121
118
|
this.#bytes = newBytes;
|
|
122
119
|
this.#dataView = new DataView(newBytes.buffer);
|
|
123
120
|
}
|
|
121
|
+
if (length > this.#length) {
|
|
122
|
+
this.#length = length;
|
|
123
|
+
}
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* @public
|
|
@@ -132,6 +132,9 @@ class Buffer {
|
|
|
132
132
|
if (!isNaturalNumber(offset)) {
|
|
133
133
|
throw new RangeError(offsetInvalid);
|
|
134
134
|
}
|
|
135
|
+
if (offset > this.#length) {
|
|
136
|
+
throw new RangeError(offsetOverflow);
|
|
137
|
+
}
|
|
135
138
|
this.#offset = offset;
|
|
136
139
|
}
|
|
137
140
|
/**
|
|
@@ -154,9 +157,8 @@ class Buffer {
|
|
|
154
157
|
if (!isNaturalNumber(length)) {
|
|
155
158
|
throw new RangeError(lengthInvalid);
|
|
156
159
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.#alloc(length - currentLength);
|
|
160
|
+
if (length > this.#length) {
|
|
161
|
+
this.#alloc(length);
|
|
160
162
|
} else {
|
|
161
163
|
this.#length = length;
|
|
162
164
|
// 重置多余字节
|
package/esm/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuintun/buffer",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "A buffer tool for javascript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
39
39
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
40
|
-
"dts-paths": "^1.1.
|
|
40
|
+
"dts-paths": "^1.1.11",
|
|
41
41
|
"magic-string": "^0.30.17",
|
|
42
42
|
"prettier": "^3.6.2",
|
|
43
43
|
"rimraf": "^6.0.1",
|
|
44
44
|
"rollup": "^4.46.2",
|
|
45
|
-
"typescript": "^5.
|
|
45
|
+
"typescript": "^5.9.2"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"lint": "tsc --noEmit",
|