bl 7.0.14 → 7.0.15

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.js CHANGED
@@ -71,7 +71,7 @@ export class BufferList {
71
71
  * @returns {number | undefined}
72
72
  */
73
73
  get (index) {
74
- if (index > this.length || index < 0) {
74
+ if (index >= this.length || index < 0) {
75
75
  return undefined
76
76
  }
77
77
 
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [7.0.15](https://github.com/rvagg/bl/compare/v7.0.14...v7.0.15) (2026-11-13)
2
+
3
+ ### Bug Fixes
4
+
5
+ * handle get on empty lists ([#190](https://github.com/rvagg/bl/issues/190)) ([39b2047](https://github.com/rvagg/bl/commit/39b204765312de24043106baf484a116a018c3df))
6
+
1
7
  ## [7.0.14](https://github.com/rvagg/bl/compare/v7.0.13...v7.0.14) (2026-10-30)
2
8
 
3
9
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "7.0.14",
3
+ "version": "7.0.15",
4
4
  "description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/test/test.js CHANGED
@@ -1030,3 +1030,31 @@ tape('destroy with error', function (t) {
1030
1030
  t.notOk(data, 'no data')
1031
1031
  }))
1032
1032
  })
1033
+
1034
+ tape('get handles empty lists', async function (t) {
1035
+ const { BufferList } = await import('../BufferListStream.js')
1036
+
1037
+ for (const Type of [BufferList, BufferListStream]) {
1038
+ const name = Type.name
1039
+ const list = new Type()
1040
+ const emptyGet = () => {
1041
+ try {
1042
+ return { value: list.get(0) }
1043
+ } catch (error) {
1044
+ return { error }
1045
+ }
1046
+ }
1047
+
1048
+ t.deepEqual(emptyGet(), { value: undefined }, `${name}: new empty list`)
1049
+ list.append(Buffer.from('a'))
1050
+ t.equal(list.get(0), 97, `${name}: first byte after append`)
1051
+ t.equal(list.get(1), undefined, `${name}: nonempty end index`)
1052
+ t.equal(list.get(-1), undefined, `${name}: negative index`)
1053
+ list.consume(1)
1054
+ t.deepEqual(emptyGet(), { value: undefined }, `${name}: fully consumed list`)
1055
+ list.append(Buffer.from('b'))
1056
+ t.equal(list.get(0), 98, `${name}: reuse after consumption`)
1057
+ }
1058
+
1059
+ t.end()
1060
+ })