@nuintun/buffer 0.1.0
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/LICENSE +21 -0
- package/README.md +310 -0
- package/cjs/Binary.cjs +25 -0
- package/cjs/Binary.d.cts +8 -0
- package/cjs/Encoding/UTF8.cjs +33 -0
- package/cjs/Encoding/UTF8.d.cts +15 -0
- package/cjs/Encoding/Unicode.cjs +45 -0
- package/cjs/Encoding/Unicode.d.cts +18 -0
- package/cjs/Encoding/index.cjs +65 -0
- package/cjs/Encoding/index.d.cts +19 -0
- package/cjs/enum.d.cts +15 -0
- package/cjs/errors.cjs +35 -0
- package/cjs/errors.d.cts +9 -0
- package/cjs/index.cjs +559 -0
- package/cjs/index.d.cts +281 -0
- package/cjs/utils.cjs +31 -0
- package/cjs/utils.d.cts +11 -0
- package/esm/Binary.d.ts +8 -0
- package/esm/Binary.js +23 -0
- package/esm/Encoding/UTF8.d.ts +15 -0
- package/esm/Encoding/UTF8.js +30 -0
- package/esm/Encoding/Unicode.d.ts +18 -0
- package/esm/Encoding/Unicode.js +42 -0
- package/esm/Encoding/index.d.ts +19 -0
- package/esm/Encoding/index.js +62 -0
- package/esm/enum.d.ts +15 -0
- package/esm/errors.d.ts +9 -0
- package/esm/errors.js +28 -0
- package/esm/index.d.ts +281 -0
- package/esm/index.js +568 -0
- package/esm/utils.d.ts +11 -0
- package/esm/utils.js +29 -0
- package/package.json +61 -0
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Buffer
|
|
3
|
+
*/
|
|
4
|
+
export declare enum Endian {
|
|
5
|
+
Big = 0,
|
|
6
|
+
Little = 1
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @function endianness
|
|
10
|
+
* @description 获取系统默认字节序
|
|
11
|
+
* @returns {Endian}
|
|
12
|
+
*/
|
|
13
|
+
export declare function endianness(): Endian;
|
|
14
|
+
/**
|
|
15
|
+
* @class Buffer
|
|
16
|
+
* @classdesc Buffer 类提供用于优化读取,写入以及处理二进制数据的方法和属性
|
|
17
|
+
*/
|
|
18
|
+
export declare class Buffer {
|
|
19
|
+
#private;
|
|
20
|
+
/**
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param {number} [length] 缓冲区初始大小
|
|
23
|
+
* @param {number} [pageSize] 缓冲区分页大小,扩容时将按分页大小增加
|
|
24
|
+
*/
|
|
25
|
+
constructor(length?: number, pageSize?: number);
|
|
26
|
+
/**
|
|
27
|
+
* @constructor
|
|
28
|
+
* @param {Uint8Array} bytes 缓冲区初始数据
|
|
29
|
+
* @param {number} [pageSize] 缓冲区分页大小,扩容时将按分页大小增加
|
|
30
|
+
*/
|
|
31
|
+
constructor(bytes?: Uint8Array, pageSize?: number);
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
* @property {number} offset
|
|
35
|
+
* @description 设置读写指针位置,以字节为单位
|
|
36
|
+
* @description 下一次调用读写方法时将在此位置开始读写
|
|
37
|
+
*/
|
|
38
|
+
set offset(offset: number);
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
* @property {number} offset
|
|
42
|
+
* @description 获取读写指针的位置
|
|
43
|
+
* @returns {number}
|
|
44
|
+
*/
|
|
45
|
+
get offset(): number;
|
|
46
|
+
/**
|
|
47
|
+
* @public
|
|
48
|
+
* @property {number} length
|
|
49
|
+
* @description 设置 Buffer 长度
|
|
50
|
+
* @description 如果将长度设置为小于当前长度的值,将会截断该字节数组
|
|
51
|
+
* @description 如果将长度设置为大于当前长度的值,则用零填充字节数组的右侧
|
|
52
|
+
*/
|
|
53
|
+
set length(length: number);
|
|
54
|
+
/**
|
|
55
|
+
* @public
|
|
56
|
+
* @property {number} length
|
|
57
|
+
* @description 获取 Buffer 长度
|
|
58
|
+
* @returns {number}
|
|
59
|
+
*/
|
|
60
|
+
get length(): number;
|
|
61
|
+
/**
|
|
62
|
+
* @public
|
|
63
|
+
* @property {ArrayBuffer} buffer
|
|
64
|
+
* @description 获取 ArrayBuffer 缓冲区
|
|
65
|
+
* @returns {ArrayBuffer}
|
|
66
|
+
*/
|
|
67
|
+
get buffer(): ArrayBuffer;
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
* @property {Uint8Array} bytes
|
|
71
|
+
* @description 获取 Uint8Array 缓冲区
|
|
72
|
+
* @returns {Uint8Array}
|
|
73
|
+
*/
|
|
74
|
+
get bytes(): Uint8Array;
|
|
75
|
+
/**
|
|
76
|
+
* @public
|
|
77
|
+
* @method writeInt8
|
|
78
|
+
* @description 在缓冲区中写入一个有符号整数
|
|
79
|
+
* @param {number} value 介于 -128 和 127 之间的整数
|
|
80
|
+
*/
|
|
81
|
+
writeInt8(value: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* @public
|
|
84
|
+
* @method writeUint8
|
|
85
|
+
* @description 在缓冲区中写入一个无符号整数
|
|
86
|
+
* @param {number} value 介于 0 和 255 之间的整数
|
|
87
|
+
*/
|
|
88
|
+
writeUint8(value: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* @method writeBoolean
|
|
91
|
+
* @description 在缓冲区中写入布尔值,true 写 1,false写 0
|
|
92
|
+
* @param {boolean} value 布尔值
|
|
93
|
+
*/
|
|
94
|
+
writeBoolean(value: boolean): void;
|
|
95
|
+
/**
|
|
96
|
+
* @method writeInt16
|
|
97
|
+
* @description 在缓冲区中写入一个 16 位有符号整数
|
|
98
|
+
* @param {number} value 要写入的 16 位有符号整数
|
|
99
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
100
|
+
*/
|
|
101
|
+
writeInt16(value: number, littleEndian?: boolean): void;
|
|
102
|
+
/**
|
|
103
|
+
* @method writeUint16
|
|
104
|
+
* @description 在缓冲区中写入一个 16 位无符号整数
|
|
105
|
+
* @param {number} value 要写入的 16 位无符号整数
|
|
106
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
107
|
+
*/
|
|
108
|
+
writeUint16(value: number, littleEndian?: boolean): void;
|
|
109
|
+
/**
|
|
110
|
+
* @method writeInt32
|
|
111
|
+
* @description 在缓冲区中写入一个有符号的 32 位有符号整数
|
|
112
|
+
* @param {number} value 要写入的 32 位有符号整数
|
|
113
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
114
|
+
*/
|
|
115
|
+
writeInt32(value: number, littleEndian?: boolean): void;
|
|
116
|
+
/**
|
|
117
|
+
* @method writeUint32
|
|
118
|
+
* @description 在缓冲区中写入一个无符号的 32 位无符号整数
|
|
119
|
+
* @param {number} value 要写入的 32 位无符号整数
|
|
120
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
121
|
+
*/
|
|
122
|
+
writeUint32(value: number, littleEndian?: boolean): void;
|
|
123
|
+
/**
|
|
124
|
+
* @method writeInt64
|
|
125
|
+
* @description 在缓冲区中写入一个无符号的 64 位有符号整数
|
|
126
|
+
* @param {bigint} value 要写入的 32 位有符号整数
|
|
127
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
128
|
+
*/
|
|
129
|
+
writeInt64(value: bigint, littleEndian?: boolean): void;
|
|
130
|
+
/**
|
|
131
|
+
* @method writeUint64
|
|
132
|
+
* @description 在缓冲区中写入一个无符号的 64 位无符号整数
|
|
133
|
+
* @param {bigint} value 要写入的 64 位无符号整数
|
|
134
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
135
|
+
*/
|
|
136
|
+
writeUint64(value: bigint, littleEndian?: boolean): void;
|
|
137
|
+
/**
|
|
138
|
+
* @method writeFloat32
|
|
139
|
+
* @description 在缓冲区中写入一个 IEEE 754 单精度 32 位浮点数
|
|
140
|
+
* @param {number} value 单精度 32 位浮点数
|
|
141
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
142
|
+
*/
|
|
143
|
+
writeFloat32(value: number, littleEndian?: boolean): void;
|
|
144
|
+
/**
|
|
145
|
+
* @method writeFloat64
|
|
146
|
+
* @description 在缓冲区中写入一个 IEEE 754 双精度 64 位浮点数
|
|
147
|
+
* @param {number} value 双精度 64 位浮点数
|
|
148
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
149
|
+
*/
|
|
150
|
+
writeFloat64(value: number, littleEndian?: boolean): void;
|
|
151
|
+
/**
|
|
152
|
+
* @method write
|
|
153
|
+
* @description 将字符串用指定编码写入字节流
|
|
154
|
+
* @param {string} value 要写入的字符串
|
|
155
|
+
* @param {string} [encoding] 字符串编码
|
|
156
|
+
*/
|
|
157
|
+
write(value: string, encoding?: string): void;
|
|
158
|
+
/**
|
|
159
|
+
* @method write
|
|
160
|
+
* @description 将 Uint8Array 对象写入字节流
|
|
161
|
+
* @param {Uint8Array} bytes 要写入 Uint8Array 对象
|
|
162
|
+
* @param {number} [start] Uint8Array 对象开始索引
|
|
163
|
+
* @param {number} [end] Uint8Array 对象结束索引
|
|
164
|
+
*/
|
|
165
|
+
write(bytes: Uint8Array, start?: number, end?: number): void;
|
|
166
|
+
/**
|
|
167
|
+
* @method readInt8
|
|
168
|
+
* @description 从缓冲区中读取有符号的整数
|
|
169
|
+
* @returns {number} 介于 -128 和 127 之间的整数
|
|
170
|
+
*/
|
|
171
|
+
readInt8(): number;
|
|
172
|
+
/**
|
|
173
|
+
* @method readUint8
|
|
174
|
+
* @description 从缓冲区中读取无符号的整数
|
|
175
|
+
* @returns {number} 介于 0 和 255 之间的无符号整数
|
|
176
|
+
*/
|
|
177
|
+
readUint8(): number;
|
|
178
|
+
/**
|
|
179
|
+
* @method readBoolean
|
|
180
|
+
* @description 从缓冲区中读取布尔值
|
|
181
|
+
* @returns {boolean} 如果字节非零,则返回 true,否则返回 false
|
|
182
|
+
*/
|
|
183
|
+
readBoolean(): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* @method readInt16
|
|
186
|
+
* @description 从缓冲区中读取一个 16 位有符号整数
|
|
187
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
188
|
+
* @returns {number} 介于 -32768 和 32767 之间的 16 位有符号整数
|
|
189
|
+
*/
|
|
190
|
+
readInt16(littleEndian?: boolean): number;
|
|
191
|
+
/**
|
|
192
|
+
* @method readUint16
|
|
193
|
+
* @description 从缓冲区中读取一个 16 位无符号整数
|
|
194
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
195
|
+
* @returns {number} 介于 0 和 65535 之间的 16 位无符号整数
|
|
196
|
+
*/
|
|
197
|
+
readUint16(littleEndian?: boolean): number;
|
|
198
|
+
/**
|
|
199
|
+
* @method readInt32
|
|
200
|
+
* @description 从缓冲区中读取一个 32 位有符号整数
|
|
201
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
202
|
+
* @returns {number} 介于 -2147483648 和 2147483647 之间的 32 位有符号整数
|
|
203
|
+
*/
|
|
204
|
+
readInt32(littleEndian?: boolean): number;
|
|
205
|
+
/**
|
|
206
|
+
* @method readUint32
|
|
207
|
+
* @description 从缓冲区中读取一个 32 位无符号整数
|
|
208
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
209
|
+
* @returns {number} 介于 0 和 4294967295 之间的 32 位无符号整数
|
|
210
|
+
*/
|
|
211
|
+
readUint32(littleEndian?: boolean): number;
|
|
212
|
+
/**
|
|
213
|
+
* @method readInt64
|
|
214
|
+
* @description 从缓冲区中读取一个 64 位有符号整数
|
|
215
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
216
|
+
* @returns {bigint} 介于 -9223372036854775808 和 9223372036854775807 之间的 64 位有符号整数
|
|
217
|
+
*/
|
|
218
|
+
readInt64(littleEndian?: boolean): bigint;
|
|
219
|
+
/**
|
|
220
|
+
* @method readUint64
|
|
221
|
+
* @description 从缓冲区中读取一个 64 位无符号整数
|
|
222
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
223
|
+
* @returns {bigint} 介于 0 和 18446744073709551615 之间的 64 位无符号整数
|
|
224
|
+
*/
|
|
225
|
+
readUint64(littleEndian?: boolean): bigint;
|
|
226
|
+
/**
|
|
227
|
+
* @method readFloat32
|
|
228
|
+
* @description 从缓冲区中读取一个 IEEE 754 单精度 32 位浮点数
|
|
229
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
230
|
+
* @returns {number} 单精度 32 位浮点数
|
|
231
|
+
*/
|
|
232
|
+
readFloat32(littleEndian?: boolean): number;
|
|
233
|
+
/**
|
|
234
|
+
* @method readFloat64
|
|
235
|
+
* @description 从缓冲区中读取一个 IEEE 754 双精度 64 位浮点数
|
|
236
|
+
* @param {boolean} [littleEndian] 是否为小端字节序
|
|
237
|
+
* @returns {number} 双精度 64 位浮点数
|
|
238
|
+
*/
|
|
239
|
+
readFloat64(littleEndian?: boolean): number;
|
|
240
|
+
/**
|
|
241
|
+
* @method read
|
|
242
|
+
* @description 从缓冲区中读取指定长度的 Uint8Array 对象
|
|
243
|
+
* @param {number} length 读取的字节长度
|
|
244
|
+
* @returns {Uint8Array}
|
|
245
|
+
*/
|
|
246
|
+
read(length: number): Uint8Array;
|
|
247
|
+
/**
|
|
248
|
+
* @method read
|
|
249
|
+
* @description 从缓冲区中读取一个字符串
|
|
250
|
+
* @param {number} length 读取的字节长度
|
|
251
|
+
* @param {string} encoding 字符串编码
|
|
252
|
+
* @returns {string} 指定编码的字符串
|
|
253
|
+
*/
|
|
254
|
+
read(length: number, encoding: string): string;
|
|
255
|
+
/**
|
|
256
|
+
* @public
|
|
257
|
+
* @method slice
|
|
258
|
+
* @description 从指定开始和结束位置索引截取并返回新的 Buffer 对象
|
|
259
|
+
* @param {number} [start] 截取开始位置索引
|
|
260
|
+
* @param {number} [end] 截取结束位置索引
|
|
261
|
+
* @returns {Buffer}
|
|
262
|
+
*/
|
|
263
|
+
slice(start?: number, end?: number): Buffer;
|
|
264
|
+
/**
|
|
265
|
+
* @public
|
|
266
|
+
* @method copyWithin
|
|
267
|
+
* @description 从 Buffer 对象中将指定位置的数据复制到以 target 起始的位置
|
|
268
|
+
* @param {number} target 粘贴开始位置索引
|
|
269
|
+
* @param {number} start 复制开始位置索引
|
|
270
|
+
* @param {number} [end] 复制结束位置索引
|
|
271
|
+
* @returns {this}
|
|
272
|
+
*/
|
|
273
|
+
copyWithin(target: number, start: number, end?: number): this;
|
|
274
|
+
/**
|
|
275
|
+
* @override
|
|
276
|
+
* @method toString
|
|
277
|
+
* @description 获取 Buffer 对象二进制编码字符串
|
|
278
|
+
* @returns {string}
|
|
279
|
+
*/
|
|
280
|
+
toString(): string;
|
|
281
|
+
}
|