Socket
Socket
Sign inDemoInstall

bl

Package Overview
Dependencies
5
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0 to 0.1.0

6

bl.js

@@ -47,3 +47,3 @@ const DuplexStream = require('readable-stream/duplex')

if (this._callback)
this._callback(this.slice())
this._callback(null, this)
}

@@ -101,2 +101,6 @@

BufferList.prototype.toString = function (encoding, start, end) {
return this.slice(start, end).toString(encoding)
}
BufferList.prototype.consume = function (bytes) {

@@ -103,0 +107,0 @@ while (this._bufs.length) {

4

package.json
{
"name" : "bl"
, "version" : "0.0.0"
, "version" : "0.1.0"
, "description" : "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!"

@@ -30,2 +30,2 @@ , "main" : "bl.js"

}
}
}

@@ -29,2 +29,7 @@ # bl *(BufferList)*

// or just use toString!
console.log(bl.toString('ascii', 3, 8)) // 'defgh'
console.log(bl.toString('ascii', 5, 10)) // 'fghij'
// other standard Buffer readables
console.log(bl.readUInt16BE(10)) // 0x0304

@@ -40,7 +45,7 @@ console.log(bl.readUInt16LE(10)) // 0x0403

var bl = new BufferList(function (data) {
console.log(data.toString())
})
fs.createReadStream('README.md').pipe(bl)
fs.createReadStream('README.md')
.pipe(new BufferList(function (err, data) {
// `data` is just a reference to the BufferList
console.log(data.toString())
})
```

@@ -69,4 +74,5 @@

* <a href="#get"><code>bl.<b>get(index)</b></code></a>
* <a href="#slice"><code>bl.<b>slice([ start ], [ end ])</b></code></a>
* <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
* <a href="#consume"><code>bl.<b>consume(bytes)</b></code></a>
* <a href="#toString"><code>bl.<b>toString([encoding, [ start, [ end ]]])</b></code></a>
* <a href="#readXX"><code>bl.<b>readDoubleBE()</b></code>, <code>bl.<b>readDoubleLE()</b></code>, <code>bl.<b>readFloatBE()</b></code>, <code>bl.<b>readFloatLE()</b></code>, <code>bl.<b>readInt32BE()</b></code>, <code>bl.<b>readInt32LE()</b></code>, <code>bl.<b>readUInt32BE()</b></code>, <code>bl.<b>readUInt32LE()</b></code>, <code>bl.<b>readInt16BE()</b></code>, <code>bl.<b>readInt16LE()</b></code>, <code>bl.<b>readUInt16BE()</b></code>, <code>bl.<b>readUInt16LE()</b></code>, <code>bl.<b>readInt8()</b></code>, <code>bl.<b>readUInt8()</b></code></a>

@@ -78,3 +84,3 @@ * <a href="#streams">Streams</a>

### new BufferList([ callback ])
The constructor takes an optional callback, if supplied, the callback will be called with the total contents of the list, concatenated together (<a href="#slice"><code>bl.slice()</code></a>) when `bl.end()` is called (from a piped stream).
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.

@@ -111,2 +117,7 @@ Normally, no arguments are required for the constructor.

--------------------------------------------------------
<a name="toString"></a>
### bl.toString([encoding, [ start, [ end ]]])
`toString()` will return a string representation of the buffer. The optional `start` and `end` arguments are passed on to `slice()`, while the `encoding` is passed on to `toString()` of the resulting Buffer. See the [Buffer#toString()](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end) documentation for more information.
--------------------------------------------------------
<a name="readXX"></a>

@@ -113,0 +124,0 @@ ### <code>bl.readDoubleBE()</code>, <code>bl.readDoubleLE()</code>, <code>bl.readFloatBE()</code>, <code>bl.readFloatLE()</code>, <code>bl.readInt32BE()</code>, <code>bl.readInt32LE()</code>, <code>bl.readUInt32BE()</code>, <code>bl.readUInt32LE()</code>, <code>bl.readInt16BE()</code>, <code>bl.readInt16LE()</code>, <code>bl.readUInt16BE()</code>, <code>bl.readUInt16LE()</code>, <code>bl.readInt8()</code>, <code>bl.readUInt8()</code>

@@ -229,2 +229,38 @@ const tape = require('tape')

tape('test toString', function (t) {
var bl = new BufferList()
bl.append(new Buffer('abcd'))
bl.append(new Buffer('efg'))
bl.append(new Buffer('hi'))
bl.append(new Buffer('j'))
t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
t.equal(bl.toString('ascii', 3, 10), 'defghij')
t.equal(bl.toString('ascii', 3, 6), 'def')
t.equal(bl.toString('ascii', 3, 8), 'defgh')
t.equal(bl.toString('ascii', 5, 10), 'fghij')
t.end()
})
tape('test toString encoding', function (t) {
var bl = new BufferList()
, b = new Buffer('abcdefghij\xff\x00')
bl.append(new Buffer('abcd'))
bl.append(new Buffer('efg'))
bl.append(new Buffer('hi'))
bl.append(new Buffer('j'))
bl.append(new Buffer('\xff\x00'))
'hex utf8 utf-8 ascii binary base64 ucs2 ucs-2 utf16le utf-16le'
.split(' ')
.forEach(function (enc) {
t.equal(bl.toString(enc), b.toString(enc))
})
t.end()
})
tape('test stream', function (t) {

@@ -234,3 +270,5 @@ var random = crypto.randomBytes(1024 * 1024)

, rndhash
, bl = new BufferList(function () {
, bl = new BufferList(function (err, _bl) {
t.ok(bl === _bl)
t.ok(err === null)
md5sum = crypto.createHash('md5')

@@ -237,0 +275,0 @@ md5sum.update(bl.slice())

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