Socket
Socket
Sign inDemoInstall

bl

Package Overview
Dependencies
7
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.1.1

36

bl.js

@@ -27,9 +27,4 @@ var DuplexStream = require('readable-stream/duplex')

})
}
else if (Buffer.isBuffer(callback))
} else {
this.append(callback)
else if (Array.isArray(callback)) {
callback.forEach(function (b) {
Buffer.isBuffer(b) && this.append(b)
}.bind(this))
}

@@ -53,16 +48,21 @@

BufferList.prototype.append = function (buf) {
var isBuffer = Buffer.isBuffer(buf) ||
buf instanceof BufferList
var i = 0
, newBuf
// coerce number arguments to strings, since Buffer(number) does
// uninitialized memory allocation
if (typeof buf == 'number')
buf = buf.toString()
if (Array.isArray(buf)) {
for (; i < buf.length; i++)
this.append(buf[i])
} else if (buf instanceof BufferList) {
// unwrap argument into individual BufferLists
for (; i < buf._bufs.length; i++)
this.append(buf._bufs[i])
} else if (buf != null) {
// coerce number arguments to strings, since Buffer(number) does
// uninitialized memory allocation
if (typeof buf == 'number')
buf = buf.toString()
if (buf instanceof BufferList) {
this._bufs.push.apply(this._bufs, buf._bufs)
this.length += buf.length
} else {
this._bufs.push(isBuffer ? buf : new Buffer(buf))
this.length += buf.length
newBuf = Buffer.isBuffer(buf) ? buf : new Buffer(buf)
this._bufs.push(newBuf)
this.length += newBuf.length
}

@@ -69,0 +69,0 @@

{
"name": "bl",
"version": "1.0.3",
"version": "1.1.1",
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",

@@ -5,0 +5,0 @@ "main": "bl.js",

@@ -99,3 +99,3 @@ # bl *(BufferList)*

<a name="ctor"></a>
### new BufferList([ callback | buffer | buffer array ])
### new BufferList([ callback | Buffer | Buffer array | BufferList | BufferList array | String ])
The constructor takes an optional callback, if supplied, the callback will be called with an error argument followed by a reference to the **bl** instance, when `bl.end()` is called (i.e. from a piped stream). This is a convenient method of collecting the entire contents of a stream, particularly when the stream is *chunky*, such as a network stream.

@@ -124,4 +124,4 @@

<a name="append"></a>
### bl.append(buffer)
`append(buffer)` adds an additional buffer or BufferList to the internal list.
### bl.append(Buffer | Buffer array | BufferList | BufferList array | String)
`append(buffer)` adds an additional buffer or BufferList to the internal list. `this` is returned so it can be chained.

@@ -128,0 +128,0 @@ --------------------------------------------------------

@@ -82,4 +82,4 @@ var tape = require('tape')

bl.append(new BufferList([new Buffer('abcd'), new Buffer('efg')]))
bl.append(new BufferList([new Buffer('hi'), new Buffer('j')]))
bl.append(new BufferList([ new Buffer('abcd'), new Buffer('efg') ]))
bl.append(new BufferList([ new Buffer('hi'), new Buffer('j') ]))

@@ -89,2 +89,3 @@ t.equal(bl.length, 10)

t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')

@@ -98,2 +99,70 @@ t.equal(bl.slice(3, 6).toString('ascii'), 'def')

// same data as previous test, just using nested constructors
tape('multiple bytes from crazy nested buffer lists', function (t) {
var bl = new BufferList()
bl.append(new BufferList([
new BufferList([
new BufferList(new Buffer('abc'))
, new Buffer('d')
, new BufferList(new Buffer('efg'))
])
, new BufferList([ new Buffer('hi') ])
, new BufferList(new Buffer('j'))
]))
t.equal(bl.length, 10)
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
t.end()
})
tape('append accepts arrays of Buffers', function (t) {
var bl = new BufferList()
bl.append(new Buffer('abc'))
bl.append([ new Buffer('def') ])
bl.append([ new Buffer('ghi'), new Buffer('jkl') ])
bl.append([ new Buffer('mnop'), new Buffer('qrstu'), new Buffer('vwxyz') ])
t.equal(bl.length, 26)
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
t.end()
})
tape('append accepts arrays of BufferLists', function (t) {
var bl = new BufferList()
bl.append(new Buffer('abc'))
bl.append([ new BufferList('def') ])
bl.append(new BufferList([ new Buffer('ghi'), new BufferList('jkl') ]))
bl.append([ new Buffer('mnop'), new BufferList([ new Buffer('qrstu'), new Buffer('vwxyz') ]) ])
t.equal(bl.length, 26)
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
t.end()
})
tape('append chainable', function (t) {
var bl = new BufferList()
t.ok(bl.append(new Buffer('abcd')) === bl)
t.ok(bl.append([ new Buffer('abcd') ]) === bl)
t.ok(bl.append(new BufferList(new Buffer('abcd'))) === bl)
t.ok(bl.append([ new BufferList(new Buffer('abcd')) ]) === bl)
t.end()
})
tape('append chainable (test results)', function (t) {
var bl = new BufferList('abc')
.append([ new BufferList('def') ])
.append(new BufferList([ new Buffer('ghi'), new BufferList('jkl') ]))
.append([ new Buffer('mnop'), new BufferList([ new Buffer('qrstu'), new Buffer('vwxyz') ]) ])
t.equal(bl.length, 26)
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
t.end()
})
tape('consuming from multiple buffers', function (t) {

@@ -100,0 +169,0 @@ var bl = new BufferList()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc