bl 2.1.2 → 2.2.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/README.md CHANGED
@@ -15,11 +15,11 @@ The original buffers are kept intact and copies are only done as necessary. Any
15
15
  const BufferList = require('bl')
16
16
 
17
17
  var bl = new BufferList()
18
- bl.append(new Buffer('abcd'))
19
- bl.append(new Buffer('efg'))
18
+ bl.append(Buffer.from('abcd'))
19
+ bl.append(Buffer.from('efg'))
20
20
  bl.append('hi') // bl will also accept & convert Strings
21
- bl.append(new Buffer('j'))
22
- bl.append(new Buffer([ 0x3, 0x4 ]))
21
+ bl.append(Buffer.from('j'))
22
+ bl.append(Buffer.from([ 0x3, 0x4 ]))
23
23
 
24
24
  console.log(bl.length) // 12
25
25
 
@@ -29,6 +29,9 @@ console.log(bl.slice(3, 6).toString('ascii')) // 'def'
29
29
  console.log(bl.slice(3, 8).toString('ascii')) // 'defgh'
30
30
  console.log(bl.slice(5, 10).toString('ascii')) // 'fghij'
31
31
 
32
+ console.log(bl.indexOf('def')) // 3
33
+ console.log(bl.indexOf('asdf')) // -1
34
+
32
35
  // or just use toString!
33
36
  console.log(bl.toString()) // 'abcdefghij\u0003\u0004'
34
37
  console.log(bl.toString('ascii', 3, 8)) // 'defgh'
@@ -72,10 +75,10 @@ const BufferList = require('bl')
72
75
  , fs = require('fs')
73
76
 
74
77
  var bl = new BufferList()
75
- bl.append(new Buffer('abcd'))
76
- bl.append(new Buffer('efg'))
77
- bl.append(new Buffer('hi'))
78
- bl.append(new Buffer('j'))
78
+ bl.append(Buffer.from('abcd'))
79
+ bl.append(Buffer.from('efg'))
80
+ bl.append(Buffer.from('hi'))
81
+ bl.append(Buffer.from('j'))
79
82
 
80
83
  bl.pipe(fs.createWriteStream('gibberish.txt'))
81
84
  ```
@@ -86,6 +89,7 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
86
89
  * <a href="#length"><code>bl.<b>length</b></code></a>
87
90
  * <a href="#append"><code>bl.<b>append(buffer)</b></code></a>
88
91
  * <a href="#get"><code>bl.<b>get(index)</b></code></a>
92
+ * <a href="#indexOf"><code>bl.<b>indexOf(value[, byteOffset][, encoding])</b></code></a>
89
93
  * <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
90
94
  * <a href="#shallowSlice"><code>bl.<b>shallowSlice([ start[, end ] ])</b></code></a>
91
95
  * <a href="#copy"><code>bl.<b>copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])</b></code></a>
@@ -129,6 +133,12 @@ Get the length of the list in bytes. This is the sum of the lengths of all of th
129
133
  ### bl.get(index)
130
134
  `get()` will return the byte at the specified index.
131
135
 
136
+ --------------------------------------------------------
137
+ <a name="indexOf"></a>
138
+ ### bl.indexOf(value[, byteOffset][, encoding])
139
+ `get()` will return the byte at the specified index.
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.
141
+
132
142
  --------------------------------------------------------
133
143
  <a name="slice"></a>
134
144
  ### bl.slice([ start, [ end ] ])
package/bl.js CHANGED
@@ -203,13 +203,16 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
203
203
 
204
204
  BufferList.prototype.shallowSlice = function shallowSlice (start, end) {
205
205
  start = start || 0
206
- end = end || this.length
206
+ end = typeof end !== 'number' ? this.length : end
207
207
 
208
208
  if (start < 0)
209
209
  start += this.length
210
210
  if (end < 0)
211
211
  end += this.length
212
212
 
213
+ if (start === end) {
214
+ return new BufferList()
215
+ }
213
216
  var startOffset = this._offset(start)
214
217
  , endOffset = this._offset(end)
215
218
  , buffers = this._bufs.slice(startOffset[0], endOffset[0] + 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "2.1.2",
3
+ "version": "2.2.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": {
package/test/test.js CHANGED
@@ -649,6 +649,20 @@ tape('shallow slice does not make a copy', function (t) {
649
649
  t.equal(bl.toString(), 'hhhhhhhh')
650
650
  })
651
651
 
652
+ tape('shallow slice with 0 length', function (t) {
653
+ t.plan(1)
654
+ var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
655
+ var bl = (new BufferList(buffers)).shallowSlice(0, 0)
656
+ t.equal(bl.length, 0)
657
+ })
658
+
659
+ tape('shallow slice with 0 length from middle', function (t) {
660
+ t.plan(1)
661
+ var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
662
+ var bl = (new BufferList(buffers)).shallowSlice(10, 10)
663
+ t.equal(bl.length, 0)
664
+ })
665
+
652
666
  tape('duplicate', function (t) {
653
667
  t.plan(2)
654
668