-
Notifications
You must be signed in to change notification settings - Fork 69
/
BufferList.d.ts
418 lines (348 loc) · 12.5 KB
/
BufferList.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
export type BufferListAcceptedTypes =
| Buffer
| BufferList
| Uint8Array
| BufferListAcceptedTypes[]
| string
| number;
export interface BufferListConstructor {
new (initData?: BufferListAcceptedTypes): BufferList;
(initData?: BufferListAcceptedTypes): BufferList;
/**
* Determines if the passed object is a BufferList. It will return true
* if the passed object is an instance of BufferList or BufferListStream
* and false otherwise.
*
* N.B. this won't return true for BufferList or BufferListStream instances
* created by versions of this library before this static method was added.
*
* @param other
*/
isBufferList(other: unknown): boolean;
}
interface BufferList {
prototype: Object
/**
* Get the length of the list in bytes. This is the sum of the lengths
* of all of the buffers contained in the list, minus any initial offset
* for a semi-consumed buffer at the beginning. Should accurately
* represent the total number of bytes that can be read from the list.
*/
length: number;
/**
* Adds an additional buffer or BufferList to the internal list.
* this is returned so it can be chained.
*
* @param buffer
*/
append(buffer: BufferListAcceptedTypes): this;
/**
* Will return the byte at the specified index.
* @param index
*/
get(index: number): number;
/**
* Returns a new Buffer object containing the bytes within the
* range specified. Both start and end are optional and will
* default to the beginning and end of the list respectively.
*
* If the requested range spans a single internal buffer then a
* slice of that buffer will be returned which shares the original
* memory range of that Buffer. If the range spans multiple buffers
* then copy operations will likely occur to give you a uniform Buffer.
*
* @param start
* @param end
*/
slice(start?: number, end?: number): Buffer;
/**
* Returns a new BufferList object containing the bytes within the
* range specified. Both start and end are optional and will default
* to the beginning and end of the list respectively.
*
* No copies will be performed. All buffers in the result share
* memory with the original list.
*
* @param start
* @param end
*/
shallowSlice(start?: number, end?: number): this;
/**
* Copies the content of the list in the `dest` buffer, starting from
* `destStart` and containing the bytes within the range specified
* with `srcStart` to `srcEnd`.
*
* `destStart`, `start` and `end` are optional and will default to the
* beginning of the dest buffer, and the beginning and end of the
* list respectively.
*
* @param dest
* @param destStart
* @param srcStart
* @param srcEnd
*/
copy(
dest: Buffer,
destStart?: number,
srcStart?: number,
srcEnd?: number
): Buffer;
/**
* Performs a shallow-copy of the list. The internal Buffers remains the
* same, so if you change the underlying Buffers, the change will be
* reflected in both the original and the duplicate.
*
* This method is needed if you want to call consume() or pipe() and
* still keep the original list.
*
* @example
*
* ```js
* var bl = new BufferListStream();
* bl.append('hello');
* bl.append(' world');
* bl.append('\n');
* bl.duplicate().pipe(process.stdout, { end: false });
*
* console.log(bl.toString())
* ```
*/
duplicate(): this;
/**
* Will shift bytes off the start of the list. The number of bytes
* consumed don't need to line up with the sizes of the internal
* Buffers—initial offsets will be calculated accordingly in order
* to give you a consistent view of the data.
*
* @param bytes
*/
consume(bytes?: number): void;
/**
* Will return a string representation of the buffer. The optional
* `start` and `end` arguments are passed on to `slice()`, while
* the encoding is passed on to `toString()` of the resulting Buffer.
*
* See the [`Buffer#toString()`](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end)
* documentation for more information.
*
* @param encoding
* @param start
* @param end
*/
toString(encoding?: string, start?: number, end?: number): string;
/**
* Will return the byte at the specified index. indexOf() method
* returns the first index at which a given element can be found
* in the BufferList, or -1 if it is not present.
*
* @param value
* @param byteOffset
* @param encoding
*/
indexOf(
value: string | number | Uint8Array | BufferList | Buffer,
byteOffset?: number,
encoding?: string
): number;
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readDoubleBE: Buffer['readDoubleBE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readDoubleLE: Buffer['readDoubleLE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readFloatBE: Buffer['readFloatBE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readFloatLE: Buffer['readFloatLE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readBigInt64BE: Buffer['readBigInt64BE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readBigInt64LE: Buffer['readBigInt64LE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readBigUInt64BE: Buffer['readBigUInt64BE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readBigUInt64LE: Buffer['readBigUInt64LE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readInt32BE: Buffer['readInt32BE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readInt32LE: Buffer['readInt32LE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readUInt32BE: Buffer['readUInt32BE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readUInt32LE: Buffer['readUInt32LE'];
/**
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
*
* @param offset
*/
readInt16BE: Buffer['readInt16BE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readInt16LE: Buffer['readInt16LE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readUInt16BE: Buffer['readUInt16BE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readUInt16LE: Buffer['readUInt16LE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readInt8: Buffer['readInt8'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readUInt8: Buffer['readUInt8'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readIntBE: Buffer['readIntBE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readIntLE: Buffer['readIntLE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readUIntBE: Buffer['readUIntBE'];
/**
* All of the standard byte-reading methods of the Buffer interface are
* implemented and will operate across internal Buffer boundaries transparently.
*
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
* documentation for how these work.
*
* @param offset
*/
readUIntLE: Buffer['readUIntLE'];
}
/**
* No arguments are required for the constructor, but you can initialise
* the list by passing in a single Buffer object or an array of Buffer
* objects.
*
* `new` is not strictly required, if you don't instantiate a new object,
* it will be done automatically for you so you can create a new instance
* simply with:
*
* ```js
* const { BufferList } = require('bl')
* const bl = BufferList()
*
* // equivalent to:
*
* const { BufferList } = require('bl')
* const bl = new BufferList()
* ```
*/
declare const BufferList: BufferListConstructor;