bl 4.1.0 → 5.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/.github/dependabot.yml +16 -0
- package/.github/workflows/test-and-release.yml +61 -0
- package/BufferList.d.ts +382 -0
- package/CHANGELOG.md +17 -0
- package/index.d.ts +88 -0
- package/package.json +91 -5
- package/test/test.js +128 -83
- package/.travis.yml +0 -17
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: 'github-actions'
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: 'daily'
|
|
7
|
+
commit-message:
|
|
8
|
+
prefix: 'chore'
|
|
9
|
+
include: 'scope'
|
|
10
|
+
- package-ecosystem: 'npm'
|
|
11
|
+
directory: '/'
|
|
12
|
+
schedule:
|
|
13
|
+
interval: 'daily'
|
|
14
|
+
commit-message:
|
|
15
|
+
prefix: 'chore'
|
|
16
|
+
include: 'scope'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: Test & Maybe Release
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
strategy:
|
|
6
|
+
fail-fast: false
|
|
7
|
+
matrix:
|
|
8
|
+
node: [14.x, 16.x, 18.x, lts/*, current]
|
|
9
|
+
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
10
|
+
runs-on: ${{ matrix.os }}
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout Repository
|
|
13
|
+
uses: actions/checkout@v3
|
|
14
|
+
- name: Use Node.js ${{ matrix.node }}
|
|
15
|
+
uses: actions/setup-node@v3.5.1
|
|
16
|
+
with:
|
|
17
|
+
node-version: ${{ matrix.node }}
|
|
18
|
+
- name: Install Dependencies
|
|
19
|
+
run: |
|
|
20
|
+
npm install --no-progress
|
|
21
|
+
- name: Run tests
|
|
22
|
+
run: |
|
|
23
|
+
npm config set script-shell bash
|
|
24
|
+
npm run test:ci
|
|
25
|
+
release:
|
|
26
|
+
name: Release
|
|
27
|
+
needs: test
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
30
|
+
steps:
|
|
31
|
+
- name: Checkout
|
|
32
|
+
uses: actions/checkout@v3
|
|
33
|
+
with:
|
|
34
|
+
fetch-depth: 0
|
|
35
|
+
- name: Setup Node.js
|
|
36
|
+
uses: actions/setup-node@v3.5.1
|
|
37
|
+
with:
|
|
38
|
+
node-version: 14
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: |
|
|
41
|
+
npm install --no-progress --no-package-lock --no-save
|
|
42
|
+
- name: Build
|
|
43
|
+
run: |
|
|
44
|
+
npm run build
|
|
45
|
+
- name: Install plugins
|
|
46
|
+
run: |
|
|
47
|
+
npm install \
|
|
48
|
+
@semantic-release/commit-analyzer \
|
|
49
|
+
conventional-changelog-conventionalcommits \
|
|
50
|
+
@semantic-release/release-notes-generator \
|
|
51
|
+
@semantic-release/npm \
|
|
52
|
+
@semantic-release/github \
|
|
53
|
+
@semantic-release/git \
|
|
54
|
+
@semantic-release/changelog \
|
|
55
|
+
--no-progress --no-package-lock --no-save
|
|
56
|
+
- name: Release
|
|
57
|
+
env:
|
|
58
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
59
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
60
|
+
run: npx semantic-release
|
|
61
|
+
|
package/BufferList.d.ts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
export type BufferListAcceptedTypes =
|
|
2
|
+
| Buffer
|
|
3
|
+
| BufferList
|
|
4
|
+
| Uint8Array
|
|
5
|
+
| BufferListAcceptedTypes[]
|
|
6
|
+
| string
|
|
7
|
+
| number;
|
|
8
|
+
|
|
9
|
+
export interface BufferListConstructor {
|
|
10
|
+
new (initData?: BufferListAcceptedTypes): BufferList;
|
|
11
|
+
(initData?: BufferListAcceptedTypes): BufferList;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the passed object is a BufferList. It will return true
|
|
15
|
+
* if the passed object is an instance of BufferList or BufferListStream
|
|
16
|
+
* and false otherwise.
|
|
17
|
+
*
|
|
18
|
+
* N.B. this won't return true for BufferList or BufferListStream instances
|
|
19
|
+
* created by versions of this library before this static method was added.
|
|
20
|
+
*
|
|
21
|
+
* @param other
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
isBufferList(other: unknown): boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface BufferList {
|
|
28
|
+
prototype: Object
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the length of the list in bytes. This is the sum of the lengths
|
|
32
|
+
* of all of the buffers contained in the list, minus any initial offset
|
|
33
|
+
* for a semi-consumed buffer at the beginning. Should accurately
|
|
34
|
+
* represent the total number of bytes that can be read from the list.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
length: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Adds an additional buffer or BufferList to the internal list.
|
|
41
|
+
* this is returned so it can be chained.
|
|
42
|
+
*
|
|
43
|
+
* @param buffer
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
append(buffer: BufferListAcceptedTypes): this;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Will return the byte at the specified index.
|
|
50
|
+
* @param index
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
get(index: number): number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns a new Buffer object containing the bytes within the
|
|
57
|
+
* range specified. Both start and end are optional and will
|
|
58
|
+
* default to the beginning and end of the list respectively.
|
|
59
|
+
*
|
|
60
|
+
* If the requested range spans a single internal buffer then a
|
|
61
|
+
* slice of that buffer will be returned which shares the original
|
|
62
|
+
* memory range of that Buffer. If the range spans multiple buffers
|
|
63
|
+
* then copy operations will likely occur to give you a uniform Buffer.
|
|
64
|
+
*
|
|
65
|
+
* @param start
|
|
66
|
+
* @param end
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
slice(start?: number, end?: number): Buffer;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Returns a new BufferList object containing the bytes within the
|
|
73
|
+
* range specified. Both start and end are optional and will default
|
|
74
|
+
* to the beginning and end of the list respectively.
|
|
75
|
+
*
|
|
76
|
+
* No copies will be performed. All buffers in the result share
|
|
77
|
+
* memory with the original list.
|
|
78
|
+
*
|
|
79
|
+
* @param start
|
|
80
|
+
* @param end
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
shallowSlice(start?: number, end?: number): this;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Copies the content of the list in the `dest` buffer, starting from
|
|
87
|
+
* `destStart` and containing the bytes within the range specified
|
|
88
|
+
* with `srcStart` to `srcEnd`.
|
|
89
|
+
*
|
|
90
|
+
* `destStart`, `start` and `end` are optional and will default to the
|
|
91
|
+
* beginning of the dest buffer, and the beginning and end of the
|
|
92
|
+
* list respectively.
|
|
93
|
+
*
|
|
94
|
+
* @param dest
|
|
95
|
+
* @param destStart
|
|
96
|
+
* @param srcStart
|
|
97
|
+
* @param srcEnd
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
copy(
|
|
101
|
+
dest: Buffer,
|
|
102
|
+
destStart?: number,
|
|
103
|
+
srcStart?: number,
|
|
104
|
+
srcEnd?: number
|
|
105
|
+
): Buffer;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Performs a shallow-copy of the list. The internal Buffers remains the
|
|
109
|
+
* same, so if you change the underlying Buffers, the change will be
|
|
110
|
+
* reflected in both the original and the duplicate.
|
|
111
|
+
*
|
|
112
|
+
* This method is needed if you want to call consume() or pipe() and
|
|
113
|
+
* still keep the original list.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
*
|
|
117
|
+
* ```js
|
|
118
|
+
* var bl = new BufferListStream();
|
|
119
|
+
* bl.append('hello');
|
|
120
|
+
* bl.append(' world');
|
|
121
|
+
* bl.append('\n');
|
|
122
|
+
* bl.duplicate().pipe(process.stdout, { end: false });
|
|
123
|
+
*
|
|
124
|
+
* console.log(bl.toString())
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
duplicate(): this;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Will shift bytes off the start of the list. The number of bytes
|
|
132
|
+
* consumed don't need to line up with the sizes of the internal
|
|
133
|
+
* Buffers—initial offsets will be calculated accordingly in order
|
|
134
|
+
* to give you a consistent view of the data.
|
|
135
|
+
*
|
|
136
|
+
* @param bytes
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
consume(bytes?: number): void;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Will return a string representation of the buffer. The optional
|
|
143
|
+
* `start` and `end` arguments are passed on to `slice()`, while
|
|
144
|
+
* the encoding is passed on to `toString()` of the resulting Buffer.
|
|
145
|
+
*
|
|
146
|
+
* See the [`Buffer#toString()`](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end)
|
|
147
|
+
* documentation for more information.
|
|
148
|
+
*
|
|
149
|
+
* @param encoding
|
|
150
|
+
* @param start
|
|
151
|
+
* @param end
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
toString(encoding?: string, start?: number, end?: number): string;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Will return the byte at the specified index. indexOf() method
|
|
158
|
+
* returns the first index at which a given element can be found
|
|
159
|
+
* in the BufferList, or -1 if it is not present.
|
|
160
|
+
*
|
|
161
|
+
* @param value
|
|
162
|
+
* @param byteOffset
|
|
163
|
+
* @param encoding
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
indexOf(
|
|
167
|
+
value: string | number | Uint8Array | BufferList | Buffer,
|
|
168
|
+
byteOffset?: number,
|
|
169
|
+
encoding?: string
|
|
170
|
+
): number;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
174
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
175
|
+
*
|
|
176
|
+
* @param offset
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
readDoubleBE: Buffer['readDoubleBE'];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
183
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
184
|
+
*
|
|
185
|
+
* @param offset
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
readDoubleLE: Buffer['readDoubleLE'];
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
192
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
193
|
+
*
|
|
194
|
+
* @param offset
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
readFloatBE: Buffer['readFloatBE'];
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
201
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
202
|
+
*
|
|
203
|
+
* @param offset
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
readFloatLE: Buffer['readFloatLE'];
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
210
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
211
|
+
*
|
|
212
|
+
* @param offset
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
readInt32BE: Buffer['readInt32BE'];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
219
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
220
|
+
*
|
|
221
|
+
* @param offset
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
readInt32LE: Buffer['readInt32LE'];
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
228
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
229
|
+
*
|
|
230
|
+
* @param offset
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
readUInt32BE: Buffer['readUInt32BE'];
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
237
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
238
|
+
*
|
|
239
|
+
* @param offset
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
readUInt32LE: Buffer['readUInt32LE'];
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
246
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
|
247
|
+
*
|
|
248
|
+
* @param offset
|
|
249
|
+
*/
|
|
250
|
+
|
|
251
|
+
readInt16BE: Buffer['readInt16BE'];
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
255
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
256
|
+
*
|
|
257
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
258
|
+
* documentation for how these work.
|
|
259
|
+
*
|
|
260
|
+
* @param offset
|
|
261
|
+
*/
|
|
262
|
+
|
|
263
|
+
readInt16LE: Buffer['readInt16LE'];
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
267
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
268
|
+
*
|
|
269
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
270
|
+
* documentation for how these work.
|
|
271
|
+
*
|
|
272
|
+
* @param offset
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
readUInt16BE: Buffer['readUInt16BE'];
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
279
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
280
|
+
*
|
|
281
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
282
|
+
* documentation for how these work.
|
|
283
|
+
*
|
|
284
|
+
* @param offset
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
readUInt16LE: Buffer['readUInt16LE'];
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
291
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
292
|
+
*
|
|
293
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
294
|
+
* documentation for how these work.
|
|
295
|
+
*
|
|
296
|
+
* @param offset
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
readInt8: Buffer['readInt8'];
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
303
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
304
|
+
*
|
|
305
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
306
|
+
* documentation for how these work.
|
|
307
|
+
*
|
|
308
|
+
* @param offset
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
readUInt8: Buffer['readUInt8'];
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
315
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
316
|
+
*
|
|
317
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
318
|
+
* documentation for how these work.
|
|
319
|
+
*
|
|
320
|
+
* @param offset
|
|
321
|
+
*/
|
|
322
|
+
|
|
323
|
+
readIntBE: Buffer['readIntBE'];
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
327
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
328
|
+
*
|
|
329
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
330
|
+
* documentation for how these work.
|
|
331
|
+
*
|
|
332
|
+
* @param offset
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
readIntLE: Buffer['readIntLE'];
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
339
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
340
|
+
*
|
|
341
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
342
|
+
* documentation for how these work.
|
|
343
|
+
*
|
|
344
|
+
* @param offset
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
readUIntBE: Buffer['readUIntBE'];
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* All of the standard byte-reading methods of the Buffer interface are
|
|
351
|
+
* implemented and will operate across internal Buffer boundaries transparently.
|
|
352
|
+
*
|
|
353
|
+
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html)
|
|
354
|
+
* documentation for how these work.
|
|
355
|
+
*
|
|
356
|
+
* @param offset
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
readUIntLE: Buffer['readUIntLE'];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* No arguments are required for the constructor, but you can initialise
|
|
364
|
+
* the list by passing in a single Buffer object or an array of Buffer
|
|
365
|
+
* objects.
|
|
366
|
+
*
|
|
367
|
+
* `new` is not strictly required, if you don't instantiate a new object,
|
|
368
|
+
* it will be done automatically for you so you can create a new instance
|
|
369
|
+
* simply with:
|
|
370
|
+
*
|
|
371
|
+
* ```js
|
|
372
|
+
* const { BufferList } = require('bl')
|
|
373
|
+
* const bl = BufferList()
|
|
374
|
+
*
|
|
375
|
+
* // equivalent to:
|
|
376
|
+
*
|
|
377
|
+
* const { BufferList } = require('bl')
|
|
378
|
+
* const bl = new BufferList()
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
declare const BufferList: BufferListConstructor;
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
## [5.1.0](https://github.com/rvagg/bl/compare/v5.0.0...v5.1.0) (2022-10-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added integrated TypeScript typings ([#108](https://github.com/rvagg/bl/issues/108)) ([433ff89](https://github.com/rvagg/bl/commit/433ff8942f47fab8a5c9d13b2c00989ccf8d0710))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* windows support in tests ([387dfaf](https://github.com/rvagg/bl/commit/387dfaf9b2bca7849f12785436ceb01e42adac2c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Trivial Changes
|
|
15
|
+
|
|
16
|
+
* GH Actions, Dependabot, auto-release, remove Travis ([997f058](https://github.com/rvagg/bl/commit/997f058357de8f2a7f66998e80a72b491835573f))
|
|
17
|
+
* **no-release:** bump standard from 16.0.4 to 17.0.0 ([#112](https://github.com/rvagg/bl/issues/112)) ([078bfe3](https://github.com/rvagg/bl/commit/078bfe33390d125297b1c946e5989c4aa9228961))
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Duplex } from "readable-stream";
|
|
2
|
+
import {
|
|
3
|
+
BufferList as BL,
|
|
4
|
+
BufferListConstructor,
|
|
5
|
+
BufferListAcceptedTypes,
|
|
6
|
+
} from "./BufferList";
|
|
7
|
+
|
|
8
|
+
type BufferListStreamInit =
|
|
9
|
+
| ((err: Error, buffer: Buffer) => void)
|
|
10
|
+
| BufferListAcceptedTypes;
|
|
11
|
+
|
|
12
|
+
interface BufferListStreamConstructor {
|
|
13
|
+
new (initData?: BufferListStreamInit): BufferListStream;
|
|
14
|
+
(callback?: BufferListStreamInit): BufferListStream;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the passed object is a BufferList. It will return true
|
|
18
|
+
* if the passed object is an instance of BufferList or BufferListStream
|
|
19
|
+
* and false otherwise.
|
|
20
|
+
*
|
|
21
|
+
* N.B. this won't return true for BufferList or BufferListStream instances
|
|
22
|
+
* created by versions of this library before this static method was added.
|
|
23
|
+
*
|
|
24
|
+
* @param other
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
isBufferList(other: unknown): boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Rexporting BufferList and BufferListStream to fix
|
|
31
|
+
* issue with require/commonjs import and "export = " below.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
BufferList: BufferListConstructor;
|
|
35
|
+
BufferListStream: BufferListStreamConstructor;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface BufferListStream extends Duplex, BL {
|
|
39
|
+
prototype: BufferListStream & BL;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* BufferListStream is a Node Duplex Stream, so it can be read from
|
|
44
|
+
* and written to like a standard Node stream. You can also pipe()
|
|
45
|
+
* to and from a BufferListStream instance.
|
|
46
|
+
*
|
|
47
|
+
* The constructor takes an optional callback, if supplied, the
|
|
48
|
+
* callback will be called with an error argument followed by a
|
|
49
|
+
* reference to the bl instance, when bl.end() is called
|
|
50
|
+
* (i.e. from a piped stream).
|
|
51
|
+
*
|
|
52
|
+
* This is a convenient method of collecting the entire contents of
|
|
53
|
+
* a stream, particularly when the stream is chunky, such as a network
|
|
54
|
+
* stream.
|
|
55
|
+
*
|
|
56
|
+
* Normally, no arguments are required for the constructor, but you can
|
|
57
|
+
* initialise the list by passing in a single Buffer object or an array
|
|
58
|
+
* of Buffer object.
|
|
59
|
+
*
|
|
60
|
+
* `new` is not strictly required, if you don't instantiate a new object,
|
|
61
|
+
* it will be done automatically for you so you can create a new instance
|
|
62
|
+
* simply with:
|
|
63
|
+
*
|
|
64
|
+
* ```js
|
|
65
|
+
* const { BufferListStream } = require('bl');
|
|
66
|
+
* const bl = BufferListStream();
|
|
67
|
+
*
|
|
68
|
+
* // equivalent to:
|
|
69
|
+
*
|
|
70
|
+
* const { BufferListStream } = require('bl');
|
|
71
|
+
* const bl = new BufferListStream();
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* N.B. For backwards compatibility reasons, BufferListStream is the default
|
|
75
|
+
* export when you `require('bl')`:
|
|
76
|
+
*
|
|
77
|
+
* ```js
|
|
78
|
+
* const { BufferListStream } = require('bl')
|
|
79
|
+
*
|
|
80
|
+
* // equivalent to:
|
|
81
|
+
*
|
|
82
|
+
* const BufferListStream = require('bl')
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
declare const BufferListStream: BufferListStreamConstructor;
|
|
87
|
+
|
|
88
|
+
export = BufferListStream;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "bl.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "standard *.js test/*.js",
|
|
9
|
-
"test": "npm run lint && node test/test.js | faucet"
|
|
9
|
+
"test": "npm run lint && npm run test:types && node test/test.js | faucet",
|
|
10
|
+
"test:ci": "npm run lint && node test/test.js && npm run test:types",
|
|
11
|
+
"test:types": "tsc --allowJs --noEmit test/test.js",
|
|
12
|
+
"build": "true"
|
|
10
13
|
},
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
@@ -25,13 +28,96 @@
|
|
|
25
28
|
"awesomesauce"
|
|
26
29
|
],
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"buffer": "^
|
|
31
|
+
"buffer": "^6.0.3",
|
|
29
32
|
"inherits": "^2.0.4",
|
|
30
33
|
"readable-stream": "^3.4.0"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
36
|
+
"@types/readable-stream": "^2.3.13",
|
|
33
37
|
"faucet": "~0.0.1",
|
|
34
|
-
"standard": "^
|
|
35
|
-
"tape": "^
|
|
38
|
+
"standard": "^17.0.0",
|
|
39
|
+
"tape": "^5.2.2",
|
|
40
|
+
"typescript": "~4.7.3"
|
|
41
|
+
},
|
|
42
|
+
"release": {
|
|
43
|
+
"branches": [
|
|
44
|
+
"master"
|
|
45
|
+
],
|
|
46
|
+
"plugins": [
|
|
47
|
+
[
|
|
48
|
+
"@semantic-release/commit-analyzer",
|
|
49
|
+
{
|
|
50
|
+
"preset": "conventionalcommits",
|
|
51
|
+
"releaseRules": [
|
|
52
|
+
{
|
|
53
|
+
"breaking": true,
|
|
54
|
+
"release": "major"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"revert": true,
|
|
58
|
+
"release": "patch"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"type": "feat",
|
|
62
|
+
"release": "minor"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "fix",
|
|
66
|
+
"release": "patch"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"type": "chore",
|
|
70
|
+
"release": "patch"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"type": "docs",
|
|
74
|
+
"release": "patch"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"type": "test",
|
|
78
|
+
"release": "patch"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"scope": "no-release",
|
|
82
|
+
"release": false
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"@semantic-release/release-notes-generator",
|
|
89
|
+
{
|
|
90
|
+
"preset": "conventionalcommits",
|
|
91
|
+
"presetConfig": {
|
|
92
|
+
"types": [
|
|
93
|
+
{
|
|
94
|
+
"type": "feat",
|
|
95
|
+
"section": "Features"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "fix",
|
|
99
|
+
"section": "Bug Fixes"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"type": "chore",
|
|
103
|
+
"section": "Trivial Changes"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "docs",
|
|
107
|
+
"section": "Trivial Changes"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"type": "test",
|
|
111
|
+
"section": "Tests"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"@semantic-release/changelog",
|
|
118
|
+
"@semantic-release/npm",
|
|
119
|
+
"@semantic-release/github",
|
|
120
|
+
"@semantic-release/git"
|
|
121
|
+
]
|
|
36
122
|
}
|
|
37
123
|
}
|
package/test/test.js
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
'use strict'
|
|
2
3
|
|
|
3
4
|
const tape = require('tape')
|
|
4
5
|
const crypto = require('crypto')
|
|
5
6
|
const fs = require('fs')
|
|
6
7
|
const path = require('path')
|
|
7
|
-
const
|
|
8
|
+
const os = require('os')
|
|
9
|
+
const BufferListStream = require('../')
|
|
8
10
|
const { Buffer } = require('buffer')
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* This typedef allows us to add _bufs to the API without declaring it publicly on types.
|
|
14
|
+
* @typedef { BufferListStream & { _bufs?: Buffer[] }} BufferListStreamWithPrivate
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Just for typechecking in js
|
|
19
|
+
* @type { NodeJS.Process & { browser?: boolean }}
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const process = globalThis.process
|
|
23
|
+
|
|
24
|
+
/** @type {BufferEncoding[]} */
|
|
25
|
+
const encodings = ['ascii', 'utf8', 'utf-8', 'hex', 'binary', 'base64']
|
|
26
|
+
|
|
27
|
+
if (process.browser) {
|
|
28
|
+
encodings.push(
|
|
29
|
+
'ucs2',
|
|
30
|
+
'ucs-2',
|
|
31
|
+
'utf16le',
|
|
32
|
+
/**
|
|
33
|
+
* This alias is not in typescript typings for BufferEncoding. Still have to fix
|
|
34
|
+
* @see https://nodejs.org/api/buffer.html#buffers-and-character-encodings
|
|
35
|
+
*/
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
'utf-16le'
|
|
38
|
+
)
|
|
39
|
+
}
|
|
13
40
|
|
|
14
41
|
require('./indexOf')
|
|
15
42
|
require('./isBufferList')
|
|
16
43
|
require('./convert')
|
|
17
44
|
|
|
18
45
|
tape('single bytes from single buffer', function (t) {
|
|
19
|
-
const bl = new
|
|
46
|
+
const bl = new BufferListStream()
|
|
20
47
|
|
|
21
48
|
bl.append(Buffer.from('abcd'))
|
|
22
49
|
|
|
@@ -32,7 +59,7 @@ tape('single bytes from single buffer', function (t) {
|
|
|
32
59
|
})
|
|
33
60
|
|
|
34
61
|
tape('single bytes from multiple buffers', function (t) {
|
|
35
|
-
const bl = new
|
|
62
|
+
const bl = new BufferListStream()
|
|
36
63
|
|
|
37
64
|
bl.append(Buffer.from('abcd'))
|
|
38
65
|
bl.append(Buffer.from('efg'))
|
|
@@ -56,7 +83,7 @@ tape('single bytes from multiple buffers', function (t) {
|
|
|
56
83
|
})
|
|
57
84
|
|
|
58
85
|
tape('multi bytes from single buffer', function (t) {
|
|
59
|
-
const bl = new
|
|
86
|
+
const bl = new BufferListStream()
|
|
60
87
|
|
|
61
88
|
bl.append(Buffer.from('abcd'))
|
|
62
89
|
|
|
@@ -71,7 +98,7 @@ tape('multi bytes from single buffer', function (t) {
|
|
|
71
98
|
})
|
|
72
99
|
|
|
73
100
|
tape('multi bytes from single buffer (negative indexes)', function (t) {
|
|
74
|
-
const bl = new
|
|
101
|
+
const bl = new BufferListStream()
|
|
75
102
|
|
|
76
103
|
bl.append(Buffer.from('buffer'))
|
|
77
104
|
|
|
@@ -85,7 +112,7 @@ tape('multi bytes from single buffer (negative indexes)', function (t) {
|
|
|
85
112
|
})
|
|
86
113
|
|
|
87
114
|
tape('multiple bytes from multiple buffers', function (t) {
|
|
88
|
-
const bl = new
|
|
115
|
+
const bl = new BufferListStream()
|
|
89
116
|
|
|
90
117
|
bl.append(Buffer.from('abcd'))
|
|
91
118
|
bl.append(Buffer.from('efg'))
|
|
@@ -105,10 +132,10 @@ tape('multiple bytes from multiple buffers', function (t) {
|
|
|
105
132
|
})
|
|
106
133
|
|
|
107
134
|
tape('multiple bytes from multiple buffer lists', function (t) {
|
|
108
|
-
const bl = new
|
|
135
|
+
const bl = new BufferListStream()
|
|
109
136
|
|
|
110
|
-
bl.append(new
|
|
111
|
-
bl.append(new
|
|
137
|
+
bl.append(new BufferListStream([Buffer.from('abcd'), Buffer.from('efg')]))
|
|
138
|
+
bl.append(new BufferListStream([Buffer.from('hi'), Buffer.from('j')]))
|
|
112
139
|
|
|
113
140
|
t.equal(bl.length, 10)
|
|
114
141
|
|
|
@@ -124,17 +151,19 @@ tape('multiple bytes from multiple buffer lists', function (t) {
|
|
|
124
151
|
|
|
125
152
|
// same data as previous test, just using nested constructors
|
|
126
153
|
tape('multiple bytes from crazy nested buffer lists', function (t) {
|
|
127
|
-
const bl = new
|
|
128
|
-
|
|
129
|
-
bl.append(
|
|
130
|
-
new
|
|
131
|
-
new
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
154
|
+
const bl = new BufferListStream()
|
|
155
|
+
|
|
156
|
+
bl.append(
|
|
157
|
+
new BufferListStream([
|
|
158
|
+
new BufferListStream([
|
|
159
|
+
new BufferListStream(Buffer.from('abc')),
|
|
160
|
+
Buffer.from('d'),
|
|
161
|
+
new BufferListStream(Buffer.from('efg'))
|
|
162
|
+
]),
|
|
163
|
+
new BufferListStream([Buffer.from('hi')]),
|
|
164
|
+
new BufferListStream(Buffer.from('j'))
|
|
165
|
+
])
|
|
166
|
+
)
|
|
138
167
|
|
|
139
168
|
t.equal(bl.length, 10)
|
|
140
169
|
|
|
@@ -149,7 +178,7 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
|
|
|
149
178
|
})
|
|
150
179
|
|
|
151
180
|
tape('append accepts arrays of Buffers', function (t) {
|
|
152
|
-
const bl = new
|
|
181
|
+
const bl = new BufferListStream()
|
|
153
182
|
|
|
154
183
|
bl.append(Buffer.from('abc'))
|
|
155
184
|
bl.append([Buffer.from('def')])
|
|
@@ -162,7 +191,7 @@ tape('append accepts arrays of Buffers', function (t) {
|
|
|
162
191
|
})
|
|
163
192
|
|
|
164
193
|
tape('append accepts arrays of Uint8Arrays', function (t) {
|
|
165
|
-
const bl = new
|
|
194
|
+
const bl = new BufferListStream()
|
|
166
195
|
|
|
167
196
|
bl.append(new Uint8Array([97, 98, 99]))
|
|
168
197
|
bl.append([Uint8Array.from([100, 101, 102])])
|
|
@@ -175,12 +204,17 @@ tape('append accepts arrays of Uint8Arrays', function (t) {
|
|
|
175
204
|
})
|
|
176
205
|
|
|
177
206
|
tape('append accepts arrays of BufferLists', function (t) {
|
|
178
|
-
const bl = new
|
|
207
|
+
const bl = new BufferListStream()
|
|
179
208
|
|
|
180
209
|
bl.append(Buffer.from('abc'))
|
|
181
|
-
bl.append([new
|
|
182
|
-
bl.append(
|
|
183
|
-
|
|
210
|
+
bl.append([new BufferListStream('def')])
|
|
211
|
+
bl.append(
|
|
212
|
+
new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
|
|
213
|
+
)
|
|
214
|
+
bl.append([
|
|
215
|
+
Buffer.from('mnop'),
|
|
216
|
+
new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
|
|
217
|
+
])
|
|
184
218
|
t.equal(bl.length, 26)
|
|
185
219
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
186
220
|
|
|
@@ -188,21 +222,26 @@ tape('append accepts arrays of BufferLists', function (t) {
|
|
|
188
222
|
})
|
|
189
223
|
|
|
190
224
|
tape('append chainable', function (t) {
|
|
191
|
-
const bl = new
|
|
225
|
+
const bl = new BufferListStream()
|
|
192
226
|
|
|
193
227
|
t.ok(bl.append(Buffer.from('abcd')) === bl)
|
|
194
228
|
t.ok(bl.append([Buffer.from('abcd')]) === bl)
|
|
195
|
-
t.ok(bl.append(new
|
|
196
|
-
t.ok(bl.append([new
|
|
229
|
+
t.ok(bl.append(new BufferListStream(Buffer.from('abcd'))) === bl)
|
|
230
|
+
t.ok(bl.append([new BufferListStream(Buffer.from('abcd'))]) === bl)
|
|
197
231
|
|
|
198
232
|
t.end()
|
|
199
233
|
})
|
|
200
234
|
|
|
201
235
|
tape('append chainable (test results)', function (t) {
|
|
202
|
-
const bl = new
|
|
203
|
-
.append([new
|
|
204
|
-
.append(
|
|
205
|
-
|
|
236
|
+
const bl = new BufferListStream('abc')
|
|
237
|
+
.append([new BufferListStream('def')])
|
|
238
|
+
.append(
|
|
239
|
+
new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
|
|
240
|
+
)
|
|
241
|
+
.append([
|
|
242
|
+
Buffer.from('mnop'),
|
|
243
|
+
new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
|
|
244
|
+
])
|
|
206
245
|
|
|
207
246
|
t.equal(bl.length, 26)
|
|
208
247
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
@@ -211,7 +250,7 @@ tape('append chainable (test results)', function (t) {
|
|
|
211
250
|
})
|
|
212
251
|
|
|
213
252
|
tape('consuming from multiple buffers', function (t) {
|
|
214
|
-
const bl = new
|
|
253
|
+
const bl = new BufferListStream()
|
|
215
254
|
|
|
216
255
|
bl.append(Buffer.from('abcd'))
|
|
217
256
|
bl.append(Buffer.from('efg'))
|
|
@@ -246,7 +285,8 @@ tape('consuming from multiple buffers', function (t) {
|
|
|
246
285
|
})
|
|
247
286
|
|
|
248
287
|
tape('complete consumption', function (t) {
|
|
249
|
-
|
|
288
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
289
|
+
const bl = new BufferListStream()
|
|
250
290
|
|
|
251
291
|
bl.append(Buffer.from('a'))
|
|
252
292
|
bl.append(Buffer.from('b'))
|
|
@@ -263,7 +303,7 @@ tape('test readUInt8 / readInt8', function (t) {
|
|
|
263
303
|
const buf1 = Buffer.alloc(1)
|
|
264
304
|
const buf2 = Buffer.alloc(3)
|
|
265
305
|
const buf3 = Buffer.alloc(3)
|
|
266
|
-
const bl = new
|
|
306
|
+
const bl = new BufferListStream()
|
|
267
307
|
|
|
268
308
|
buf1[0] = 0x1
|
|
269
309
|
buf2[1] = 0x3
|
|
@@ -292,7 +332,7 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
|
|
|
292
332
|
const buf1 = Buffer.alloc(1)
|
|
293
333
|
const buf2 = Buffer.alloc(3)
|
|
294
334
|
const buf3 = Buffer.alloc(3)
|
|
295
|
-
const bl = new
|
|
335
|
+
const bl = new BufferListStream()
|
|
296
336
|
|
|
297
337
|
buf1[0] = 0x1
|
|
298
338
|
buf2[1] = 0x3
|
|
@@ -326,7 +366,7 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
|
|
|
326
366
|
const buf1 = Buffer.alloc(1)
|
|
327
367
|
const buf2 = Buffer.alloc(3)
|
|
328
368
|
const buf3 = Buffer.alloc(3)
|
|
329
|
-
const bl = new
|
|
369
|
+
const bl = new BufferListStream()
|
|
330
370
|
|
|
331
371
|
buf1[0] = 0x1
|
|
332
372
|
buf2[1] = 0x3
|
|
@@ -352,7 +392,7 @@ tape('test readUIntLE / readUIntBE / readIntLE / readIntBE', function (t) {
|
|
|
352
392
|
const buf1 = Buffer.alloc(1)
|
|
353
393
|
const buf2 = Buffer.alloc(3)
|
|
354
394
|
const buf3 = Buffer.alloc(3)
|
|
355
|
-
const bl = new
|
|
395
|
+
const bl = new BufferListStream()
|
|
356
396
|
|
|
357
397
|
buf2[0] = 0x2
|
|
358
398
|
buf2[1] = 0x3
|
|
@@ -397,7 +437,7 @@ tape('test readFloatLE / readFloatBE', function (t) {
|
|
|
397
437
|
const buf1 = Buffer.alloc(1)
|
|
398
438
|
const buf2 = Buffer.alloc(3)
|
|
399
439
|
const buf3 = Buffer.alloc(3)
|
|
400
|
-
const bl = new
|
|
440
|
+
const bl = new BufferListStream()
|
|
401
441
|
|
|
402
442
|
buf1[0] = 0x01
|
|
403
443
|
buf2[1] = 0x00
|
|
@@ -422,7 +462,7 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
|
422
462
|
const buf1 = Buffer.alloc(1)
|
|
423
463
|
const buf2 = Buffer.alloc(3)
|
|
424
464
|
const buf3 = Buffer.alloc(10)
|
|
425
|
-
const bl = new
|
|
465
|
+
const bl = new BufferListStream()
|
|
426
466
|
|
|
427
467
|
buf1[0] = 0x01
|
|
428
468
|
buf2[1] = 0x55
|
|
@@ -448,7 +488,7 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
|
448
488
|
})
|
|
449
489
|
|
|
450
490
|
tape('test toString', function (t) {
|
|
451
|
-
const bl = new
|
|
491
|
+
const bl = new BufferListStream()
|
|
452
492
|
|
|
453
493
|
bl.append(Buffer.from('abcd'))
|
|
454
494
|
bl.append(Buffer.from('efg'))
|
|
@@ -465,7 +505,7 @@ tape('test toString', function (t) {
|
|
|
465
505
|
})
|
|
466
506
|
|
|
467
507
|
tape('test toString encoding', function (t) {
|
|
468
|
-
const bl = new
|
|
508
|
+
const bl = new BufferListStream()
|
|
469
509
|
const b = Buffer.from('abcdefghij\xff\x00')
|
|
470
510
|
|
|
471
511
|
bl.append(Buffer.from('abcd'))
|
|
@@ -485,7 +525,7 @@ tape('uninitialized memory', function (t) {
|
|
|
485
525
|
const secret = crypto.randomBytes(256)
|
|
486
526
|
for (let i = 0; i < 1e6; i++) {
|
|
487
527
|
const clone = Buffer.from(secret)
|
|
488
|
-
const bl = new
|
|
528
|
+
const bl = new BufferListStream()
|
|
489
529
|
bl.append(Buffer.from('a'))
|
|
490
530
|
bl.consume(-1024)
|
|
491
531
|
const buf = bl.slice(1)
|
|
@@ -500,17 +540,17 @@ tape('uninitialized memory', function (t) {
|
|
|
500
540
|
!process.browser && tape('test stream', function (t) {
|
|
501
541
|
const random = crypto.randomBytes(65534)
|
|
502
542
|
|
|
503
|
-
const bl = new
|
|
543
|
+
const bl = new BufferListStream((err, buf) => {
|
|
504
544
|
t.ok(Buffer.isBuffer(buf))
|
|
505
545
|
t.ok(err === null)
|
|
506
546
|
t.ok(random.equals(bl.slice()))
|
|
507
547
|
t.ok(random.equals(buf.slice()))
|
|
508
548
|
|
|
509
|
-
bl.pipe(fs.createWriteStream('
|
|
549
|
+
bl.pipe(fs.createWriteStream(path.join(os.tmpdir(), 'bl_test_rnd_out.dat')))
|
|
510
550
|
.on('close', function () {
|
|
511
551
|
const rndhash = crypto.createHash('md5').update(random).digest('hex')
|
|
512
552
|
const md5sum = crypto.createHash('md5')
|
|
513
|
-
const s = fs.createReadStream('
|
|
553
|
+
const s = fs.createReadStream(path.join(os.tmpdir(), 'bl_test_rnd_out.dat'))
|
|
514
554
|
|
|
515
555
|
s.on('data', md5sum.update.bind(md5sum))
|
|
516
556
|
s.on('end', function () {
|
|
@@ -520,24 +560,24 @@ tape('uninitialized memory', function (t) {
|
|
|
520
560
|
})
|
|
521
561
|
})
|
|
522
562
|
|
|
523
|
-
fs.writeFileSync('
|
|
524
|
-
fs.createReadStream('
|
|
563
|
+
fs.writeFileSync(path.join(os.tmpdir(), 'bl_test_rnd.dat'), random)
|
|
564
|
+
fs.createReadStream(path.join(os.tmpdir(), 'bl_test_rnd.dat')).pipe(bl)
|
|
525
565
|
})
|
|
526
566
|
|
|
527
567
|
tape('instantiation with Buffer', function (t) {
|
|
528
568
|
const buf = crypto.randomBytes(1024)
|
|
529
569
|
const buf2 = crypto.randomBytes(1024)
|
|
530
|
-
let b =
|
|
570
|
+
let b = BufferListStream(buf)
|
|
531
571
|
|
|
532
572
|
t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
|
|
533
|
-
b =
|
|
573
|
+
b = BufferListStream([buf, buf2])
|
|
534
574
|
t.equal(b.slice().toString('hex'), Buffer.concat([buf, buf2]).toString('hex'), 'same buffer')
|
|
535
575
|
|
|
536
576
|
t.end()
|
|
537
577
|
})
|
|
538
578
|
|
|
539
579
|
tape('test String appendage', function (t) {
|
|
540
|
-
const bl = new
|
|
580
|
+
const bl = new BufferListStream()
|
|
541
581
|
const b = Buffer.from('abcdefghij\xff\x00')
|
|
542
582
|
|
|
543
583
|
bl.append('abcd')
|
|
@@ -554,7 +594,7 @@ tape('test String appendage', function (t) {
|
|
|
554
594
|
})
|
|
555
595
|
|
|
556
596
|
tape('test Number appendage', function (t) {
|
|
557
|
-
const bl = new
|
|
597
|
+
const bl = new BufferListStream()
|
|
558
598
|
const b = Buffer.from('1234567890')
|
|
559
599
|
|
|
560
600
|
bl.append(1234)
|
|
@@ -571,7 +611,7 @@ tape('test Number appendage', function (t) {
|
|
|
571
611
|
|
|
572
612
|
tape('write nothing, should get empty buffer', function (t) {
|
|
573
613
|
t.plan(3)
|
|
574
|
-
|
|
614
|
+
BufferListStream(function (err, data) {
|
|
575
615
|
t.notOk(err, 'no error')
|
|
576
616
|
t.ok(Buffer.isBuffer(data), 'got a buffer')
|
|
577
617
|
t.equal(0, data.length, 'got a zero-length buffer')
|
|
@@ -585,7 +625,7 @@ tape('unicode string', function (t) {
|
|
|
585
625
|
const inp1 = '\u2600'
|
|
586
626
|
const inp2 = '\u2603'
|
|
587
627
|
const exp = inp1 + ' and ' + inp2
|
|
588
|
-
const bl =
|
|
628
|
+
const bl = BufferListStream()
|
|
589
629
|
|
|
590
630
|
bl.write(inp1)
|
|
591
631
|
bl.write(' and ')
|
|
@@ -595,8 +635,8 @@ tape('unicode string', function (t) {
|
|
|
595
635
|
})
|
|
596
636
|
|
|
597
637
|
tape('should emit finish', function (t) {
|
|
598
|
-
const source =
|
|
599
|
-
const dest =
|
|
638
|
+
const source = BufferListStream()
|
|
639
|
+
const dest = BufferListStream()
|
|
600
640
|
|
|
601
641
|
source.write('hello')
|
|
602
642
|
source.pipe(dest)
|
|
@@ -610,7 +650,7 @@ tape('should emit finish', function (t) {
|
|
|
610
650
|
tape('basic copy', function (t) {
|
|
611
651
|
const buf = crypto.randomBytes(1024)
|
|
612
652
|
const buf2 = Buffer.alloc(1024)
|
|
613
|
-
const b =
|
|
653
|
+
const b = BufferListStream(buf)
|
|
614
654
|
|
|
615
655
|
b.copy(buf2)
|
|
616
656
|
t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
@@ -621,7 +661,7 @@ tape('basic copy', function (t) {
|
|
|
621
661
|
tape('copy after many appends', function (t) {
|
|
622
662
|
const buf = crypto.randomBytes(512)
|
|
623
663
|
const buf2 = Buffer.alloc(1024)
|
|
624
|
-
const b =
|
|
664
|
+
const b = BufferListStream(buf)
|
|
625
665
|
|
|
626
666
|
b.append(buf)
|
|
627
667
|
b.copy(buf2)
|
|
@@ -633,7 +673,7 @@ tape('copy after many appends', function (t) {
|
|
|
633
673
|
tape('copy at a precise position', function (t) {
|
|
634
674
|
const buf = crypto.randomBytes(1004)
|
|
635
675
|
const buf2 = Buffer.alloc(1024)
|
|
636
|
-
const b =
|
|
676
|
+
const b = BufferListStream(buf)
|
|
637
677
|
|
|
638
678
|
b.copy(buf2, 20)
|
|
639
679
|
t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
|
|
@@ -644,7 +684,7 @@ tape('copy at a precise position', function (t) {
|
|
|
644
684
|
tape('copy starting from a precise location', function (t) {
|
|
645
685
|
const buf = crypto.randomBytes(10)
|
|
646
686
|
const buf2 = Buffer.alloc(5)
|
|
647
|
-
const b =
|
|
687
|
+
const b = BufferListStream(buf)
|
|
648
688
|
|
|
649
689
|
b.copy(buf2, 0, 5)
|
|
650
690
|
t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
@@ -654,7 +694,7 @@ tape('copy starting from a precise location', function (t) {
|
|
|
654
694
|
|
|
655
695
|
tape('copy in an interval', function (t) {
|
|
656
696
|
const rnd = crypto.randomBytes(10)
|
|
657
|
-
const b =
|
|
697
|
+
const b = BufferListStream(rnd) // put the random bytes there
|
|
658
698
|
const actual = Buffer.alloc(3)
|
|
659
699
|
const expected = Buffer.alloc(3)
|
|
660
700
|
|
|
@@ -669,7 +709,7 @@ tape('copy in an interval', function (t) {
|
|
|
669
709
|
tape('copy an interval between two buffers', function (t) {
|
|
670
710
|
const buf = crypto.randomBytes(10)
|
|
671
711
|
const buf2 = Buffer.alloc(10)
|
|
672
|
-
const b =
|
|
712
|
+
const b = BufferListStream(buf)
|
|
673
713
|
|
|
674
714
|
b.append(buf)
|
|
675
715
|
b.copy(buf2, 0, 5, 15)
|
|
@@ -680,7 +720,7 @@ tape('copy an interval between two buffers', function (t) {
|
|
|
680
720
|
})
|
|
681
721
|
|
|
682
722
|
tape('shallow slice across buffer boundaries', function (t) {
|
|
683
|
-
const bl = new
|
|
723
|
+
const bl = new BufferListStream(['First', 'Second', 'Third'])
|
|
684
724
|
|
|
685
725
|
t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh')
|
|
686
726
|
|
|
@@ -690,7 +730,7 @@ tape('shallow slice across buffer boundaries', function (t) {
|
|
|
690
730
|
tape('shallow slice within single buffer', function (t) {
|
|
691
731
|
t.plan(2)
|
|
692
732
|
|
|
693
|
-
const bl = new
|
|
733
|
+
const bl = new BufferListStream(['First', 'Second', 'Third'])
|
|
694
734
|
|
|
695
735
|
t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')
|
|
696
736
|
t.equal(bl.shallowSlice(7, 10).toString(), 'con')
|
|
@@ -701,7 +741,7 @@ tape('shallow slice within single buffer', function (t) {
|
|
|
701
741
|
tape('shallow slice single buffer', function (t) {
|
|
702
742
|
t.plan(3)
|
|
703
743
|
|
|
704
|
-
const bl = new
|
|
744
|
+
const bl = new BufferListStream(['First', 'Second', 'Third'])
|
|
705
745
|
|
|
706
746
|
t.equal(bl.shallowSlice(0, 5).toString(), 'First')
|
|
707
747
|
t.equal(bl.shallowSlice(5, 11).toString(), 'Second')
|
|
@@ -711,7 +751,7 @@ tape('shallow slice single buffer', function (t) {
|
|
|
711
751
|
tape('shallow slice with negative or omitted indices', function (t) {
|
|
712
752
|
t.plan(4)
|
|
713
753
|
|
|
714
|
-
const bl = new
|
|
754
|
+
const bl = new BufferListStream(['First', 'Second', 'Third'])
|
|
715
755
|
|
|
716
756
|
t.equal(bl.shallowSlice().toString(), 'FirstSecondThird')
|
|
717
757
|
t.equal(bl.shallowSlice(5).toString(), 'SecondThird')
|
|
@@ -723,7 +763,7 @@ tape('shallow slice does not make a copy', function (t) {
|
|
|
723
763
|
t.plan(1)
|
|
724
764
|
|
|
725
765
|
const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
|
|
726
|
-
const bl =
|
|
766
|
+
const bl = new BufferListStream(buffers).shallowSlice(5, -3)
|
|
727
767
|
|
|
728
768
|
buffers[1].fill('h')
|
|
729
769
|
buffers[2].fill('h')
|
|
@@ -735,7 +775,7 @@ tape('shallow slice with 0 length', function (t) {
|
|
|
735
775
|
t.plan(1)
|
|
736
776
|
|
|
737
777
|
const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
|
|
738
|
-
const bl = (new
|
|
778
|
+
const bl = (new BufferListStream(buffers)).shallowSlice(0, 0)
|
|
739
779
|
|
|
740
780
|
t.equal(bl.length, 0)
|
|
741
781
|
})
|
|
@@ -744,7 +784,7 @@ tape('shallow slice with 0 length from middle', function (t) {
|
|
|
744
784
|
t.plan(1)
|
|
745
785
|
|
|
746
786
|
const buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
|
|
747
|
-
const bl = (new
|
|
787
|
+
const bl = (new BufferListStream(buffers)).shallowSlice(10, 10)
|
|
748
788
|
|
|
749
789
|
t.equal(bl.length, 0)
|
|
750
790
|
})
|
|
@@ -752,7 +792,7 @@ tape('shallow slice with 0 length from middle', function (t) {
|
|
|
752
792
|
tape('duplicate', function (t) {
|
|
753
793
|
t.plan(2)
|
|
754
794
|
|
|
755
|
-
const bl = new
|
|
795
|
+
const bl = new BufferListStream('abcdefghij\xff\x00')
|
|
756
796
|
const dup = bl.duplicate()
|
|
757
797
|
|
|
758
798
|
t.equal(bl.prototype, dup.prototype)
|
|
@@ -762,7 +802,8 @@ tape('duplicate', function (t) {
|
|
|
762
802
|
tape('destroy no pipe', function (t) {
|
|
763
803
|
t.plan(2)
|
|
764
804
|
|
|
765
|
-
|
|
805
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
806
|
+
const bl = new BufferListStream('alsdkfja;lsdkfja;lsdk')
|
|
766
807
|
|
|
767
808
|
bl.destroy()
|
|
768
809
|
|
|
@@ -773,7 +814,8 @@ tape('destroy no pipe', function (t) {
|
|
|
773
814
|
tape('destroy with error', function (t) {
|
|
774
815
|
t.plan(3)
|
|
775
816
|
|
|
776
|
-
|
|
817
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
818
|
+
const bl = new BufferListStream('alsdkfja;lsdkfja;lsdk')
|
|
777
819
|
const err = new Error('kaboom')
|
|
778
820
|
|
|
779
821
|
bl.destroy(err)
|
|
@@ -788,7 +830,8 @@ tape('destroy with error', function (t) {
|
|
|
788
830
|
!process.browser && tape('destroy with pipe before read end', function (t) {
|
|
789
831
|
t.plan(2)
|
|
790
832
|
|
|
791
|
-
|
|
833
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
834
|
+
const bl = new BufferListStream()
|
|
792
835
|
fs.createReadStream(path.join(__dirname, '/test.js'))
|
|
793
836
|
.pipe(bl)
|
|
794
837
|
|
|
@@ -801,7 +844,8 @@ tape('destroy with error', function (t) {
|
|
|
801
844
|
!process.browser && tape('destroy with pipe before read end with race', function (t) {
|
|
802
845
|
t.plan(2)
|
|
803
846
|
|
|
804
|
-
|
|
847
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
848
|
+
const bl = new BufferListStream()
|
|
805
849
|
|
|
806
850
|
fs.createReadStream(path.join(__dirname, '/test.js'))
|
|
807
851
|
.pipe(bl)
|
|
@@ -818,8 +862,8 @@ tape('destroy with error', function (t) {
|
|
|
818
862
|
!process.browser && tape('destroy with pipe after read end', function (t) {
|
|
819
863
|
t.plan(2)
|
|
820
864
|
|
|
821
|
-
|
|
822
|
-
|
|
865
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
866
|
+
const bl = new BufferListStream()
|
|
823
867
|
fs.createReadStream(path.join(__dirname, '/test.js'))
|
|
824
868
|
.on('end', onEnd)
|
|
825
869
|
.pipe(bl)
|
|
@@ -835,8 +879,9 @@ tape('destroy with error', function (t) {
|
|
|
835
879
|
!process.browser && tape('destroy with pipe while writing to a destination', function (t) {
|
|
836
880
|
t.plan(4)
|
|
837
881
|
|
|
838
|
-
|
|
839
|
-
const
|
|
882
|
+
/** @type {BufferListStreamWithPrivate} */
|
|
883
|
+
const bl = new BufferListStream()
|
|
884
|
+
const ds = new BufferListStream()
|
|
840
885
|
|
|
841
886
|
fs.createReadStream(path.join(__dirname, '/test.js'))
|
|
842
887
|
.on('end', onEnd)
|
|
@@ -862,7 +907,7 @@ tape('destroy with error', function (t) {
|
|
|
862
907
|
!process.browser && tape('handle error', function (t) {
|
|
863
908
|
t.plan(2)
|
|
864
909
|
|
|
865
|
-
fs.createReadStream('/does/not/exist').pipe(
|
|
910
|
+
fs.createReadStream('/does/not/exist').pipe(BufferListStream(function (err, data) {
|
|
866
911
|
t.ok(err instanceof Error, 'has error')
|
|
867
912
|
t.notOk(data, 'no data')
|
|
868
913
|
}))
|