bl 1.2.1 → 2.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/.travis.yml +3 -3
- package/LICENSE.md +1 -1
- package/README.md +2 -2
- package/bl.js +22 -8
- package/package.json +4 -3
- package/test/test.js +118 -73
- package/.npmignore +0 -1
package/.travis.yml
CHANGED
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ Normally, no arguments are required for the constructor, but you can initialise
|
|
|
108
108
|
var bl = require('bl')
|
|
109
109
|
var myinstance = bl()
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
// equivalent to:
|
|
112
112
|
|
|
113
113
|
var BufferList = require('bl')
|
|
114
114
|
var myinstance = new BufferList()
|
|
@@ -203,6 +203,6 @@ See the <b><code>[Buffer](http://nodejs.org/docs/latest/api/buffer.html)</code><
|
|
|
203
203
|
<a name="license"></a>
|
|
204
204
|
## License & copyright
|
|
205
205
|
|
|
206
|
-
Copyright (c) 2013-
|
|
206
|
+
Copyright (c) 2013-2018 bl contributors (listed above).
|
|
207
207
|
|
|
208
208
|
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/bl.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
var DuplexStream = require('readable-stream
|
|
1
|
+
var DuplexStream = require('readable-stream').Duplex
|
|
2
2
|
, util = require('util')
|
|
3
|
+
, Buffer = require('safe-buffer').Buffer
|
|
3
4
|
|
|
5
|
+
var tempBuffer = Buffer.alloc(1)
|
|
4
6
|
|
|
5
7
|
function BufferList (callback) {
|
|
6
8
|
if (!(this instanceof BufferList))
|
|
@@ -66,7 +68,7 @@ BufferList.prototype.append = function append (buf) {
|
|
|
66
68
|
if (typeof buf == 'number')
|
|
67
69
|
buf = buf.toString()
|
|
68
70
|
|
|
69
|
-
this._appendBuffer(
|
|
71
|
+
this._appendBuffer(Buffer.from(buf));
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
return this
|
|
@@ -108,7 +110,8 @@ BufferList.prototype.end = function end (chunk) {
|
|
|
108
110
|
|
|
109
111
|
|
|
110
112
|
BufferList.prototype.get = function get (index) {
|
|
111
|
-
|
|
113
|
+
this.copy(tempBuffer, 0, index, index + 1)
|
|
114
|
+
return tempBuffer[0]
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
|
|
@@ -127,9 +130,9 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
|
127
130
|
if (typeof srcEnd != 'number' || srcEnd > this.length)
|
|
128
131
|
srcEnd = this.length
|
|
129
132
|
if (srcStart >= this.length)
|
|
130
|
-
return dst ||
|
|
133
|
+
return dst || Buffer.alloc(0)
|
|
131
134
|
if (srcEnd <= 0)
|
|
132
|
-
return dst ||
|
|
135
|
+
return dst || Buffer.alloc(0)
|
|
133
136
|
|
|
134
137
|
var copy = !!dst
|
|
135
138
|
, off = this._offset(srcStart)
|
|
@@ -165,7 +168,7 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
if (!copy) // a slice, we need something to copy in to
|
|
168
|
-
dst =
|
|
171
|
+
dst = Buffer.allocUnsafe(len)
|
|
169
172
|
|
|
170
173
|
for (i = off[0]; i < this._bufs.length; i++) {
|
|
171
174
|
l = this._bufs[i].length - start
|
|
@@ -265,12 +268,23 @@ BufferList.prototype.destroy = function destroy () {
|
|
|
265
268
|
, 'readUInt16LE' : 2
|
|
266
269
|
, 'readInt8' : 1
|
|
267
270
|
, 'readUInt8' : 1
|
|
271
|
+
, 'readIntBE' : null
|
|
272
|
+
, 'readIntLE' : null
|
|
273
|
+
, 'readUIntBE' : null
|
|
274
|
+
, 'readUIntLE' : null
|
|
268
275
|
}
|
|
269
276
|
|
|
270
277
|
for (var m in methods) {
|
|
271
278
|
(function (m) {
|
|
272
|
-
|
|
273
|
-
|
|
279
|
+
if (methods[m] === null) {
|
|
280
|
+
BufferList.prototype[m] = function (offset, byteLength) {
|
|
281
|
+
return this.slice(offset, offset + byteLength)[m](0, byteLength)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
BufferList.prototype[m] = function (offset) {
|
|
286
|
+
return this.slice(offset, offset + methods[m])[m](0)
|
|
287
|
+
}
|
|
274
288
|
}
|
|
275
289
|
}(m))
|
|
276
290
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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,11 +24,12 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"readable-stream": "^2.
|
|
27
|
+
"readable-stream": "^2.3.5",
|
|
28
|
+
"safe-buffer": "^5.1.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"faucet": "0.0.1",
|
|
31
32
|
"hash_file": "~0.1.1",
|
|
32
|
-
"tape": "~4.
|
|
33
|
+
"tape": "~4.9.0"
|
|
33
34
|
}
|
|
34
35
|
}
|
package/test/test.js
CHANGED
|
@@ -3,6 +3,7 @@ var tape = require('tape')
|
|
|
3
3
|
, fs = require('fs')
|
|
4
4
|
, hash = require('hash_file')
|
|
5
5
|
, BufferList = require('../')
|
|
6
|
+
, Buffer = require('safe-buffer').Buffer
|
|
6
7
|
|
|
7
8
|
, encodings =
|
|
8
9
|
('hex utf8 utf-8 ascii binary base64'
|
|
@@ -10,7 +11,7 @@ var tape = require('tape')
|
|
|
10
11
|
|
|
11
12
|
tape('single bytes from single buffer', function (t) {
|
|
12
13
|
var bl = new BufferList()
|
|
13
|
-
bl.append(
|
|
14
|
+
bl.append(Buffer.from('abcd'))
|
|
14
15
|
|
|
15
16
|
t.equal(bl.length, 4)
|
|
16
17
|
|
|
@@ -24,10 +25,10 @@ tape('single bytes from single buffer', function (t) {
|
|
|
24
25
|
|
|
25
26
|
tape('single bytes from multiple buffers', function (t) {
|
|
26
27
|
var bl = new BufferList()
|
|
27
|
-
bl.append(
|
|
28
|
-
bl.append(
|
|
29
|
-
bl.append(
|
|
30
|
-
bl.append(
|
|
28
|
+
bl.append(Buffer.from('abcd'))
|
|
29
|
+
bl.append(Buffer.from('efg'))
|
|
30
|
+
bl.append(Buffer.from('hi'))
|
|
31
|
+
bl.append(Buffer.from('j'))
|
|
31
32
|
|
|
32
33
|
t.equal(bl.length, 10)
|
|
33
34
|
|
|
@@ -46,7 +47,7 @@ tape('single bytes from multiple buffers', function (t) {
|
|
|
46
47
|
|
|
47
48
|
tape('multi bytes from single buffer', function (t) {
|
|
48
49
|
var bl = new BufferList()
|
|
49
|
-
bl.append(
|
|
50
|
+
bl.append(Buffer.from('abcd'))
|
|
50
51
|
|
|
51
52
|
t.equal(bl.length, 4)
|
|
52
53
|
|
|
@@ -60,7 +61,7 @@ tape('multi bytes from single buffer', function (t) {
|
|
|
60
61
|
|
|
61
62
|
tape('multi bytes from single buffer (negative indexes)', function (t) {
|
|
62
63
|
var bl = new BufferList()
|
|
63
|
-
bl.append(
|
|
64
|
+
bl.append(Buffer.from('buffer'))
|
|
64
65
|
|
|
65
66
|
t.equal(bl.length, 6)
|
|
66
67
|
|
|
@@ -74,10 +75,10 @@ tape('multi bytes from single buffer (negative indexes)', function (t) {
|
|
|
74
75
|
tape('multiple bytes from multiple buffers', function (t) {
|
|
75
76
|
var bl = new BufferList()
|
|
76
77
|
|
|
77
|
-
bl.append(
|
|
78
|
-
bl.append(
|
|
79
|
-
bl.append(
|
|
80
|
-
bl.append(
|
|
78
|
+
bl.append(Buffer.from('abcd'))
|
|
79
|
+
bl.append(Buffer.from('efg'))
|
|
80
|
+
bl.append(Buffer.from('hi'))
|
|
81
|
+
bl.append(Buffer.from('j'))
|
|
81
82
|
|
|
82
83
|
t.equal(bl.length, 10)
|
|
83
84
|
|
|
@@ -94,8 +95,8 @@ tape('multiple bytes from multiple buffers', function (t) {
|
|
|
94
95
|
tape('multiple bytes from multiple buffer lists', function (t) {
|
|
95
96
|
var bl = new BufferList()
|
|
96
97
|
|
|
97
|
-
bl.append(new BufferList([
|
|
98
|
-
bl.append(new BufferList([
|
|
98
|
+
bl.append(new BufferList([ Buffer.from('abcd'), Buffer.from('efg') ]))
|
|
99
|
+
bl.append(new BufferList([ Buffer.from('hi'), Buffer.from('j') ]))
|
|
99
100
|
|
|
100
101
|
t.equal(bl.length, 10)
|
|
101
102
|
|
|
@@ -115,12 +116,12 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
|
|
|
115
116
|
|
|
116
117
|
bl.append(new BufferList([
|
|
117
118
|
new BufferList([
|
|
118
|
-
new BufferList(
|
|
119
|
-
,
|
|
120
|
-
, new BufferList(
|
|
119
|
+
new BufferList(Buffer.from('abc'))
|
|
120
|
+
, Buffer.from('d')
|
|
121
|
+
, new BufferList(Buffer.from('efg'))
|
|
121
122
|
])
|
|
122
|
-
, new BufferList([
|
|
123
|
-
, new BufferList(
|
|
123
|
+
, new BufferList([ Buffer.from('hi') ])
|
|
124
|
+
, new BufferList(Buffer.from('j'))
|
|
124
125
|
]))
|
|
125
126
|
|
|
126
127
|
t.equal(bl.length, 10)
|
|
@@ -137,10 +138,10 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
|
|
|
137
138
|
|
|
138
139
|
tape('append accepts arrays of Buffers', function (t) {
|
|
139
140
|
var bl = new BufferList()
|
|
140
|
-
bl.append(
|
|
141
|
-
bl.append([
|
|
142
|
-
bl.append([
|
|
143
|
-
bl.append([
|
|
141
|
+
bl.append(Buffer.from('abc'))
|
|
142
|
+
bl.append([ Buffer.from('def') ])
|
|
143
|
+
bl.append([ Buffer.from('ghi'), Buffer.from('jkl') ])
|
|
144
|
+
bl.append([ Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz') ])
|
|
144
145
|
t.equal(bl.length, 26)
|
|
145
146
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
146
147
|
t.end()
|
|
@@ -148,10 +149,10 @@ tape('append accepts arrays of Buffers', function (t) {
|
|
|
148
149
|
|
|
149
150
|
tape('append accepts arrays of BufferLists', function (t) {
|
|
150
151
|
var bl = new BufferList()
|
|
151
|
-
bl.append(
|
|
152
|
+
bl.append(Buffer.from('abc'))
|
|
152
153
|
bl.append([ new BufferList('def') ])
|
|
153
|
-
bl.append(new BufferList([
|
|
154
|
-
bl.append([
|
|
154
|
+
bl.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
|
|
155
|
+
bl.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
|
|
155
156
|
t.equal(bl.length, 26)
|
|
156
157
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
157
158
|
t.end()
|
|
@@ -159,18 +160,18 @@ tape('append accepts arrays of BufferLists', function (t) {
|
|
|
159
160
|
|
|
160
161
|
tape('append chainable', function (t) {
|
|
161
162
|
var bl = new BufferList()
|
|
162
|
-
t.ok(bl.append(
|
|
163
|
-
t.ok(bl.append([
|
|
164
|
-
t.ok(bl.append(new BufferList(
|
|
165
|
-
t.ok(bl.append([ new BufferList(
|
|
163
|
+
t.ok(bl.append(Buffer.from('abcd')) === bl)
|
|
164
|
+
t.ok(bl.append([ Buffer.from('abcd') ]) === bl)
|
|
165
|
+
t.ok(bl.append(new BufferList(Buffer.from('abcd'))) === bl)
|
|
166
|
+
t.ok(bl.append([ new BufferList(Buffer.from('abcd')) ]) === bl)
|
|
166
167
|
t.end()
|
|
167
168
|
})
|
|
168
169
|
|
|
169
170
|
tape('append chainable (test results)', function (t) {
|
|
170
171
|
var bl = new BufferList('abc')
|
|
171
172
|
.append([ new BufferList('def') ])
|
|
172
|
-
.append(new BufferList([
|
|
173
|
-
.append([
|
|
173
|
+
.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
|
|
174
|
+
.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
|
|
174
175
|
|
|
175
176
|
t.equal(bl.length, 26)
|
|
176
177
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
|
@@ -180,10 +181,10 @@ tape('append chainable (test results)', function (t) {
|
|
|
180
181
|
tape('consuming from multiple buffers', function (t) {
|
|
181
182
|
var bl = new BufferList()
|
|
182
183
|
|
|
183
|
-
bl.append(
|
|
184
|
-
bl.append(
|
|
185
|
-
bl.append(
|
|
186
|
-
bl.append(
|
|
184
|
+
bl.append(Buffer.from('abcd'))
|
|
185
|
+
bl.append(Buffer.from('efg'))
|
|
186
|
+
bl.append(Buffer.from('hi'))
|
|
187
|
+
bl.append(Buffer.from('j'))
|
|
187
188
|
|
|
188
189
|
t.equal(bl.length, 10)
|
|
189
190
|
|
|
@@ -215,8 +216,8 @@ tape('consuming from multiple buffers', function (t) {
|
|
|
215
216
|
tape('complete consumption', function (t) {
|
|
216
217
|
var bl = new BufferList()
|
|
217
218
|
|
|
218
|
-
bl.append(
|
|
219
|
-
bl.append(
|
|
219
|
+
bl.append(Buffer.from('a'))
|
|
220
|
+
bl.append(Buffer.from('b'))
|
|
220
221
|
|
|
221
222
|
bl.consume(2)
|
|
222
223
|
|
|
@@ -227,9 +228,9 @@ tape('complete consumption', function (t) {
|
|
|
227
228
|
})
|
|
228
229
|
|
|
229
230
|
tape('test readUInt8 / readInt8', function (t) {
|
|
230
|
-
var buf1 =
|
|
231
|
-
, buf2 =
|
|
232
|
-
, buf3 =
|
|
231
|
+
var buf1 = Buffer.alloc(1)
|
|
232
|
+
, buf2 = Buffer.alloc(3)
|
|
233
|
+
, buf3 = Buffer.alloc(3)
|
|
233
234
|
, bl = new BufferList()
|
|
234
235
|
|
|
235
236
|
buf2[1] = 0x3
|
|
@@ -253,9 +254,9 @@ tape('test readUInt8 / readInt8', function (t) {
|
|
|
253
254
|
})
|
|
254
255
|
|
|
255
256
|
tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
|
|
256
|
-
var buf1 =
|
|
257
|
-
, buf2 =
|
|
258
|
-
, buf3 =
|
|
257
|
+
var buf1 = Buffer.alloc(1)
|
|
258
|
+
, buf2 = Buffer.alloc(3)
|
|
259
|
+
, buf3 = Buffer.alloc(3)
|
|
259
260
|
, bl = new BufferList()
|
|
260
261
|
|
|
261
262
|
buf2[1] = 0x3
|
|
@@ -283,9 +284,9 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
|
|
|
283
284
|
})
|
|
284
285
|
|
|
285
286
|
tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
|
|
286
|
-
var buf1 =
|
|
287
|
-
, buf2 =
|
|
288
|
-
, buf3 =
|
|
287
|
+
var buf1 = Buffer.alloc(1)
|
|
288
|
+
, buf2 = Buffer.alloc(3)
|
|
289
|
+
, buf3 = Buffer.alloc(3)
|
|
289
290
|
, bl = new BufferList()
|
|
290
291
|
|
|
291
292
|
buf2[1] = 0x3
|
|
@@ -304,10 +305,54 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
|
|
|
304
305
|
t.end()
|
|
305
306
|
})
|
|
306
307
|
|
|
308
|
+
tape('test readUIntLE / readUIntBE / readIntLE / readIntBE', function (t) {
|
|
309
|
+
var buf1 = Buffer.alloc(1)
|
|
310
|
+
, buf2 = Buffer.alloc(3)
|
|
311
|
+
, buf3 = Buffer.alloc(3)
|
|
312
|
+
, bl = new BufferList()
|
|
313
|
+
|
|
314
|
+
buf2[0] = 0x2
|
|
315
|
+
buf2[1] = 0x3
|
|
316
|
+
buf2[2] = 0x4
|
|
317
|
+
buf3[0] = 0x23
|
|
318
|
+
buf3[1] = 0x42
|
|
319
|
+
buf3[2] = 0x61
|
|
320
|
+
|
|
321
|
+
bl.append(buf1)
|
|
322
|
+
bl.append(buf2)
|
|
323
|
+
bl.append(buf3)
|
|
324
|
+
|
|
325
|
+
t.equal(bl.readUIntBE(1, 1), 0x02)
|
|
326
|
+
t.equal(bl.readUIntBE(1, 2), 0x0203)
|
|
327
|
+
t.equal(bl.readUIntBE(1, 3), 0x020304)
|
|
328
|
+
t.equal(bl.readUIntBE(1, 4), 0x02030423)
|
|
329
|
+
t.equal(bl.readUIntBE(1, 5), 0x0203042342)
|
|
330
|
+
t.equal(bl.readUIntBE(1, 6), 0x020304234261)
|
|
331
|
+
t.equal(bl.readUIntLE(1, 1), 0x02)
|
|
332
|
+
t.equal(bl.readUIntLE(1, 2), 0x0302)
|
|
333
|
+
t.equal(bl.readUIntLE(1, 3), 0x040302)
|
|
334
|
+
t.equal(bl.readUIntLE(1, 4), 0x23040302)
|
|
335
|
+
t.equal(bl.readUIntLE(1, 5), 0x4223040302)
|
|
336
|
+
t.equal(bl.readUIntLE(1, 6), 0x614223040302)
|
|
337
|
+
t.equal(bl.readIntBE(1, 1), 0x02)
|
|
338
|
+
t.equal(bl.readIntBE(1, 2), 0x0203)
|
|
339
|
+
t.equal(bl.readIntBE(1, 3), 0x020304)
|
|
340
|
+
t.equal(bl.readIntBE(1, 4), 0x02030423)
|
|
341
|
+
t.equal(bl.readIntBE(1, 5), 0x0203042342)
|
|
342
|
+
t.equal(bl.readIntBE(1, 6), 0x020304234261)
|
|
343
|
+
t.equal(bl.readIntLE(1, 1), 0x02)
|
|
344
|
+
t.equal(bl.readIntLE(1, 2), 0x0302)
|
|
345
|
+
t.equal(bl.readIntLE(1, 3), 0x040302)
|
|
346
|
+
t.equal(bl.readIntLE(1, 4), 0x23040302)
|
|
347
|
+
t.equal(bl.readIntLE(1, 5), 0x4223040302)
|
|
348
|
+
t.equal(bl.readIntLE(1, 6), 0x614223040302)
|
|
349
|
+
t.end()
|
|
350
|
+
})
|
|
351
|
+
|
|
307
352
|
tape('test readFloatLE / readFloatBE', function (t) {
|
|
308
|
-
var buf1 =
|
|
309
|
-
, buf2 =
|
|
310
|
-
, buf3 =
|
|
353
|
+
var buf1 = Buffer.alloc(1)
|
|
354
|
+
, buf2 = Buffer.alloc(3)
|
|
355
|
+
, buf3 = Buffer.alloc(3)
|
|
311
356
|
, bl = new BufferList()
|
|
312
357
|
|
|
313
358
|
buf2[1] = 0x00
|
|
@@ -324,9 +369,9 @@ tape('test readFloatLE / readFloatBE', function (t) {
|
|
|
324
369
|
})
|
|
325
370
|
|
|
326
371
|
tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
327
|
-
var buf1 =
|
|
328
|
-
, buf2 =
|
|
329
|
-
, buf3 =
|
|
372
|
+
var buf1 = Buffer.alloc(1)
|
|
373
|
+
, buf2 = Buffer.alloc(3)
|
|
374
|
+
, buf3 = Buffer.alloc(10)
|
|
330
375
|
, bl = new BufferList()
|
|
331
376
|
|
|
332
377
|
buf2[1] = 0x55
|
|
@@ -349,10 +394,10 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
|
|
|
349
394
|
tape('test toString', function (t) {
|
|
350
395
|
var bl = new BufferList()
|
|
351
396
|
|
|
352
|
-
bl.append(
|
|
353
|
-
bl.append(
|
|
354
|
-
bl.append(
|
|
355
|
-
bl.append(
|
|
397
|
+
bl.append(Buffer.from('abcd'))
|
|
398
|
+
bl.append(Buffer.from('efg'))
|
|
399
|
+
bl.append(Buffer.from('hi'))
|
|
400
|
+
bl.append(Buffer.from('j'))
|
|
356
401
|
|
|
357
402
|
t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
|
|
358
403
|
t.equal(bl.toString('ascii', 3, 10), 'defghij')
|
|
@@ -365,13 +410,13 @@ tape('test toString', function (t) {
|
|
|
365
410
|
|
|
366
411
|
tape('test toString encoding', function (t) {
|
|
367
412
|
var bl = new BufferList()
|
|
368
|
-
, b =
|
|
413
|
+
, b = Buffer.from('abcdefghij\xff\x00')
|
|
369
414
|
|
|
370
|
-
bl.append(
|
|
371
|
-
bl.append(
|
|
372
|
-
bl.append(
|
|
373
|
-
bl.append(
|
|
374
|
-
bl.append(
|
|
415
|
+
bl.append(Buffer.from('abcd'))
|
|
416
|
+
bl.append(Buffer.from('efg'))
|
|
417
|
+
bl.append(Buffer.from('hi'))
|
|
418
|
+
bl.append(Buffer.from('j'))
|
|
419
|
+
bl.append(Buffer.from('\xff\x00'))
|
|
375
420
|
|
|
376
421
|
encodings.forEach(function (enc) {
|
|
377
422
|
t.equal(bl.toString(enc), b.toString(enc), enc)
|
|
@@ -419,7 +464,7 @@ tape('instantiation with Buffer', function (t) {
|
|
|
419
464
|
|
|
420
465
|
tape('test String appendage', function (t) {
|
|
421
466
|
var bl = new BufferList()
|
|
422
|
-
, b =
|
|
467
|
+
, b = Buffer.from('abcdefghij\xff\x00')
|
|
423
468
|
|
|
424
469
|
bl.append('abcd')
|
|
425
470
|
bl.append('efg')
|
|
@@ -436,7 +481,7 @@ tape('test String appendage', function (t) {
|
|
|
436
481
|
|
|
437
482
|
tape('test Number appendage', function (t) {
|
|
438
483
|
var bl = new BufferList()
|
|
439
|
-
, b =
|
|
484
|
+
, b = Buffer.from('1234567890')
|
|
440
485
|
|
|
441
486
|
bl.append(1234)
|
|
442
487
|
bl.append(567)
|
|
@@ -470,7 +515,7 @@ tape('unicode string', function (t) {
|
|
|
470
515
|
bl.write(' and ')
|
|
471
516
|
bl.write(inp2)
|
|
472
517
|
t.equal(exp, bl.toString())
|
|
473
|
-
t.equal(
|
|
518
|
+
t.equal(Buffer.from(exp).toString('hex'), bl.toString('hex'))
|
|
474
519
|
})
|
|
475
520
|
|
|
476
521
|
tape('should emit finish', function (t) {
|
|
@@ -488,7 +533,7 @@ tape('should emit finish', function (t) {
|
|
|
488
533
|
|
|
489
534
|
tape('basic copy', function (t) {
|
|
490
535
|
var buf = crypto.randomBytes(1024)
|
|
491
|
-
, buf2 =
|
|
536
|
+
, buf2 = Buffer.alloc(1024)
|
|
492
537
|
, b = BufferList(buf)
|
|
493
538
|
|
|
494
539
|
b.copy(buf2)
|
|
@@ -498,7 +543,7 @@ tape('basic copy', function (t) {
|
|
|
498
543
|
|
|
499
544
|
tape('copy after many appends', function (t) {
|
|
500
545
|
var buf = crypto.randomBytes(512)
|
|
501
|
-
, buf2 =
|
|
546
|
+
, buf2 = Buffer.alloc(1024)
|
|
502
547
|
, b = BufferList(buf)
|
|
503
548
|
|
|
504
549
|
b.append(buf)
|
|
@@ -509,7 +554,7 @@ tape('copy after many appends', function (t) {
|
|
|
509
554
|
|
|
510
555
|
tape('copy at a precise position', function (t) {
|
|
511
556
|
var buf = crypto.randomBytes(1004)
|
|
512
|
-
, buf2 =
|
|
557
|
+
, buf2 = Buffer.alloc(1024)
|
|
513
558
|
, b = BufferList(buf)
|
|
514
559
|
|
|
515
560
|
b.copy(buf2, 20)
|
|
@@ -519,7 +564,7 @@ tape('copy at a precise position', function (t) {
|
|
|
519
564
|
|
|
520
565
|
tape('copy starting from a precise location', function (t) {
|
|
521
566
|
var buf = crypto.randomBytes(10)
|
|
522
|
-
, buf2 =
|
|
567
|
+
, buf2 = Buffer.alloc(5)
|
|
523
568
|
, b = BufferList(buf)
|
|
524
569
|
|
|
525
570
|
b.copy(buf2, 0, 5)
|
|
@@ -530,8 +575,8 @@ tape('copy starting from a precise location', function (t) {
|
|
|
530
575
|
tape('copy in an interval', function (t) {
|
|
531
576
|
var rnd = crypto.randomBytes(10)
|
|
532
577
|
, b = BufferList(rnd) // put the random bytes there
|
|
533
|
-
, actual =
|
|
534
|
-
, expected =
|
|
578
|
+
, actual = Buffer.alloc(3)
|
|
579
|
+
, expected = Buffer.alloc(3)
|
|
535
580
|
|
|
536
581
|
rnd.copy(expected, 0, 5, 8)
|
|
537
582
|
b.copy(actual, 0, 5, 8)
|
|
@@ -542,7 +587,7 @@ tape('copy in an interval', function (t) {
|
|
|
542
587
|
|
|
543
588
|
tape('copy an interval between two buffers', function (t) {
|
|
544
589
|
var buf = crypto.randomBytes(10)
|
|
545
|
-
, buf2 =
|
|
590
|
+
, buf2 = Buffer.alloc(10)
|
|
546
591
|
, b = BufferList(buf)
|
|
547
592
|
|
|
548
593
|
b.append(buf)
|
|
@@ -589,7 +634,7 @@ tape('shallow slice with negative or omitted indices', function (t) {
|
|
|
589
634
|
|
|
590
635
|
tape('shallow slice does not make a copy', function (t) {
|
|
591
636
|
t.plan(1)
|
|
592
|
-
var buffers = [
|
|
637
|
+
var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
|
|
593
638
|
var bl = (new BufferList(buffers)).shallowSlice(5, -3)
|
|
594
639
|
|
|
595
640
|
buffers[1].fill('h')
|
package/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules/
|