bl 4.0.0 → 4.0.4

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 CHANGED
@@ -1,15 +1,16 @@
1
1
  sudo: false
2
+ arch:
3
+ - amd64
4
+ - ppc64le
2
5
  language: node_js
3
6
  node_js:
4
7
  - '6'
5
8
  - '8'
6
9
  - '10'
7
10
  - '12'
11
+ - '14'
12
+ - '15'
8
13
  - lts/*
9
- - current
10
- branches:
11
- only:
12
- - master
13
14
  notifications:
14
15
  email:
15
16
  - rod@vagg.org
package/BufferList.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { Buffer } = require('buffer')
3
4
  const symbol = Symbol.for('BufferList')
4
5
 
5
6
  function BufferList (buf) {
@@ -133,12 +134,13 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
133
134
 
134
135
  if (bytes > l) {
135
136
  this._bufs[i].copy(dst, bufoff, start)
137
+ bufoff += l
136
138
  } else {
137
139
  this._bufs[i].copy(dst, bufoff, start, start + bytes)
140
+ bufoff += l
138
141
  break
139
142
  }
140
143
 
141
- bufoff += l
142
144
  bytes -= l
143
145
 
144
146
  if (start) {
@@ -146,6 +148,9 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
146
148
  }
147
149
  }
148
150
 
151
+ // safeguard so that we don't return uninitialized memory
152
+ if (dst.length > bufoff) return dst.slice(0, bufoff)
153
+
149
154
  return dst
150
155
  }
151
156
 
@@ -187,6 +192,11 @@ BufferList.prototype.toString = function toString (encoding, start, end) {
187
192
  }
188
193
 
189
194
  BufferList.prototype.consume = function consume (bytes) {
195
+ // first, normalize the argument, in accordance with how Buffer does it
196
+ bytes = Math.trunc(bytes)
197
+ // do nothing if not a positive number
198
+ if (Number.isNaN(bytes) || bytes <= 0) return this
199
+
190
200
  while (this._bufs.length) {
191
201
  if (bytes >= this._bufs[0].length) {
192
202
  bytes -= this._bufs[0].length
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # bl *(BufferList)*
2
2
 
3
- [![Build Status](https://travis-ci.org/rvagg/bl.svg?branch=master)](https://travis-ci.org/rvagg/bl)
3
+ [![Build Status](https://api.travis-ci.com/rvagg/bl.svg?branch=master)](https://travis-ci.com/rvagg/bl/)
4
4
 
5
5
  **A Node.js Buffer list collector, reader and streamer thingy.**
6
6
 
@@ -72,10 +72,10 @@ hyperquest(url).pipe(BufferListStream((err, data) => {
72
72
  Or, use it as a readable stream to recompose a list of Buffers to an output source:
73
73
 
74
74
  ```js
75
- const { BufferList } = require('bl')
75
+ const { BufferListStream } = require('bl')
76
76
  const fs = require('fs')
77
77
 
78
- var bl = new BufferList()
78
+ var bl = new BufferListStream()
79
79
  bl.append(Buffer.from('abcd'))
80
80
  bl.append(Buffer.from('efg'))
81
81
  bl.append(Buffer.from('hi'))
@@ -171,7 +171,7 @@ No copies will be performed. All buffers in the result share memory with the ori
171
171
  `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:
172
172
 
173
173
  ```js
174
- var bl = new BufferList()
174
+ var bl = new BufferListStream()
175
175
 
176
176
  bl.append('hello')
177
177
  bl.append(' world')
package/bl.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const DuplexStream = require('readable-stream').Duplex
4
- const util = require('util')
4
+ const inherits = require('inherits')
5
5
  const BufferList = require('./BufferList')
6
6
 
7
7
  function BufferListStream (callback) {
@@ -33,7 +33,7 @@ function BufferListStream (callback) {
33
33
  DuplexStream.call(this)
34
34
  }
35
35
 
36
- util.inherits(BufferListStream, DuplexStream)
36
+ inherits(BufferListStream, DuplexStream)
37
37
  Object.assign(BufferListStream.prototype, BufferList.prototype)
38
38
 
39
39
  BufferListStream.prototype._new = function _new (callback) {
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "4.0.0",
3
+ "version": "4.0.4",
4
4
  "description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
5
+ "license": "MIT",
5
6
  "main": "bl.js",
6
7
  "scripts": {
7
8
  "lint": "standard *.js test/*.js",
@@ -23,8 +24,9 @@
23
24
  "stream",
24
25
  "awesomesauce"
25
26
  ],
26
- "license": "MIT",
27
27
  "dependencies": {
28
+ "buffer": "^5.5.0",
29
+ "inherits": "^2.0.4",
28
30
  "readable-stream": "^3.4.0"
29
31
  },
30
32
  "devDependencies": {
package/test/convert.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const tape = require('tape')
4
4
  const { BufferList, BufferListStream } = require('../')
5
- const { Buffer } = require('safe-buffer')
5
+ const { Buffer } = require('buffer')
6
6
 
7
7
  tape('convert from BufferList to BufferListStream', (t) => {
8
8
  const data = Buffer.from(`TEST-${Date.now()}`)
package/test/indexOf.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const tape = require('tape')
4
4
  const BufferList = require('../')
5
- const Buffer = require('safe-buffer').Buffer
5
+ const { Buffer } = require('buffer')
6
6
 
7
7
  tape('indexOf single byte needle', (t) => {
8
8
  const bl = new BufferList(['abcdefg', 'abcdefg', '12345'])
@@ -345,9 +345,9 @@ tape('indexOf the entire nodejs10 buffer test suite', (t) => {
345
345
 
346
346
  // Search for a non-ASCII string in a pure ASCII string.
347
347
  const asciiString = Buffer.from(
348
- 'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf')
348
+ 'somethingnotatallsinisterwhichalsoworks')
349
349
  t.equal(-1, asciiString.indexOf('\x2061'))
350
- t.equal(3, asciiString.indexOf('leb', 0))
350
+ t.equal(3, asciiString.indexOf('eth', 0))
351
351
 
352
352
  // Search in string containing many non-ASCII chars.
353
353
  const allCodePoints = []
@@ -2,7 +2,7 @@
2
2
 
3
3
  const tape = require('tape')
4
4
  const { BufferList, BufferListStream } = require('../')
5
- const { Buffer } = require('safe-buffer')
5
+ const { Buffer } = require('buffer')
6
6
 
7
7
  tape('isBufferList positives', (t) => {
8
8
  t.ok(BufferList.isBufferList(new BufferList()))
package/test/test.js CHANGED
@@ -5,7 +5,7 @@ const crypto = require('crypto')
5
5
  const fs = require('fs')
6
6
  const path = require('path')
7
7
  const BufferList = require('../')
8
- const Buffer = require('safe-buffer').Buffer
8
+ const { Buffer } = require('buffer')
9
9
 
10
10
  const encodings =
11
11
  ('hex utf8 utf-8 ascii binary base64' +
@@ -463,6 +463,22 @@ tape('test toString encoding', function (t) {
463
463
  t.end()
464
464
  })
465
465
 
466
+ tape('uninitialized memory', function (t) {
467
+ const secret = crypto.randomBytes(256)
468
+ for (let i = 0; i < 1e6; i++) {
469
+ const clone = Buffer.from(secret)
470
+ const bl = new BufferList()
471
+ bl.append(Buffer.from('a'))
472
+ bl.consume(-1024)
473
+ const buf = bl.slice(1)
474
+ if (buf.indexOf(clone) !== -1) {
475
+ t.fail(`Match (at ${i})`)
476
+ break
477
+ }
478
+ }
479
+ t.end()
480
+ })
481
+
466
482
  !process.browser && tape('test stream', function (t) {
467
483
  const random = crypto.randomBytes(65534)
468
484