bl 6.0.19 → 6.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/BufferList.d.ts +13 -0
- package/BufferList.js +28 -7
- package/CHANGELOG.md +12 -0
- package/README.md +14 -2
- package/package.json +2 -2
- package/test/test.js +84 -0
package/BufferList.d.ts
CHANGED
|
@@ -45,6 +45,14 @@ interface BufferList {
|
|
|
45
45
|
|
|
46
46
|
append(buffer: BufferListAcceptedTypes): this;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Adds an additional buffer or BufferList at the beginning of the internal list.
|
|
50
|
+
* this is returned so it can be chained.
|
|
51
|
+
*
|
|
52
|
+
* @param buffer
|
|
53
|
+
*/
|
|
54
|
+
prepend(buffer: BufferListAcceptedTypes): this;
|
|
55
|
+
|
|
48
56
|
/**
|
|
49
57
|
* Will return the byte at the specified index.
|
|
50
58
|
* @param index
|
|
@@ -169,6 +177,11 @@ interface BufferList {
|
|
|
169
177
|
encoding?: string
|
|
170
178
|
): number;
|
|
171
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Will return the internal list of buffers.
|
|
182
|
+
*/
|
|
183
|
+
getBuffers(): Buffer[];
|
|
184
|
+
|
|
172
185
|
/**
|
|
173
186
|
* All of the standard byte-reading methods of the Buffer interface are implemented and will operate across internal Buffer boundaries transparently.
|
|
174
187
|
* See the [Buffer](http://nodejs.org/docs/latest/api/buffer.html) documentation for how these work.
|
package/BufferList.js
CHANGED
|
@@ -53,6 +53,10 @@ BufferList.prototype._reverseOffset = function (blOffset) {
|
|
|
53
53
|
return offset
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
BufferList.prototype.getBuffers = function getBuffers () {
|
|
57
|
+
return this._bufs
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
BufferList.prototype.get = function get (index) {
|
|
57
61
|
if (index > this.length || index < 0) {
|
|
58
62
|
return undefined
|
|
@@ -223,21 +227,33 @@ BufferList.prototype.duplicate = function duplicate () {
|
|
|
223
227
|
}
|
|
224
228
|
|
|
225
229
|
BufferList.prototype.append = function append (buf) {
|
|
230
|
+
return this._attach(buf, BufferList.prototype._appendBuffer)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
BufferList.prototype.prepend = function prepend (buf) {
|
|
234
|
+
return this._attach(buf, BufferList.prototype._prependBuffer, true)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
BufferList.prototype._attach = function _attach (buf, attacher, prepend) {
|
|
226
238
|
if (buf == null) {
|
|
227
239
|
return this
|
|
228
240
|
}
|
|
229
241
|
|
|
230
242
|
if (buf.buffer) {
|
|
231
|
-
// append a view of the underlying ArrayBuffer
|
|
232
|
-
|
|
243
|
+
// append/prepend a view of the underlying ArrayBuffer
|
|
244
|
+
attacher.call(this, Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength))
|
|
233
245
|
} else if (Array.isArray(buf)) {
|
|
234
|
-
|
|
235
|
-
|
|
246
|
+
const [starting, modifier] = prepend ? [buf.length - 1, -1] : [0, 1]
|
|
247
|
+
|
|
248
|
+
for (let i = starting; i >= 0 && i < buf.length; i += modifier) {
|
|
249
|
+
this._attach(buf[i], attacher, prepend)
|
|
236
250
|
}
|
|
237
251
|
} else if (this._isBufferList(buf)) {
|
|
238
252
|
// unwrap argument into individual BufferLists
|
|
239
|
-
|
|
240
|
-
|
|
253
|
+
const [starting, modifier] = prepend ? [buf._bufs.length - 1, -1] : [0, 1]
|
|
254
|
+
|
|
255
|
+
for (let i = starting; i >= 0 && i < buf._bufs.length; i += modifier) {
|
|
256
|
+
this._attach(buf._bufs[i], attacher, prepend)
|
|
241
257
|
}
|
|
242
258
|
} else {
|
|
243
259
|
// coerce number arguments to strings, since Buffer(number) does
|
|
@@ -246,7 +262,7 @@ BufferList.prototype.append = function append (buf) {
|
|
|
246
262
|
buf = buf.toString()
|
|
247
263
|
}
|
|
248
264
|
|
|
249
|
-
|
|
265
|
+
attacher.call(this, Buffer.from(buf))
|
|
250
266
|
}
|
|
251
267
|
|
|
252
268
|
return this
|
|
@@ -257,6 +273,11 @@ BufferList.prototype._appendBuffer = function appendBuffer (buf) {
|
|
|
257
273
|
this.length += buf.length
|
|
258
274
|
}
|
|
259
275
|
|
|
276
|
+
BufferList.prototype._prependBuffer = function prependBuffer (buf) {
|
|
277
|
+
this._bufs.unshift(buf)
|
|
278
|
+
this.length += buf.length
|
|
279
|
+
}
|
|
280
|
+
|
|
260
281
|
BufferList.prototype.indexOf = function (search, offset, encoding) {
|
|
261
282
|
if (encoding === undefined && typeof offset === 'string') {
|
|
262
283
|
encoding = offset
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [6.1.0](https://github.com/rvagg/bl/compare/v6.0.20...v6.1.0) (2025-03-11)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* Added prepend and getBuffers methods. ([#154](https://github.com/rvagg/bl/issues/154)) ([e9eda95](https://github.com/rvagg/bl/commit/e9eda9549b1235af16afbe0c721f92e705109663))
|
|
6
|
+
|
|
7
|
+
## [6.0.20](https://github.com/rvagg/bl/compare/v6.0.19...v6.0.20) (2025-03-03)
|
|
8
|
+
|
|
9
|
+
### Trivial Changes
|
|
10
|
+
|
|
11
|
+
* **deps-dev:** bump typescript from 5.7.3 to 5.8.2 ([#153](https://github.com/rvagg/bl/issues/153)) ([9291cf9](https://github.com/rvagg/bl/commit/9291cf9ec4b3cdef8c5779c73247844f48943c02))
|
|
12
|
+
|
|
1
13
|
## [6.0.19](https://github.com/rvagg/bl/compare/v6.0.18...v6.0.19) (2025-01-28)
|
|
2
14
|
|
|
3
15
|
### Trivial Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# bl *(BufferList)*
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
5
|
**A Node.js Buffer list collector, reader and streamer thingy.**
|
|
6
6
|
|
|
@@ -90,6 +90,7 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
|
|
|
90
90
|
* <a href="#isBufferList"><code><b>BufferList.isBufferList(obj)</b></code></a>
|
|
91
91
|
* <a href="#length"><code>bl.<b>length</b></code></a>
|
|
92
92
|
* <a href="#append"><code>bl.<b>append(buffer)</b></code></a>
|
|
93
|
+
* <a href="#prepend"><code>bl.<b>append(buffer)</b></code></a>
|
|
93
94
|
* <a href="#get"><code>bl.<b>get(index)</b></code></a>
|
|
94
95
|
* <a href="#indexOf"><code>bl.<b>indexOf(value[, byteOffset][, encoding])</b></code></a>
|
|
95
96
|
* <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
|
|
@@ -100,7 +101,8 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
|
|
|
100
101
|
* <a href="#toString"><code>bl.<b>toString([encoding, [ start, [ end ]]])</b></code></a>
|
|
101
102
|
* <a href="#readXX"><code>bl.<b>readDoubleBE()</b></code>, <code>bl.<b>readDoubleLE()</b></code>, <code>bl.<b>readFloatBE()</b></code>, <code>bl.<b>readFloatLE()</b></code>, <code>bl.<b>readBigInt64BE()</b></code>, <code>bl.<b>readBigInt64LE()</b></code>, <code>bl.<b>readBigUInt64BE()</b></code>, <code>bl.<b>readBigUInt64LE()</b></code>, <code>bl.<b>readInt32BE()</b></code>, <code>bl.<b>readInt32LE()</b></code>, <code>bl.<b>readUInt32BE()</b></code>, <code>bl.<b>readUInt32LE()</b></code>, <code>bl.<b>readInt16BE()</b></code>, <code>bl.<b>readInt16LE()</b></code>, <code>bl.<b>readUInt16BE()</b></code>, <code>bl.<b>readUInt16LE()</b></code>, <code>bl.<b>readInt8()</b></code>, <code>bl.<b>readUInt8()</b></code></a>
|
|
102
103
|
* <a href="#ctorStream"><code><b>new BufferListStream([ callback ])</b></code></a>
|
|
103
|
-
|
|
104
|
+
* <a href="#getBuffers"><code>bl.<b>getBuffers()</b></code></a>
|
|
105
|
+
|
|
104
106
|
--------------------------------------------------------
|
|
105
107
|
<a name="ctor"></a>
|
|
106
108
|
### new BufferList([ Buffer | Buffer array | BufferList | BufferList array | String ])
|
|
@@ -135,6 +137,11 @@ Get the length of the list in bytes. This is the sum of the lengths of all of th
|
|
|
135
137
|
### bl.append(Buffer | Buffer array | BufferList | BufferList array | String)
|
|
136
138
|
`append(buffer)` adds an additional buffer or BufferList to the internal list. `this` is returned so it can be chained.
|
|
137
139
|
|
|
140
|
+
--------------------------------------------------------
|
|
141
|
+
<a name="prepend"></a>
|
|
142
|
+
### bl.prepend(Buffer | Buffer array | BufferList | BufferList array | String)
|
|
143
|
+
`prepend(buffer)` adds an additional buffer or BufferList at the beginning of the internal list. `this` is returned so it can be chained.
|
|
144
|
+
|
|
138
145
|
--------------------------------------------------------
|
|
139
146
|
<a name="get"></a>
|
|
140
147
|
### bl.get(index)
|
|
@@ -230,6 +237,11 @@ const BufferListStream = require('bl')
|
|
|
230
237
|
```
|
|
231
238
|
|
|
232
239
|
--------------------------------------------------------
|
|
240
|
+
<a name="getBuffers"></a>
|
|
241
|
+
### bl.getBuffers()
|
|
242
|
+
|
|
243
|
+
`getBuffers()` returns the internal list of buffers.
|
|
244
|
+
|
|
233
245
|
|
|
234
246
|
## Contributors
|
|
235
247
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bl",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.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",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"faucet": "~0.0.1",
|
|
38
38
|
"standard": "^17.0.0",
|
|
39
39
|
"tape": "^5.2.2",
|
|
40
|
-
"typescript": "~5.
|
|
40
|
+
"typescript": "~5.8.2"
|
|
41
41
|
},
|
|
42
42
|
"release": {
|
|
43
43
|
"branches": [
|
package/test/test.js
CHANGED
|
@@ -249,6 +249,78 @@ tape('append chainable (test results)', function (t) {
|
|
|
249
249
|
t.end()
|
|
250
250
|
})
|
|
251
251
|
|
|
252
|
+
tape('prepend accepts arrays of Buffers', function (t) {
|
|
253
|
+
const bl = new BufferListStream()
|
|
254
|
+
|
|
255
|
+
bl.prepend(Buffer.from('abc'))
|
|
256
|
+
bl.prepend([Buffer.from('def')])
|
|
257
|
+
bl.prepend([Buffer.from('ghi'), Buffer.from('jkl')])
|
|
258
|
+
bl.prepend([Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz')])
|
|
259
|
+
t.equal(bl.length, 26)
|
|
260
|
+
t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
|
|
261
|
+
|
|
262
|
+
t.end()
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
tape('prepend accepts arrays of Uint8Arrays', function (t) {
|
|
266
|
+
const bl = new BufferListStream()
|
|
267
|
+
|
|
268
|
+
bl.prepend(new Uint8Array([97, 98, 99]))
|
|
269
|
+
bl.prepend([Uint8Array.from([100, 101, 102])])
|
|
270
|
+
bl.prepend([new Uint8Array([103, 104, 105]), new Uint8Array([106, 107, 108])])
|
|
271
|
+
bl.prepend([new Uint8Array([109, 110, 111, 112]), new Uint8Array([113, 114, 115, 116, 117]), new Uint8Array([118, 119, 120, 121, 122])])
|
|
272
|
+
t.equal(bl.length, 26)
|
|
273
|
+
t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
|
|
274
|
+
|
|
275
|
+
t.end()
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
tape('prepend accepts arrays of BufferLists', function (t) {
|
|
279
|
+
const bl = new BufferListStream()
|
|
280
|
+
|
|
281
|
+
bl.prepend(Buffer.from('abc'))
|
|
282
|
+
bl.prepend([new BufferListStream('def')])
|
|
283
|
+
bl.prepend(
|
|
284
|
+
new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
|
|
285
|
+
)
|
|
286
|
+
bl.prepend([
|
|
287
|
+
Buffer.from('mnop'),
|
|
288
|
+
new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
|
|
289
|
+
])
|
|
290
|
+
t.equal(bl.length, 26)
|
|
291
|
+
t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
|
|
292
|
+
|
|
293
|
+
t.end()
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
tape('prepend chainable', function (t) {
|
|
297
|
+
const bl = new BufferListStream()
|
|
298
|
+
|
|
299
|
+
t.ok(bl.prepend(Buffer.from('abcd')) === bl)
|
|
300
|
+
t.ok(bl.prepend([Buffer.from('abcd')]) === bl)
|
|
301
|
+
t.ok(bl.prepend(new BufferListStream(Buffer.from('abcd'))) === bl)
|
|
302
|
+
t.ok(bl.prepend([new BufferListStream(Buffer.from('abcd'))]) === bl)
|
|
303
|
+
|
|
304
|
+
t.end()
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
tape('prepend chainable (test results)', function (t) {
|
|
308
|
+
const bl = new BufferListStream('abc')
|
|
309
|
+
.prepend([new BufferListStream('def')])
|
|
310
|
+
.prepend(
|
|
311
|
+
new BufferListStream([Buffer.from('ghi'), new BufferListStream('jkl')])
|
|
312
|
+
)
|
|
313
|
+
.prepend([
|
|
314
|
+
Buffer.from('mnop'),
|
|
315
|
+
new BufferListStream([Buffer.from('qrstu'), Buffer.from('vwxyz')])
|
|
316
|
+
])
|
|
317
|
+
|
|
318
|
+
t.equal(bl.length, 26)
|
|
319
|
+
t.equal(bl.slice().toString('ascii'), 'mnopqrstuvwxyzghijkldefabc')
|
|
320
|
+
|
|
321
|
+
t.end()
|
|
322
|
+
})
|
|
323
|
+
|
|
252
324
|
tape('consuming from multiple buffers', function (t) {
|
|
253
325
|
const bl = new BufferListStream()
|
|
254
326
|
|
|
@@ -555,6 +627,18 @@ tape('test toString encoding', function (t) {
|
|
|
555
627
|
t.end()
|
|
556
628
|
})
|
|
557
629
|
|
|
630
|
+
tape('getBuffers', function (t) {
|
|
631
|
+
const bl = new BufferListStream([Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')])
|
|
632
|
+
|
|
633
|
+
t.deepEquals(
|
|
634
|
+
bl.getBuffers(),
|
|
635
|
+
// @ts-ignore
|
|
636
|
+
bl._bufs
|
|
637
|
+
)
|
|
638
|
+
|
|
639
|
+
t.end()
|
|
640
|
+
})
|
|
641
|
+
|
|
558
642
|
tape('uninitialized memory', function (t) {
|
|
559
643
|
const secret = crypto.randomBytes(256)
|
|
560
644
|
for (let i = 0; i < 1e6; i++) {
|