bl 2.2.1 → 3.0.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/.travis.yml +0 -2
- package/bl.js +3 -13
- package/package.json +3 -4
- package/test/test.js +14 -16
package/.travis.yml
CHANGED
package/bl.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
var DuplexStream = require('readable-stream').Duplex
|
|
3
3
|
, util = require('util')
|
|
4
|
-
, Buffer = require('safe-buffer').Buffer
|
|
5
4
|
|
|
6
5
|
function BufferList (callback) {
|
|
7
6
|
if (!(this instanceof BufferList))
|
|
@@ -186,22 +185,18 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
|
186
185
|
|
|
187
186
|
if (bytes > l) {
|
|
188
187
|
this._bufs[i].copy(dst, bufoff, start)
|
|
189
|
-
bufoff += l
|
|
190
188
|
} else {
|
|
191
189
|
this._bufs[i].copy(dst, bufoff, start, start + bytes)
|
|
192
|
-
bufoff += l
|
|
193
190
|
break
|
|
194
191
|
}
|
|
195
192
|
|
|
193
|
+
bufoff += l
|
|
196
194
|
bytes -= l
|
|
197
195
|
|
|
198
196
|
if (start)
|
|
199
197
|
start = 0
|
|
200
198
|
}
|
|
201
199
|
|
|
202
|
-
// safeguard so that we don't return uninitialized memory
|
|
203
|
-
if (dst.length > bufoff) return dst.slice(0, bufoff)
|
|
204
|
-
|
|
205
200
|
return dst
|
|
206
201
|
}
|
|
207
202
|
|
|
@@ -237,11 +232,6 @@ BufferList.prototype.toString = function toString (encoding, start, end) {
|
|
|
237
232
|
}
|
|
238
233
|
|
|
239
234
|
BufferList.prototype.consume = function consume (bytes) {
|
|
240
|
-
// first, normalize the argument, in accordance with how Buffer does it
|
|
241
|
-
bytes = Math.trunc(bytes)
|
|
242
|
-
// do nothing if not a positive number
|
|
243
|
-
if (Number.isNaN(bytes) || bytes <= 0) return this
|
|
244
|
-
|
|
245
235
|
while (this._bufs.length) {
|
|
246
236
|
if (bytes >= this._bufs[0].length) {
|
|
247
237
|
bytes -= this._bufs[0].length
|
|
@@ -268,10 +258,10 @@ BufferList.prototype.duplicate = function duplicate () {
|
|
|
268
258
|
}
|
|
269
259
|
|
|
270
260
|
|
|
271
|
-
BufferList.prototype.
|
|
261
|
+
BufferList.prototype._destroy = function _destroy (err, cb) {
|
|
272
262
|
this._bufs.length = 0
|
|
273
263
|
this.length = 0
|
|
274
|
-
|
|
264
|
+
cb(err)
|
|
275
265
|
}
|
|
276
266
|
|
|
277
267
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
|
|
5
5
|
"main": "bl.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,12 +24,11 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"readable-stream": "^
|
|
28
|
-
"safe-buffer": "^5.1.1"
|
|
27
|
+
"readable-stream": "^3.0.1"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"faucet": "0.0.1",
|
|
32
31
|
"hash_file": "~0.1.1",
|
|
33
|
-
"tape": "~4.9.
|
|
32
|
+
"tape": "~4.9.1"
|
|
34
33
|
}
|
|
35
34
|
}
|
package/test/test.js
CHANGED
|
@@ -431,22 +431,6 @@ tape('test toString encoding', function (t) {
|
|
|
431
431
|
t.end()
|
|
432
432
|
})
|
|
433
433
|
|
|
434
|
-
tape('uninitialized memory', function (t) {
|
|
435
|
-
const secret = crypto.randomBytes(256)
|
|
436
|
-
for (let i = 0; i < 1e6; i++) {
|
|
437
|
-
const clone = Buffer.from(secret)
|
|
438
|
-
const bl = new BufferList()
|
|
439
|
-
bl.append(Buffer.from('a'))
|
|
440
|
-
bl.consume(-1024)
|
|
441
|
-
const buf = bl.slice(1)
|
|
442
|
-
if (buf.indexOf(clone) !== -1) {
|
|
443
|
-
t.fail(`Match (at ${i})`)
|
|
444
|
-
break
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
t.end()
|
|
448
|
-
})
|
|
449
|
-
|
|
450
434
|
!process.browser && tape('test stream', function (t) {
|
|
451
435
|
var random = crypto.randomBytes(65534)
|
|
452
436
|
, rndhash = hash(random, 'md5')
|
|
@@ -699,6 +683,20 @@ tape('destroy no pipe', function (t) {
|
|
|
699
683
|
t.equal(bl.length, 0)
|
|
700
684
|
})
|
|
701
685
|
|
|
686
|
+
tape('destroy with error', function (t) {
|
|
687
|
+
t.plan(3)
|
|
688
|
+
|
|
689
|
+
var bl = new BufferList('alsdkfja;lsdkfja;lsdk')
|
|
690
|
+
var err = new Error('kaboom')
|
|
691
|
+
bl.destroy(err)
|
|
692
|
+
bl.on('error', function (_err) {
|
|
693
|
+
t.equal(_err, err)
|
|
694
|
+
})
|
|
695
|
+
|
|
696
|
+
t.equal(bl._bufs.length, 0)
|
|
697
|
+
t.equal(bl.length, 0)
|
|
698
|
+
})
|
|
699
|
+
|
|
702
700
|
!process.browser && tape('destroy with pipe before read end', function (t) {
|
|
703
701
|
t.plan(2)
|
|
704
702
|
|