bl 6.1.6 → 7.0.1
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 +4 -0
- package/.github/workflows/test-and-release.yml +18 -21
- package/BufferList.js +399 -317
- package/BufferListStream.js +134 -0
- package/CHANGELOG.md +28 -0
- package/README.md +49 -63
- package/package.json +32 -18
- package/test/convert.js +3 -5
- package/test/indexOf.js +3 -5
- package/test/isBufferList.js +3 -5
- package/test/test.js +27 -27
- package/test/types.ts +89 -0
- package/test/verify-types.js +51 -0
- package/tsconfig.json +24 -0
- package/types/BufferList.d.ts +109 -0
- package/types/BufferList.d.ts.map +1 -0
- package/types/BufferListStream.d.ts +54 -0
- package/types/BufferListStream.d.ts.map +1 -0
- package/types/augment.d.ts +50 -0
- package/types/index.d.ts +4 -0
- package/BufferList.d.ts +0 -431
- package/bl.js +0 -84
- package/index.d.ts +0 -88
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Duplex } from 'node:stream'
|
|
2
|
+
import { BufferList } from './BufferList.js'
|
|
3
|
+
|
|
4
|
+
const symbol = Symbol.for('BufferList')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import('./BufferList.js').BufferListAcceptedTypes} BufferListAcceptedTypes
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export class BufferListStream extends Duplex {
|
|
11
|
+
/**
|
|
12
|
+
* @param {((err: Error | null, buffer?: Buffer) => void) | BufferListAcceptedTypes} [callback]
|
|
13
|
+
*/
|
|
14
|
+
constructor (callback) {
|
|
15
|
+
super()
|
|
16
|
+
|
|
17
|
+
if (typeof callback === 'function') {
|
|
18
|
+
this._callback = callback
|
|
19
|
+
|
|
20
|
+
/** @param {Error} err */
|
|
21
|
+
const piper = (err) => {
|
|
22
|
+
if (this._callback) {
|
|
23
|
+
this._callback(err)
|
|
24
|
+
this._callback = undefined
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.on('pipe', (src) => {
|
|
29
|
+
src.on('error', piper)
|
|
30
|
+
})
|
|
31
|
+
this.on('unpipe', (src) => {
|
|
32
|
+
src.removeListener('error', piper)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
callback = undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Object.defineProperty(this, symbol, { value: true })
|
|
39
|
+
/** @type {Buffer[]} */
|
|
40
|
+
this._bufs = []
|
|
41
|
+
/** @type {number} */
|
|
42
|
+
this.length = 0
|
|
43
|
+
|
|
44
|
+
if (callback) {
|
|
45
|
+
/** @type {any} */ (this).append(callback)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {any} buf
|
|
51
|
+
* @param {string} encoding
|
|
52
|
+
* @param {Function} callback
|
|
53
|
+
*/
|
|
54
|
+
_write (buf, encoding, callback) {
|
|
55
|
+
/** @type {any} */ (this)._appendBuffer(buf)
|
|
56
|
+
if (typeof callback === 'function') {
|
|
57
|
+
callback()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {number} size */
|
|
62
|
+
_read (size) {
|
|
63
|
+
if (!this.length) {
|
|
64
|
+
return this.push(null)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const self = /** @type {any} */ (this)
|
|
68
|
+
size = Math.min(size, this.length)
|
|
69
|
+
this.push(self.slice(0, size))
|
|
70
|
+
self.consume(size)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {any} [chunk]
|
|
75
|
+
* @param {any} [encoding]
|
|
76
|
+
* @param {any} [cb]
|
|
77
|
+
* @returns {this}
|
|
78
|
+
*/
|
|
79
|
+
end (chunk, encoding, cb) {
|
|
80
|
+
Duplex.prototype.end.call(this, chunk, encoding, cb)
|
|
81
|
+
|
|
82
|
+
if (this._callback) {
|
|
83
|
+
this._callback(null, /** @type {any} */ (this).slice())
|
|
84
|
+
this._callback = undefined
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return this
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {Error | null} err
|
|
92
|
+
* @param {Function} cb
|
|
93
|
+
*/
|
|
94
|
+
_destroy (err, cb) {
|
|
95
|
+
this._bufs.length = 0
|
|
96
|
+
this.length = 0
|
|
97
|
+
cb(err)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @param {any} [callback] */
|
|
101
|
+
_new (callback) {
|
|
102
|
+
return new BufferListStream(callback)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {any} b
|
|
107
|
+
* @returns {b is BufferList}
|
|
108
|
+
*/
|
|
109
|
+
_isBufferList (b) {
|
|
110
|
+
return b instanceof BufferListStream || b instanceof BufferList || BufferListStream.isBufferList(b)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {any} b
|
|
115
|
+
* @returns {boolean}
|
|
116
|
+
*/
|
|
117
|
+
static isBufferList (b) {
|
|
118
|
+
return BufferList.isBufferList(b)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Copy BufferList prototype methods to BufferListStream prototype
|
|
123
|
+
for (const key of Object.getOwnPropertyNames(BufferList.prototype)) {
|
|
124
|
+
if (key === 'constructor' || key === '_new' || key === '_isBufferList') continue
|
|
125
|
+
const descriptor = Object.getOwnPropertyDescriptor(BufferList.prototype, key)
|
|
126
|
+
if (descriptor) {
|
|
127
|
+
Object.defineProperty(BufferListStream.prototype, key, descriptor)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default BufferListStream
|
|
132
|
+
export { BufferList }
|
|
133
|
+
/** @type {(b: any) => boolean} */
|
|
134
|
+
export const isBufferList = BufferList.isBufferList
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [7.0.1](https://github.com/rvagg/bl/compare/v7.0.0...v7.0.1) (2026-04-28)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* properly exclude tsconfig.tsbuildinfo ([34a382b](https://github.com/rvagg/bl/commit/34a382bd94e8f2a697351b294b0146b6dafe5cc6))
|
|
6
|
+
|
|
7
|
+
### Trivial Changes
|
|
8
|
+
|
|
9
|
+
* **deps:** bump actions/setup-node from 6.3.0 to 6.4.0 ([d06d140](https://github.com/rvagg/bl/commit/d06d140ffdf577ee5c2bee284f84fcf798517c09))
|
|
10
|
+
|
|
11
|
+
## [7.0.0](https://github.com/rvagg/bl/compare/v6.1.6...v7.0.0) (2026-04-14)
|
|
12
|
+
|
|
13
|
+
### ⚠ BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* CJS require() no longer supported, use ESM import.
|
|
16
|
+
BufferList and BufferListStream must be called with new.
|
|
17
|
+
Switches from readable-stream to node:stream and buffer to node:buffer,
|
|
18
|
+
removing all runtime dependencies. Node.js >= 20 required.
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* modernise to ESM, drop all runtime dependencies ([#169](https://github.com/rvagg/bl/issues/169)) ([fbd6e13](https://github.com/rvagg/bl/commit/fbd6e1367f0d56012ad22ac4cbc6e1737011bffc))
|
|
23
|
+
|
|
24
|
+
### Trivial Changes
|
|
25
|
+
|
|
26
|
+
* **deps:** bump actions/setup-node from 6.1.0 to 6.2.0 ([#164](https://github.com/rvagg/bl/issues/164)) ([ee438e6](https://github.com/rvagg/bl/commit/ee438e62aba6941d1b99a98d5cc29dcda709915f))
|
|
27
|
+
* **deps:** bump actions/setup-node from 6.2.0 to 6.3.0 ([#166](https://github.com/rvagg/bl/issues/166)) ([265c92a](https://github.com/rvagg/bl/commit/265c92a11cf4e04845f6c739e652374c2c10dc5a))
|
|
28
|
+
|
|
1
29
|
## [6.1.6](https://github.com/rvagg/bl/compare/v6.1.5...v6.1.6) (2025-12-04)
|
|
2
30
|
|
|
3
31
|
### Trivial Changes
|
package/README.md
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
# bl *(BufferList)*
|
|
2
2
|
|
|
3
|
-
](https://nodei.co/npm/bl/)
|
|
4
4
|
|
|
5
5
|
**A Node.js Buffer list collector, reader and streamer thingy.**
|
|
6
6
|
|
|
7
|
-
[](https://nodei.co/npm/bl/)
|
|
8
|
-
|
|
9
7
|
**bl** is a storage object for collections of Node Buffers, exposing them with the main Buffer readable API. Also works as a duplex stream so you can collect buffers from a stream that emits them and emit buffers to a stream that consumes them!
|
|
10
8
|
|
|
11
9
|
The original buffers are kept intact and copies are only done as necessary. Any reads that require the use of a single original buffer will return a slice of that buffer only (which references the same memory as the original buffer). Reads that span buffers perform concatenation as required and return the results transparently.
|
|
12
10
|
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install bl
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Basic Usage
|
|
18
|
+
|
|
13
19
|
```js
|
|
14
|
-
|
|
20
|
+
import { BufferList } from 'bl'
|
|
15
21
|
|
|
16
22
|
const bl = new BufferList()
|
|
17
23
|
bl.append(Buffer.from('abcd'))
|
|
@@ -41,47 +47,35 @@ console.log(bl.readUInt16BE(10)) // 0x0304
|
|
|
41
47
|
console.log(bl.readUInt16LE(10)) // 0x0403
|
|
42
48
|
```
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
const { BufferListStream } = require('bl')
|
|
48
|
-
const fs = require('fs')
|
|
49
|
-
|
|
50
|
-
fs.createReadStream('README.md')
|
|
51
|
-
.pipe(BufferListStream((err, data) => { // note 'new' isn't strictly required
|
|
52
|
-
// `data` is a complete Buffer object containing the full data
|
|
53
|
-
console.log(data.toString())
|
|
54
|
-
}))
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Note that when you use the *callback* method like this, the resulting `data` parameter is a concatenation of all `Buffer` objects in the list. If you want to avoid the overhead of this concatenation (in cases of extreme performance consciousness), then avoid the *callback* method and just listen to `'end'` instead, like a standard Stream.
|
|
50
|
+
### Node.js Streams
|
|
58
51
|
|
|
59
|
-
|
|
52
|
+
Collect the contents of a stream:
|
|
60
53
|
|
|
61
54
|
```js
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
import { BufferListStream } from 'bl'
|
|
56
|
+
import { pipeline } from 'node:stream/promises'
|
|
57
|
+
import { Readable } from 'node:stream'
|
|
64
58
|
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}))
|
|
59
|
+
const response = await fetch('https://raw.githubusercontent.com/rvagg/bl/master/README.md')
|
|
60
|
+
const bl = new BufferListStream()
|
|
61
|
+
await pipeline(Readable.fromWeb(response.body), bl)
|
|
62
|
+
console.log(bl.toString())
|
|
70
63
|
```
|
|
71
64
|
|
|
72
|
-
Or
|
|
65
|
+
Or use it as a readable stream to pipe to an output:
|
|
73
66
|
|
|
74
67
|
```js
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
import BufferListStream from 'bl'
|
|
69
|
+
import { pipeline } from 'node:stream/promises'
|
|
70
|
+
import fs from 'node:fs'
|
|
77
71
|
|
|
78
|
-
|
|
72
|
+
const bl = new BufferListStream()
|
|
79
73
|
bl.append(Buffer.from('abcd'))
|
|
80
74
|
bl.append(Buffer.from('efg'))
|
|
81
75
|
bl.append(Buffer.from('hi'))
|
|
82
76
|
bl.append(Buffer.from('j'))
|
|
83
77
|
|
|
84
|
-
bl
|
|
78
|
+
await pipeline(bl, fs.createWriteStream('gibberish.txt'))
|
|
85
79
|
```
|
|
86
80
|
|
|
87
81
|
## API
|
|
@@ -90,7 +84,7 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
|
|
|
90
84
|
* <a href="#isBufferList"><code><b>BufferList.isBufferList(obj)</b></code></a>
|
|
91
85
|
* <a href="#length"><code>bl.<b>length</b></code></a>
|
|
92
86
|
* <a href="#append"><code>bl.<b>append(buffer)</b></code></a>
|
|
93
|
-
* <a href="#prepend"><code>bl.<b>
|
|
87
|
+
* <a href="#prepend"><code>bl.<b>prepend(buffer)</b></code></a>
|
|
94
88
|
* <a href="#get"><code>bl.<b>get(index)</b></code></a>
|
|
95
89
|
* <a href="#indexOf"><code>bl.<b>indexOf(value[, byteOffset][, encoding])</b></code></a>
|
|
96
90
|
* <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
|
|
@@ -102,21 +96,14 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
|
|
|
102
96
|
* <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>
|
|
103
97
|
* <a href="#ctorStream"><code><b>new BufferListStream([ callback ])</b></code></a>
|
|
104
98
|
* <a href="#getBuffers"><code>bl.<b>getBuffers()</b></code></a>
|
|
105
|
-
|
|
99
|
+
|
|
106
100
|
--------------------------------------------------------
|
|
107
101
|
<a name="ctor"></a>
|
|
108
102
|
### new BufferList([ Buffer | Buffer array | BufferList | BufferList array | String ])
|
|
109
103
|
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.
|
|
110
104
|
|
|
111
|
-
`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:
|
|
112
|
-
|
|
113
105
|
```js
|
|
114
|
-
|
|
115
|
-
const bl = BufferList()
|
|
116
|
-
|
|
117
|
-
// equivalent to:
|
|
118
|
-
|
|
119
|
-
const { BufferList } = require('bl')
|
|
106
|
+
import { BufferList } from 'bl'
|
|
120
107
|
const bl = new BufferList()
|
|
121
108
|
```
|
|
122
109
|
|
|
@@ -150,7 +137,6 @@ Get the length of the list in bytes. This is the sum of the lengths of all of th
|
|
|
150
137
|
--------------------------------------------------------
|
|
151
138
|
<a name="indexOf"></a>
|
|
152
139
|
### bl.indexOf(value[, byteOffset][, encoding])
|
|
153
|
-
`get()` will return the byte at the specified index.
|
|
154
140
|
`indexOf()` method returns the first index at which a given element can be found in the BufferList, or -1 if it is not present.
|
|
155
141
|
|
|
156
142
|
--------------------------------------------------------
|
|
@@ -175,10 +161,12 @@ No copies will be performed. All buffers in the result share memory with the ori
|
|
|
175
161
|
--------------------------------------------------------
|
|
176
162
|
<a name="duplicate"></a>
|
|
177
163
|
### bl.duplicate()
|
|
178
|
-
`duplicate()` 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:
|
|
164
|
+
`duplicate()` 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:
|
|
179
165
|
|
|
180
166
|
```js
|
|
181
|
-
|
|
167
|
+
import BufferListStream from 'bl'
|
|
168
|
+
|
|
169
|
+
const bl = new BufferListStream()
|
|
182
170
|
|
|
183
171
|
bl.append('hello')
|
|
184
172
|
bl.append(' world')
|
|
@@ -192,7 +180,7 @@ console.log(bl.toString())
|
|
|
192
180
|
--------------------------------------------------------
|
|
193
181
|
<a name="consume"></a>
|
|
194
182
|
### bl.consume(bytes)
|
|
195
|
-
`consume()` 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
|
|
183
|
+
`consume()` 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.
|
|
196
184
|
|
|
197
185
|
--------------------------------------------------------
|
|
198
186
|
<a name="toString"></a>
|
|
@@ -214,26 +202,14 @@ See the <b><code>[Buffer](http://nodejs.org/docs/latest/api/buffer.html)</code><
|
|
|
214
202
|
|
|
215
203
|
The constructor takes an optional callback, if supplied, the callback will be called with an error argument followed by a reference to the **bl** instance, when `bl.end()` is called (i.e. from a piped stream). This is a convenient method of collecting the entire contents of a stream, particularly when the stream is *chunky*, such as a network stream.
|
|
216
204
|
|
|
217
|
-
Normally, 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`
|
|
218
|
-
|
|
219
|
-
`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:
|
|
220
|
-
|
|
221
|
-
```js
|
|
222
|
-
const { BufferListStream } = require('bl')
|
|
223
|
-
const bl = BufferListStream()
|
|
224
|
-
|
|
225
|
-
// equivalent to:
|
|
226
|
-
|
|
227
|
-
const { BufferListStream } = require('bl')
|
|
228
|
-
const bl = new BufferListStream()
|
|
229
|
-
```
|
|
205
|
+
Normally, 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.
|
|
230
206
|
|
|
231
|
-
N.B. For backwards compatibility reasons, `BufferListStream` is the **default** export when you `
|
|
207
|
+
N.B. For backwards compatibility reasons, `BufferListStream` is the **default** export when you `import from 'bl'`:
|
|
232
208
|
|
|
233
209
|
```js
|
|
234
|
-
|
|
210
|
+
import { BufferListStream } from 'bl'
|
|
235
211
|
// equivalent to:
|
|
236
|
-
|
|
212
|
+
import BufferListStream from 'bl'
|
|
237
213
|
```
|
|
238
214
|
|
|
239
215
|
--------------------------------------------------------
|
|
@@ -243,6 +219,16 @@ const BufferListStream = require('bl')
|
|
|
243
219
|
`getBuffers()` returns the internal list of buffers.
|
|
244
220
|
|
|
245
221
|
|
|
222
|
+
## Migrating from v6
|
|
223
|
+
|
|
224
|
+
v7 is a modernisation release:
|
|
225
|
+
|
|
226
|
+
* **ESM-only**: CommonJS `require('bl')` is no longer supported. Use `import` instead.
|
|
227
|
+
* **`new` is required**: `BufferListStream()` and `BufferList()` can no longer be called without `new`.
|
|
228
|
+
* **Zero runtime dependencies**: `readable-stream`, `buffer`, and `inherits` have been removed. `BufferListStream` now uses Node's built-in `node:stream` Duplex directly.
|
|
229
|
+
* **Node.js >= 20**: Browser bundling is no longer a supported use case. If you need buffer accumulation in the browser, consider working with `Uint8Array` directly.
|
|
230
|
+
|
|
231
|
+
|
|
246
232
|
## Contributors
|
|
247
233
|
|
|
248
234
|
**bl** is brought to you by the following hackers:
|
|
@@ -252,8 +238,8 @@ const BufferListStream = require('bl')
|
|
|
252
238
|
* [Jarett Cruger](https://github.com/jcrugzz)
|
|
253
239
|
|
|
254
240
|
<a name="license"></a>
|
|
255
|
-
## License &
|
|
241
|
+
## License & copyright
|
|
256
242
|
|
|
257
|
-
Copyright (c) 2013-
|
|
243
|
+
Copyright (c) 2013-2026 bl contributors (listed above).
|
|
258
244
|
|
|
259
245
|
bl is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
|
package/package.json
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bl",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too
|
|
3
|
+
"version": "7.0.1",
|
|
4
|
+
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"main": "./BufferListStream.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./BufferListStream.js",
|
|
14
|
+
"types": "./types/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
7
17
|
"scripts": {
|
|
8
|
-
"lint": "standard
|
|
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 --
|
|
12
|
-
"build": "
|
|
18
|
+
"lint": "standard BufferList.js BufferListStream.js test/*.js",
|
|
19
|
+
"test": "npm run lint && npm run build:types && npm run test:types && node test/test.js | faucet",
|
|
20
|
+
"test:ci": "npm run lint && node test/test.js && npm run build:types && npm run test:types",
|
|
21
|
+
"test:types": "tsc --noEmit --strict --module nodenext --moduleResolution nodenext --target esnext --skipLibCheck --types node test/types.ts --ignoreConfig && node test/verify-types.js",
|
|
22
|
+
"build:types": "tsc --build",
|
|
23
|
+
"build": "npm run build:types"
|
|
13
24
|
},
|
|
14
25
|
"repository": {
|
|
15
26
|
"type": "git",
|
|
@@ -27,17 +38,20 @@
|
|
|
27
38
|
"stream",
|
|
28
39
|
"awesomesauce"
|
|
29
40
|
],
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@types/readable-stream": "^4.0.0",
|
|
32
|
-
"buffer": "^6.0.3",
|
|
33
|
-
"inherits": "^2.0.4",
|
|
34
|
-
"readable-stream": "^4.2.0"
|
|
35
|
-
},
|
|
36
41
|
"devDependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
42
|
+
"@types/node": "^25.0.0",
|
|
43
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
44
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
45
|
+
"@semantic-release/git": "^10.0.1",
|
|
46
|
+
"@semantic-release/github": "^12.0.6",
|
|
47
|
+
"@semantic-release/npm": "^13.1.5",
|
|
48
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
49
|
+
"conventional-changelog-conventionalcommits": "^9.3.0",
|
|
50
|
+
"faucet": "^0.0.4",
|
|
51
|
+
"semantic-release": "^25.0.3",
|
|
52
|
+
"standard": "^17.1.2",
|
|
53
|
+
"tape": "^5.9.0",
|
|
54
|
+
"typescript": "^6.0.2"
|
|
41
55
|
},
|
|
42
56
|
"release": {
|
|
43
57
|
"branches": [
|
package/test/convert.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { BufferList, BufferListStream } = require('../')
|
|
5
|
-
const { Buffer } = require('buffer')
|
|
1
|
+
import tape from 'tape'
|
|
2
|
+
import { BufferList, BufferListStream } from '../BufferListStream.js'
|
|
3
|
+
import { Buffer } from 'node:buffer'
|
|
6
4
|
|
|
7
5
|
tape('convert from BufferList to BufferListStream', (t) => {
|
|
8
6
|
const data = Buffer.from(`TEST-${Date.now()}`)
|
package/test/indexOf.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const BufferList = require('../')
|
|
5
|
-
const { Buffer } = require('buffer')
|
|
1
|
+
import tape from 'tape'
|
|
2
|
+
import BufferList from '../BufferListStream.js'
|
|
3
|
+
import { Buffer } from 'node:buffer'
|
|
6
4
|
|
|
7
5
|
tape('indexOf single byte needle', (t) => {
|
|
8
6
|
const bl = new BufferList(['abcdefg', 'abcdefg', '12345'])
|
package/test/isBufferList.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { BufferList, BufferListStream } = require('../')
|
|
5
|
-
const { Buffer } = require('buffer')
|
|
1
|
+
import tape from 'tape'
|
|
2
|
+
import { BufferList, BufferListStream } from '../BufferListStream.js'
|
|
3
|
+
import { Buffer } from 'node:buffer'
|
|
6
4
|
|
|
7
5
|
tape('isBufferList positives', (t) => {
|
|
8
6
|
t.ok(BufferList.isBufferList(new BufferList()))
|
package/test/test.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import tape from 'tape'
|
|
3
|
+
import * as crypto from 'node:crypto'
|
|
4
|
+
import * as fs from 'node:fs'
|
|
5
|
+
import * as path from 'node:path'
|
|
6
|
+
import * as os from 'node:os'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
import BufferListStream from '../BufferListStream.js'
|
|
9
|
+
import { Buffer } from 'node:buffer'
|
|
10
|
+
import './indexOf.js'
|
|
11
|
+
import './isBufferList.js'
|
|
12
|
+
import './convert.js'
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* This typedef allows us to add _bufs to the API without declaring it publicly on types.
|
|
@@ -38,10 +42,6 @@ if (process.browser) {
|
|
|
38
42
|
)
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
require('./indexOf')
|
|
42
|
-
require('./isBufferList')
|
|
43
|
-
require('./convert')
|
|
44
|
-
|
|
45
45
|
tape('single bytes from single buffer', function (t) {
|
|
46
46
|
const bl = new BufferListStream()
|
|
47
47
|
|
|
@@ -685,10 +685,10 @@ tape('uninitialized memory', function (t) {
|
|
|
685
685
|
tape('instantiation with Buffer', function (t) {
|
|
686
686
|
const buf = crypto.randomBytes(1024)
|
|
687
687
|
const buf2 = crypto.randomBytes(1024)
|
|
688
|
-
let b = BufferListStream(buf)
|
|
688
|
+
let b = new BufferListStream(buf)
|
|
689
689
|
|
|
690
690
|
t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
|
|
691
|
-
b = BufferListStream([buf, buf2])
|
|
691
|
+
b = new BufferListStream([buf, buf2])
|
|
692
692
|
t.equal(b.slice().toString('hex'), Buffer.concat([buf, buf2]).toString('hex'), 'same buffer')
|
|
693
693
|
|
|
694
694
|
t.end()
|
|
@@ -729,7 +729,7 @@ tape('test Number appendage', function (t) {
|
|
|
729
729
|
|
|
730
730
|
tape('write nothing, should get empty buffer', function (t) {
|
|
731
731
|
t.plan(3)
|
|
732
|
-
BufferListStream(function (err, data) {
|
|
732
|
+
new BufferListStream(function (err, data) {
|
|
733
733
|
t.notOk(err, 'no error')
|
|
734
734
|
t.ok(Buffer.isBuffer(data), 'got a buffer')
|
|
735
735
|
t.equal(0, data.length, 'got a zero-length buffer')
|
|
@@ -743,7 +743,7 @@ tape('unicode string', function (t) {
|
|
|
743
743
|
const inp1 = '\u2600'
|
|
744
744
|
const inp2 = '\u2603'
|
|
745
745
|
const exp = inp1 + ' and ' + inp2
|
|
746
|
-
const bl = BufferListStream()
|
|
746
|
+
const bl = new BufferListStream()
|
|
747
747
|
|
|
748
748
|
bl.write(inp1)
|
|
749
749
|
bl.write(' and ')
|
|
@@ -753,8 +753,8 @@ tape('unicode string', function (t) {
|
|
|
753
753
|
})
|
|
754
754
|
|
|
755
755
|
tape('should emit finish', function (t) {
|
|
756
|
-
const source = BufferListStream()
|
|
757
|
-
const dest = BufferListStream()
|
|
756
|
+
const source = new BufferListStream()
|
|
757
|
+
const dest = new BufferListStream()
|
|
758
758
|
|
|
759
759
|
source.write('hello')
|
|
760
760
|
source.pipe(dest)
|
|
@@ -768,7 +768,7 @@ tape('should emit finish', function (t) {
|
|
|
768
768
|
tape('basic copy', function (t) {
|
|
769
769
|
const buf = crypto.randomBytes(1024)
|
|
770
770
|
const buf2 = Buffer.alloc(1024)
|
|
771
|
-
const b = BufferListStream(buf)
|
|
771
|
+
const b = new BufferListStream(buf)
|
|
772
772
|
|
|
773
773
|
b.copy(buf2)
|
|
774
774
|
t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
@@ -779,7 +779,7 @@ tape('basic copy', function (t) {
|
|
|
779
779
|
tape('copy after many appends', function (t) {
|
|
780
780
|
const buf = crypto.randomBytes(512)
|
|
781
781
|
const buf2 = Buffer.alloc(1024)
|
|
782
|
-
const b = BufferListStream(buf)
|
|
782
|
+
const b = new BufferListStream(buf)
|
|
783
783
|
|
|
784
784
|
b.append(buf)
|
|
785
785
|
b.copy(buf2)
|
|
@@ -791,7 +791,7 @@ tape('copy after many appends', function (t) {
|
|
|
791
791
|
tape('copy at a precise position', function (t) {
|
|
792
792
|
const buf = crypto.randomBytes(1004)
|
|
793
793
|
const buf2 = Buffer.alloc(1024)
|
|
794
|
-
const b = BufferListStream(buf)
|
|
794
|
+
const b = new BufferListStream(buf)
|
|
795
795
|
|
|
796
796
|
b.copy(buf2, 20)
|
|
797
797
|
t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
|
|
@@ -802,7 +802,7 @@ tape('copy at a precise position', function (t) {
|
|
|
802
802
|
tape('copy starting from a precise location', function (t) {
|
|
803
803
|
const buf = crypto.randomBytes(10)
|
|
804
804
|
const buf2 = Buffer.alloc(5)
|
|
805
|
-
const b = BufferListStream(buf)
|
|
805
|
+
const b = new BufferListStream(buf)
|
|
806
806
|
|
|
807
807
|
b.copy(buf2, 0, 5)
|
|
808
808
|
t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
|
|
@@ -812,7 +812,7 @@ tape('copy starting from a precise location', function (t) {
|
|
|
812
812
|
|
|
813
813
|
tape('copy in an interval', function (t) {
|
|
814
814
|
const rnd = crypto.randomBytes(10)
|
|
815
|
-
const b = BufferListStream(rnd) // put the random bytes there
|
|
815
|
+
const b = new BufferListStream(rnd) // put the random bytes there
|
|
816
816
|
const actual = Buffer.alloc(3)
|
|
817
817
|
const expected = Buffer.alloc(3)
|
|
818
818
|
|
|
@@ -827,7 +827,7 @@ tape('copy in an interval', function (t) {
|
|
|
827
827
|
tape('copy an interval between two buffers', function (t) {
|
|
828
828
|
const buf = crypto.randomBytes(10)
|
|
829
829
|
const buf2 = Buffer.alloc(10)
|
|
830
|
-
const b = BufferListStream(buf)
|
|
830
|
+
const b = new BufferListStream(buf)
|
|
831
831
|
|
|
832
832
|
b.append(buf)
|
|
833
833
|
b.copy(buf2, 0, 5, 15)
|
|
@@ -913,7 +913,7 @@ tape('duplicate', function (t) {
|
|
|
913
913
|
const bl = new BufferListStream('abcdefghij\xff\x00')
|
|
914
914
|
const dup = bl.duplicate()
|
|
915
915
|
|
|
916
|
-
t.equal(bl
|
|
916
|
+
t.equal(Object.getPrototypeOf(bl), Object.getPrototypeOf(dup))
|
|
917
917
|
t.equal(bl.toString('hex'), dup.toString('hex'))
|
|
918
918
|
})
|
|
919
919
|
|
|
@@ -1025,7 +1025,7 @@ tape('destroy with error', function (t) {
|
|
|
1025
1025
|
!process.browser && tape('handle error', function (t) {
|
|
1026
1026
|
t.plan(2)
|
|
1027
1027
|
|
|
1028
|
-
fs.createReadStream('/does/not/exist').pipe(BufferListStream(function (err, data) {
|
|
1028
|
+
fs.createReadStream('/does/not/exist').pipe(new BufferListStream(function (err, data) {
|
|
1029
1029
|
t.ok(err instanceof Error, 'has error')
|
|
1030
1030
|
t.notOk(data, 'no data')
|
|
1031
1031
|
}))
|