[Pkg-javascript-commits] [node-bl] 01/03: New upstream version 1.1.2

Paolo Greppi paolog-guest at moszumanska.debian.org
Sun Dec 4 14:11:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

paolog-guest pushed a commit to branch master
in repository node-bl.

commit 4117acde8324e2a4c8dc0092465753488491bf6c
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Sun Dec 4 12:38:09 2016 +0000

    New upstream version 1.1.2
---
 .travis.yml        |   8 +-
 README.md          |  15 +-
 bl.js              |  89 +++++---
 package.json       |  12 +-
 test/basic-test.js | 541 --------------------------------------------
 test/sauce.js      |  38 ----
 test/test.js       | 643 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 7 files changed, 715 insertions(+), 631 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 7ddb9c9..5cb0480 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,13 @@
+sudo: false
 language: node_js
 node_js:
-  - 0.8
-  - "0.10"
+  - '0.10'
+  - '0.12'
+  - '4'
+  - '5'
 branches:
   only:
     - master
 notifications:
   email:
     - rod at vagg.org
-script: npm test
\ No newline at end of file
diff --git a/README.md b/README.md
index 1753cc4..f7044db 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
 # bl *(BufferList)*
 
+[![Build Status](https://travis-ci.org/rvagg/bl.svg?branch=master)](https://travis-ci.org/rvagg/bl)
+
 **A Node.js Buffer list collector, reader and streamer thingy.**
 
 [![NPM](https://nodei.co/npm/bl.png?downloads=true&downloadRank=true)](https://nodei.co/npm/bl/)
@@ -94,7 +96,7 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
 
 --------------------------------------------------------
 <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.
 
 Normally, no arguments are required for the constructor, but you can initialise the list by passing in a single `Buffer` object or an array of `Buffer` object.
@@ -118,8 +120,8 @@ Get the length of the list in bytes. This is the sum of the lengths of all of th
 
 --------------------------------------------------------
 <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.
 
 --------------------------------------------------------
 <a name="get"></a>
@@ -190,6 +192,9 @@ See the <b><code>[Buffer](http://nodejs.org/docs/latest/api/buffer.html)</code><
 
 =======
 
-## License
+<a name="license"></a>
+## License & copyright
+
+Copyright (c) 2013-2014 bl contributors (listed above).
 
-**bl** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
+bl is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
diff --git a/bl.js b/bl.js
index d1ea3b5..f585df1 100644
--- a/bl.js
+++ b/bl.js
@@ -1,6 +1,7 @@
-var DuplexStream = require('readable-stream').Duplex
+var DuplexStream = require('readable-stream/duplex')
   , util         = require('util')
 
+
 function BufferList (callback) {
   if (!(this instanceof BufferList))
     return new BufferList(callback)
@@ -11,34 +12,31 @@ function BufferList (callback) {
   if (typeof callback == 'function') {
     this._callback = callback
 
-    var piper = function (err) {
+    var piper = function piper (err) {
       if (this._callback) {
         this._callback(err)
         this._callback = null
       }
     }.bind(this)
 
-    this.on('pipe', function (src) {
+    this.on('pipe', function onPipe (src) {
       src.on('error', piper)
     })
-    this.on('unpipe', function (src) {
+    this.on('unpipe', function onUnpipe (src) {
       src.removeListener('error', piper)
     })
-  }
-  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))
   }
 
   DuplexStream.call(this)
 }
 
+
 util.inherits(BufferList, DuplexStream)
 
-BufferList.prototype._offset = function (offset) {
+
+BufferList.prototype._offset = function _offset (offset) {
   var tot = 0, i = 0, _t
   for (; i < this._bufs.length; i++) {
     _t = tot + this._bufs[i].length
@@ -48,30 +46,52 @@ BufferList.prototype._offset = function (offset) {
   }
 }
 
-BufferList.prototype.append = function (buf) {
-  var isBuffer = Buffer.isBuffer(buf) ||
-                 buf instanceof BufferList
 
-  this._bufs.push(isBuffer ? buf : new Buffer(buf))
-  this.length += buf.length
+BufferList.prototype.append = function append (buf) {
+  var i = 0
+    , newBuf
+
+  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()
+
+    newBuf = Buffer.isBuffer(buf) ? buf : new Buffer(buf)
+    this._bufs.push(newBuf)
+    this.length += newBuf.length
+  }
+
   return this
 }
 
-BufferList.prototype._write = function (buf, encoding, callback) {
+
+BufferList.prototype._write = function _write (buf, encoding, callback) {
   this.append(buf)
-  if (callback)
+
+  if (typeof callback == 'function')
     callback()
 }
 
-BufferList.prototype._read = function (size) {
+
+BufferList.prototype._read = function _read (size) {
   if (!this.length)
     return this.push(null)
+
   size = Math.min(size, this.length)
   this.push(this.slice(0, size))
   this.consume(size)
 }
 
-BufferList.prototype.end = function (chunk) {
+
+BufferList.prototype.end = function end (chunk) {
   DuplexStream.prototype.end.call(this, chunk)
 
   if (this._callback) {
@@ -80,15 +100,18 @@ BufferList.prototype.end = function (chunk) {
   }
 }
 
-BufferList.prototype.get = function (index) {
+
+BufferList.prototype.get = function get (index) {
   return this.slice(index, index + 1)[0]
 }
 
-BufferList.prototype.slice = function (start, end) {
+
+BufferList.prototype.slice = function slice (start, end) {
   return this.copy(null, 0, start, end)
 }
 
-BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
+
+BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
   if (typeof srcStart != 'number' || srcStart < 0)
     srcStart = 0
   if (typeof srcEnd != 'number' || srcEnd > this.length)
@@ -151,13 +174,13 @@ BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
   return dst
 }
 
-BufferList.prototype.toString = function (encoding, start, end) {
+BufferList.prototype.toString = function toString (encoding, start, end) {
   return this.slice(start, end).toString(encoding)
 }
 
-BufferList.prototype.consume = function (bytes) {
+BufferList.prototype.consume = function consume (bytes) {
   while (this._bufs.length) {
-    if (bytes > this._bufs[0].length) {
+    if (bytes >= this._bufs[0].length) {
       bytes -= this._bufs[0].length
       this.length -= this._bufs[0].length
       this._bufs.shift()
@@ -170,7 +193,8 @@ BufferList.prototype.consume = function (bytes) {
   return this
 }
 
-BufferList.prototype.duplicate = function () {
+
+BufferList.prototype.duplicate = function duplicate () {
   var i = 0
     , copy = new BufferList()
 
@@ -180,12 +204,14 @@ BufferList.prototype.duplicate = function () {
   return copy
 }
 
-BufferList.prototype.destroy = function () {
-  this._bufs.length = 0;
-  this.length = 0;
-  this.push(null);
+
+BufferList.prototype.destroy = function destroy () {
+  this._bufs.length = 0
+  this.length = 0
+  this.push(null)
 }
 
+
 ;(function () {
   var methods = {
       'readDoubleBE' : 8
@@ -213,4 +239,5 @@ BufferList.prototype.destroy = function () {
   }
 }())
 
+
 module.exports = BufferList
diff --git a/package.json b/package.json
index f5a1e44..aac62e3 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,10 @@
 {
   "name": "bl",
-  "version": "0.9.3",
+  "version": "1.1.2",
   "description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
   "main": "bl.js",
   "scripts": {
-    "test": "node test/test.js | faucet",
-    "test-local": "brtapsauce-local test/basic-test.js"
+    "test": "node test/test.js | faucet"
   },
   "repository": {
     "type": "git",
@@ -25,12 +24,11 @@
   ],
   "license": "MIT",
   "dependencies": {
-    "readable-stream": "~1.0.26"
+    "readable-stream": "~2.0.5"
   },
   "devDependencies": {
-    "tape": "~2.12.3",
+    "faucet": "0.0.1",
     "hash_file": "~0.1.1",
-    "faucet": "~0.0.1",
-    "brtapsauce": "~0.3.0"
+    "tape": "~4.4.0"
   }
 }
diff --git a/test/basic-test.js b/test/basic-test.js
deleted file mode 100644
index 75116a3..0000000
--- a/test/basic-test.js
+++ /dev/null
@@ -1,541 +0,0 @@
-var tape       = require('tape')
-  , crypto     = require('crypto')
-  , fs         = require('fs')
-  , hash       = require('hash_file')
-  , BufferList = require('../')
-
-  , encodings  =
-      ('hex utf8 utf-8 ascii binary base64'
-          + (process.browser ? '' : ' ucs2 ucs-2 utf16le utf-16le')).split(' ')
-
-tape('single bytes from single buffer', function (t) {
-  var bl = new BufferList()
-  bl.append(new Buffer('abcd'))
-
-  t.equal(bl.length, 4)
-
-  t.equal(bl.get(0), 97)
-  t.equal(bl.get(1), 98)
-  t.equal(bl.get(2), 99)
-  t.equal(bl.get(3), 100)
-
-  t.end()
-})
-
-tape('single bytes from multiple buffers', 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.length, 10)
-
-  t.equal(bl.get(0), 97)
-  t.equal(bl.get(1), 98)
-  t.equal(bl.get(2), 99)
-  t.equal(bl.get(3), 100)
-  t.equal(bl.get(4), 101)
-  t.equal(bl.get(5), 102)
-  t.equal(bl.get(6), 103)
-  t.equal(bl.get(7), 104)
-  t.equal(bl.get(8), 105)
-  t.equal(bl.get(9), 106)
-  t.end()
-})
-
-tape('multi bytes from single buffer', function (t) {
-  var bl = new BufferList()
-  bl.append(new Buffer('abcd'))
-
-  t.equal(bl.length, 4)
-
-  t.equal(bl.slice(0, 4).toString('ascii'), 'abcd')
-  t.equal(bl.slice(0, 3).toString('ascii'), 'abc')
-  t.equal(bl.slice(1, 4).toString('ascii'), 'bcd')
-
-  t.end()
-})
-
-tape('multiple bytes from multiple buffers', 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.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('multiple bytes from multiple buffer lists', function (t) {
-  var bl = new BufferList()
-
-  bl.append(new BufferList([new Buffer('abcd'), new Buffer('efg')]))
-  bl.append(new BufferList([new Buffer('hi'), 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('consuming from multiple buffers', 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.length, 10)
-
-  t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
-
-  bl.consume(3)
-  t.equal(bl.length, 7)
-  t.equal(bl.slice(0, 7).toString('ascii'), 'defghij')
-
-  bl.consume(2)
-  t.equal(bl.length, 5)
-  t.equal(bl.slice(0, 5).toString('ascii'), 'fghij')
-
-  bl.consume(1)
-  t.equal(bl.length, 4)
-  t.equal(bl.slice(0, 4).toString('ascii'), 'ghij')
-
-  bl.consume(1)
-  t.equal(bl.length, 3)
-  t.equal(bl.slice(0, 3).toString('ascii'), 'hij')
-
-  bl.consume(2)
-  t.equal(bl.length, 1)
-  t.equal(bl.slice(0, 1).toString('ascii'), 'j')
-
-  t.end()
-})
-
-tape('test readUInt8 / readInt8', function (t) {
-  var buf1 = new Buffer(1)
-    , buf2 = new Buffer(3)
-    , buf3 = new Buffer(3)
-    , bl  = new BufferList()
-
-  buf2[1] = 0x3
-  buf2[2] = 0x4
-  buf3[0] = 0x23
-  buf3[1] = 0x42
-
-  bl.append(buf1)
-  bl.append(buf2)
-  bl.append(buf3)
-
-  t.equal(bl.readUInt8(2), 0x3)
-  t.equal(bl.readInt8(2), 0x3)
-  t.equal(bl.readUInt8(3), 0x4)
-  t.equal(bl.readInt8(3), 0x4)
-  t.equal(bl.readUInt8(4), 0x23)
-  t.equal(bl.readInt8(4), 0x23)
-  t.equal(bl.readUInt8(5), 0x42)
-  t.equal(bl.readInt8(5), 0x42)
-  t.end()
-})
-
-tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
-  var buf1 = new Buffer(1)
-    , buf2 = new Buffer(3)
-    , buf3 = new Buffer(3)
-    , bl   = new BufferList()
-
-  buf2[1] = 0x3
-  buf2[2] = 0x4
-  buf3[0] = 0x23
-  buf3[1] = 0x42
-
-  bl.append(buf1)
-  bl.append(buf2)
-  bl.append(buf3)
-
-  t.equal(bl.readUInt16BE(2), 0x0304)
-  t.equal(bl.readUInt16LE(2), 0x0403)
-  t.equal(bl.readInt16BE(2), 0x0304)
-  t.equal(bl.readInt16LE(2), 0x0403)
-  t.equal(bl.readUInt16BE(3), 0x0423)
-  t.equal(bl.readUInt16LE(3), 0x2304)
-  t.equal(bl.readInt16BE(3), 0x0423)
-  t.equal(bl.readInt16LE(3), 0x2304)
-  t.equal(bl.readUInt16BE(4), 0x2342)
-  t.equal(bl.readUInt16LE(4), 0x4223)
-  t.equal(bl.readInt16BE(4), 0x2342)
-  t.equal(bl.readInt16LE(4), 0x4223)
-  t.end()
-})
-
-tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
-  var buf1 = new Buffer(1)
-    , buf2 = new Buffer(3)
-    , buf3 = new Buffer(3)
-    , bl   = new BufferList()
-
-  buf2[1] = 0x3
-  buf2[2] = 0x4
-  buf3[0] = 0x23
-  buf3[1] = 0x42
-
-  bl.append(buf1)
-  bl.append(buf2)
-  bl.append(buf3)
-
-  t.equal(bl.readUInt32BE(2), 0x03042342)
-  t.equal(bl.readUInt32LE(2), 0x42230403)
-  t.equal(bl.readInt32BE(2), 0x03042342)
-  t.equal(bl.readInt32LE(2), 0x42230403)
-  t.end()
-})
-
-tape('test readFloatLE / readFloatBE', function (t) {
-  var buf1 = new Buffer(1)
-    , buf2 = new Buffer(3)
-    , buf3 = new Buffer(3)
-    , bl   = new BufferList()
-
-  buf2[1] = 0x00
-  buf2[2] = 0x00
-  buf3[0] = 0x80
-  buf3[1] = 0x3f
-
-  bl.append(buf1)
-  bl.append(buf2)
-  bl.append(buf3)
-
-  t.equal(bl.readFloatLE(2), 0x01)
-  t.end()
-})
-
-tape('test readDoubleLE / readDoubleBE', function (t) {
-  var buf1 = new Buffer(1)
-    , buf2 = new Buffer(3)
-    , buf3 = new Buffer(10)
-    , bl   = new BufferList()
-
-  buf2[1] = 0x55
-  buf2[2] = 0x55
-  buf3[0] = 0x55
-  buf3[1] = 0x55
-  buf3[2] = 0x55
-  buf3[3] = 0x55
-  buf3[4] = 0xd5
-  buf3[5] = 0x3f
-
-  bl.append(buf1)
-  bl.append(buf2)
-  bl.append(buf3)
-
-  t.equal(bl.readDoubleLE(2), 0.3333333333333333)
-  t.end()
-})
-
-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'))
-
-  encodings.forEach(function (enc) {
-      t.equal(bl.toString(enc), b.toString(enc), enc)
-    })
-
-  t.end()
-})
-
-!process.browser && tape('test stream', function (t) {
-  var random = crypto.randomBytes(65534)
-    , rndhash = hash(random, 'md5')
-    , md5sum = crypto.createHash('md5')
-    , bl     = new BufferList(function (err, buf) {
-        t.ok(Buffer.isBuffer(buf))
-        t.ok(err === null)
-        t.equal(rndhash, hash(bl.slice(), 'md5'))
-        t.equal(rndhash, hash(buf, 'md5'))
-
-        bl.pipe(fs.createWriteStream('/tmp/bl_test_rnd_out.dat'))
-          .on('close', function () {
-            var s = fs.createReadStream('/tmp/bl_test_rnd_out.dat')
-            s.on('data', md5sum.update.bind(md5sum))
-            s.on('end', function() {
-              t.equal(rndhash, md5sum.digest('hex'), 'woohoo! correct hash!')
-              t.end()
-            })
-          })
-
-      })
-
-  fs.writeFileSync('/tmp/bl_test_rnd.dat', random)
-  fs.createReadStream('/tmp/bl_test_rnd.dat').pipe(bl)
-})
-
-tape('instantiation with Buffer', function (t) {
-  var buf  = crypto.randomBytes(1024)
-    , buf2 = crypto.randomBytes(1024)
-    , b    = BufferList(buf)
-
-  t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
-  b = BufferList([ buf, buf2 ])
-  t.equal(b.slice().toString('hex'), Buffer.concat([ buf, buf2 ]).toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('test String appendage', function (t) {
-  var bl = new BufferList()
-    , b  = new Buffer('abcdefghij\xff\x00')
-
-  bl.append('abcd')
-  bl.append('efg')
-  bl.append('hi')
-  bl.append('j')
-  bl.append('\xff\x00')
-
-  encodings.forEach(function (enc) {
-      t.equal(bl.toString(enc), b.toString(enc))
-    })
-
-  t.end()
-})
-
-tape('write nothing, should get empty buffer', function (t) {
-  t.plan(3)
-  BufferList(function (err, data) {
-    t.notOk(err, 'no error')
-    t.ok(Buffer.isBuffer(data), 'got a buffer')
-    t.equal(0, data.length, 'got a zero-length buffer')
-    t.end()
-  }).end()
-})
-
-tape('unicode string', function (t) {
-  t.plan(2)
-  var inp1 = '\u2600'
-    , inp2 = '\u2603'
-    , exp = inp1 + ' and ' + inp2
-    , bl = BufferList()
-  bl.write(inp1)
-  bl.write(' and ')
-  bl.write(inp2)
-  t.equal(exp, bl.toString())
-  t.equal(new Buffer(exp).toString('hex'), bl.toString('hex'))
-})
-
-tape('should emit finish', function (t) {
-  var source = BufferList()
-    , dest = BufferList()
-
-  source.write('hello')
-  source.pipe(dest)
-
-  dest.on('finish', function () {
-    t.equal(dest.toString('utf8'), 'hello')
-    t.end()
-  })
-})
-
-tape('basic copy', function (t) {
-  var buf  = crypto.randomBytes(1024)
-    , buf2 = new Buffer(1024)
-    , b    = BufferList(buf)
-
-  b.copy(buf2)
-  t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('copy after many appends', function (t) {
-  var buf  = crypto.randomBytes(512)
-    , buf2 = new Buffer(1024)
-    , b    = BufferList(buf)
-
-  b.append(buf)
-  b.copy(buf2)
-  t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('copy at a precise position', function (t) {
-  var buf  = crypto.randomBytes(1004)
-    , buf2 = new Buffer(1024)
-    , b    = BufferList(buf)
-
-  b.copy(buf2, 20)
-  t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('copy starting from a precise location', function (t) {
-  var buf  = crypto.randomBytes(10)
-    , buf2 = new Buffer(5)
-    , b    = BufferList(buf)
-
-  b.copy(buf2, 0, 5)
-  t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('copy in an interval', function (t) {
-  var rnd      = crypto.randomBytes(10)
-    , b        = BufferList(rnd) // put the random bytes there
-    , actual   = new Buffer(3)
-    , expected = new Buffer(3)
-
-  rnd.copy(expected, 0, 5, 8)
-  b.copy(actual, 0, 5, 8)
-
-  t.equal(actual.toString('hex'), expected.toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('copy an interval between two buffers', function (t) {
-  var buf      = crypto.randomBytes(10)
-    , buf2     = new Buffer(10)
-    , b        = BufferList(buf)
-
-  b.append(buf)
-  b.copy(buf2, 0, 5, 15)
-
-  t.equal(b.slice(5, 15).toString('hex'), buf2.toString('hex'), 'same buffer')
-  t.end()
-})
-
-tape('duplicate', function (t) {
-  t.plan(2)
-
-  var bl = new BufferList('abcdefghij\xff\x00')
-    , dup = bl.duplicate()
-
-  t.equal(bl.prototype, dup.prototype)
-  t.equal(bl.toString('hex'), dup.toString('hex'))
-})
-
-tape('destroy no pipe', function (t) {
-  t.plan(2)
-
-  var bl = new BufferList('alsdkfja;lsdkfja;lsdk')
-  bl.destroy()
-
-  t.equal(bl._bufs.length, 0)
-  t.equal(bl.length, 0)
-})
-
-!process.browser && tape('destroy with pipe before read end', function (t) {
-  t.plan(2)
-
-  var bl = new BufferList()
-  fs.createReadStream(__dirname + '/sauce.js')
-    .pipe(bl)
-
-  bl.destroy()
-
-  t.equal(bl._bufs.length, 0)
-  t.equal(bl.length, 0)
-
-})
-
-!process.browser && tape('destroy with pipe before read end with race', function (t) {
-  t.plan(2)
-
-  var bl = new BufferList()
-  fs.createReadStream(__dirname + '/sauce.js')
-    .pipe(bl)
-
-  setTimeout(function () {
-    bl.destroy()
-    setTimeout(function () {
-      t.equal(bl._bufs.length, 0)
-      t.equal(bl.length, 0)
-    }, 500)
-  }, 500)
-})
-
-!process.browser && tape('destroy with pipe after read end', function (t) {
-  t.plan(2)
-
-  var bl = new BufferList()
-  fs.createReadStream(__dirname + '/sauce.js')
-    .on('end', onEnd)
-    .pipe(bl)
-
-  function onEnd () {
-    bl.destroy()
-
-    t.equal(bl._bufs.length, 0)
-    t.equal(bl.length, 0)
-  }
-})
-
-!process.browser && tape('destroy with pipe while writing to a destination', function (t) {
-  t.plan(4)
-
-  var bl = new BufferList()
-    , ds = new BufferList()
-
-  fs.createReadStream(__dirname + '/sauce.js')
-    .on('end', onEnd)
-    .pipe(bl)
-
-  function onEnd () {
-    bl.pipe(ds)
-
-    setTimeout(function () {
-      bl.destroy()
-
-      t.equals(bl._bufs.length, 0)
-      t.equals(bl.length, 0)
-
-      ds.destroy()
-
-      t.equals(bl._bufs.length, 0)
-      t.equals(bl.length, 0)
-
-    }, 100)
-  }
-})
-
-!process.browser && tape('handle error', function (t) {
-  t.plan(2)
-  fs.createReadStream('/does/not/exist').pipe(BufferList(function (err, data) {
-    t.ok(err instanceof Error, 'has error')
-    t.notOk(data, 'no data')
-  }))
-})
diff --git a/test/sauce.js b/test/sauce.js
deleted file mode 100644
index a6d2862..0000000
--- a/test/sauce.js
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env node
-
-const user       = process.env.SAUCE_USER
-    , key        = process.env.SAUCE_KEY
-    , path       = require('path')
-    , brtapsauce = require('brtapsauce')
-    , testFile   = path.join(__dirname, 'basic-test.js')
-
-    , capabilities = [
-          { browserName: 'chrome'            , platform: 'Windows XP', version: ''   }
-        , { browserName: 'firefox'           , platform: 'Windows 8' , version: ''   }
-        , { browserName: 'firefox'           , platform: 'Windows XP', version: '4'  }
-        , { browserName: 'internet explorer' , platform: 'Windows 8' , version: '10' }
-        , { browserName: 'internet explorer' , platform: 'Windows 7' , version: '9'  }
-        , { browserName: 'internet explorer' , platform: 'Windows 7' , version: '8'  }
-        , { browserName: 'internet explorer' , platform: 'Windows XP', version: '7'  }
-        , { browserName: 'internet explorer' , platform: 'Windows XP', version: '6'  }
-        , { browserName: 'safari'            , platform: 'Windows 7' , version: '5'  }
-        , { browserName: 'safari'            , platform: 'OS X 10.8' , version: '6'  }
-        , { browserName: 'opera'             , platform: 'Windows 7' , version: ''   }
-        , { browserName: 'opera'             , platform: 'Windows 7' , version: '11' }
-        , { browserName: 'ipad'              , platform: 'OS X 10.8' , version: '6'  }
-        , { browserName: 'android'           , platform: 'Linux'     , version: '4.0', 'device-type': 'tablet' }
-      ]
-
-if (!user)
-  throw new Error('Must set a SAUCE_USER env var')
-if (!key)
-  throw new Error('Must set a SAUCE_KEY env var')
-
-brtapsauce({
-    name         : 'Traversty'
-  , user         : user
-  , key          : key
-  , brsrc        : testFile
-  , capabilities : capabilities
-  , options      : { timeout: 60 * 6 }
-})
\ No newline at end of file
diff --git a/test/test.js b/test/test.js
index aa9b487..c95b1ba 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,9 +1,640 @@
-require('./basic-test')
+var tape       = require('tape')
+  , crypto     = require('crypto')
+  , fs         = require('fs')
+  , hash       = require('hash_file')
+  , BufferList = require('../')
 
-if (!process.env.SAUCE_KEY || !process.env.SAUCE_USER)
-  return console.log('SAUCE_KEY and/or SAUCE_USER not set, not running sauce tests')
+  , encodings  =
+      ('hex utf8 utf-8 ascii binary base64'
+          + (process.browser ? '' : ' ucs2 ucs-2 utf16le utf-16le')).split(' ')
 
-if (!/v0\.10/.test(process.version))
-  return console.log('Not Node v0.10.x, not running sauce tests')
+tape('single bytes from single buffer', function (t) {
+  var bl = new BufferList()
+  bl.append(new Buffer('abcd'))
 
-require('./sauce.js')
\ No newline at end of file
+  t.equal(bl.length, 4)
+
+  t.equal(bl.get(0), 97)
+  t.equal(bl.get(1), 98)
+  t.equal(bl.get(2), 99)
+  t.equal(bl.get(3), 100)
+
+  t.end()
+})
+
+tape('single bytes from multiple buffers', 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.length, 10)
+
+  t.equal(bl.get(0), 97)
+  t.equal(bl.get(1), 98)
+  t.equal(bl.get(2), 99)
+  t.equal(bl.get(3), 100)
+  t.equal(bl.get(4), 101)
+  t.equal(bl.get(5), 102)
+  t.equal(bl.get(6), 103)
+  t.equal(bl.get(7), 104)
+  t.equal(bl.get(8), 105)
+  t.equal(bl.get(9), 106)
+  t.end()
+})
+
+tape('multi bytes from single buffer', function (t) {
+  var bl = new BufferList()
+  bl.append(new Buffer('abcd'))
+
+  t.equal(bl.length, 4)
+
+  t.equal(bl.slice(0, 4).toString('ascii'), 'abcd')
+  t.equal(bl.slice(0, 3).toString('ascii'), 'abc')
+  t.equal(bl.slice(1, 4).toString('ascii'), 'bcd')
+
+  t.end()
+})
+
+tape('multiple bytes from multiple buffers', 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.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('multiple bytes from multiple buffer lists', function (t) {
+  var bl = new BufferList()
+
+  bl.append(new BufferList([ new Buffer('abcd'), new Buffer('efg') ]))
+  bl.append(new BufferList([ new Buffer('hi'), 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()
+})
+
+// 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) {
+  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.length, 10)
+
+  t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
+
+  bl.consume(3)
+  t.equal(bl.length, 7)
+  t.equal(bl.slice(0, 7).toString('ascii'), 'defghij')
+
+  bl.consume(2)
+  t.equal(bl.length, 5)
+  t.equal(bl.slice(0, 5).toString('ascii'), 'fghij')
+
+  bl.consume(1)
+  t.equal(bl.length, 4)
+  t.equal(bl.slice(0, 4).toString('ascii'), 'ghij')
+
+  bl.consume(1)
+  t.equal(bl.length, 3)
+  t.equal(bl.slice(0, 3).toString('ascii'), 'hij')
+
+  bl.consume(2)
+  t.equal(bl.length, 1)
+  t.equal(bl.slice(0, 1).toString('ascii'), 'j')
+
+  t.end()
+})
+
+tape('complete consumption', function (t) {
+  var bl = new BufferList()
+
+  bl.append(new Buffer('a'))
+  bl.append(new Buffer('b'))
+
+  bl.consume(2)
+
+  t.equal(bl.length, 0)
+  t.equal(bl._bufs.length, 0)
+
+  t.end()
+})
+
+tape('test readUInt8 / readInt8', function (t) {
+  var buf1 = new Buffer(1)
+    , buf2 = new Buffer(3)
+    , buf3 = new Buffer(3)
+    , bl  = new BufferList()
+
+  buf2[1] = 0x3
+  buf2[2] = 0x4
+  buf3[0] = 0x23
+  buf3[1] = 0x42
+
+  bl.append(buf1)
+  bl.append(buf2)
+  bl.append(buf3)
+
+  t.equal(bl.readUInt8(2), 0x3)
+  t.equal(bl.readInt8(2), 0x3)
+  t.equal(bl.readUInt8(3), 0x4)
+  t.equal(bl.readInt8(3), 0x4)
+  t.equal(bl.readUInt8(4), 0x23)
+  t.equal(bl.readInt8(4), 0x23)
+  t.equal(bl.readUInt8(5), 0x42)
+  t.equal(bl.readInt8(5), 0x42)
+  t.end()
+})
+
+tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
+  var buf1 = new Buffer(1)
+    , buf2 = new Buffer(3)
+    , buf3 = new Buffer(3)
+    , bl   = new BufferList()
+
+  buf2[1] = 0x3
+  buf2[2] = 0x4
+  buf3[0] = 0x23
+  buf3[1] = 0x42
+
+  bl.append(buf1)
+  bl.append(buf2)
+  bl.append(buf3)
+
+  t.equal(bl.readUInt16BE(2), 0x0304)
+  t.equal(bl.readUInt16LE(2), 0x0403)
+  t.equal(bl.readInt16BE(2), 0x0304)
+  t.equal(bl.readInt16LE(2), 0x0403)
+  t.equal(bl.readUInt16BE(3), 0x0423)
+  t.equal(bl.readUInt16LE(3), 0x2304)
+  t.equal(bl.readInt16BE(3), 0x0423)
+  t.equal(bl.readInt16LE(3), 0x2304)
+  t.equal(bl.readUInt16BE(4), 0x2342)
+  t.equal(bl.readUInt16LE(4), 0x4223)
+  t.equal(bl.readInt16BE(4), 0x2342)
+  t.equal(bl.readInt16LE(4), 0x4223)
+  t.end()
+})
+
+tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
+  var buf1 = new Buffer(1)
+    , buf2 = new Buffer(3)
+    , buf3 = new Buffer(3)
+    , bl   = new BufferList()
+
+  buf2[1] = 0x3
+  buf2[2] = 0x4
+  buf3[0] = 0x23
+  buf3[1] = 0x42
+
+  bl.append(buf1)
+  bl.append(buf2)
+  bl.append(buf3)
+
+  t.equal(bl.readUInt32BE(2), 0x03042342)
+  t.equal(bl.readUInt32LE(2), 0x42230403)
+  t.equal(bl.readInt32BE(2), 0x03042342)
+  t.equal(bl.readInt32LE(2), 0x42230403)
+  t.end()
+})
+
+tape('test readFloatLE / readFloatBE', function (t) {
+  var buf1 = new Buffer(1)
+    , buf2 = new Buffer(3)
+    , buf3 = new Buffer(3)
+    , bl   = new BufferList()
+
+  buf2[1] = 0x00
+  buf2[2] = 0x00
+  buf3[0] = 0x80
+  buf3[1] = 0x3f
+
+  bl.append(buf1)
+  bl.append(buf2)
+  bl.append(buf3)
+
+  t.equal(bl.readFloatLE(2), 0x01)
+  t.end()
+})
+
+tape('test readDoubleLE / readDoubleBE', function (t) {
+  var buf1 = new Buffer(1)
+    , buf2 = new Buffer(3)
+    , buf3 = new Buffer(10)
+    , bl   = new BufferList()
+
+  buf2[1] = 0x55
+  buf2[2] = 0x55
+  buf3[0] = 0x55
+  buf3[1] = 0x55
+  buf3[2] = 0x55
+  buf3[3] = 0x55
+  buf3[4] = 0xd5
+  buf3[5] = 0x3f
+
+  bl.append(buf1)
+  bl.append(buf2)
+  bl.append(buf3)
+
+  t.equal(bl.readDoubleLE(2), 0.3333333333333333)
+  t.end()
+})
+
+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'))
+
+  encodings.forEach(function (enc) {
+      t.equal(bl.toString(enc), b.toString(enc), enc)
+    })
+
+  t.end()
+})
+
+!process.browser && tape('test stream', function (t) {
+  var random = crypto.randomBytes(65534)
+    , rndhash = hash(random, 'md5')
+    , md5sum = crypto.createHash('md5')
+    , bl     = new BufferList(function (err, buf) {
+        t.ok(Buffer.isBuffer(buf))
+        t.ok(err === null)
+        t.equal(rndhash, hash(bl.slice(), 'md5'))
+        t.equal(rndhash, hash(buf, 'md5'))
+
+        bl.pipe(fs.createWriteStream('/tmp/bl_test_rnd_out.dat'))
+          .on('close', function () {
+            var s = fs.createReadStream('/tmp/bl_test_rnd_out.dat')
+            s.on('data', md5sum.update.bind(md5sum))
+            s.on('end', function() {
+              t.equal(rndhash, md5sum.digest('hex'), 'woohoo! correct hash!')
+              t.end()
+            })
+          })
+
+      })
+
+  fs.writeFileSync('/tmp/bl_test_rnd.dat', random)
+  fs.createReadStream('/tmp/bl_test_rnd.dat').pipe(bl)
+})
+
+tape('instantiation with Buffer', function (t) {
+  var buf  = crypto.randomBytes(1024)
+    , buf2 = crypto.randomBytes(1024)
+    , b    = BufferList(buf)
+
+  t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
+  b = BufferList([ buf, buf2 ])
+  t.equal(b.slice().toString('hex'), Buffer.concat([ buf, buf2 ]).toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('test String appendage', function (t) {
+  var bl = new BufferList()
+    , b  = new Buffer('abcdefghij\xff\x00')
+
+  bl.append('abcd')
+  bl.append('efg')
+  bl.append('hi')
+  bl.append('j')
+  bl.append('\xff\x00')
+
+  encodings.forEach(function (enc) {
+      t.equal(bl.toString(enc), b.toString(enc))
+    })
+
+  t.end()
+})
+
+tape('test Number appendage', function (t) {
+  var bl = new BufferList()
+    , b  = new Buffer('1234567890')
+
+  bl.append(1234)
+  bl.append(567)
+  bl.append(89)
+  bl.append(0)
+
+  encodings.forEach(function (enc) {
+      t.equal(bl.toString(enc), b.toString(enc))
+    })
+
+  t.end()
+})
+
+tape('write nothing, should get empty buffer', function (t) {
+  t.plan(3)
+  BufferList(function (err, data) {
+    t.notOk(err, 'no error')
+    t.ok(Buffer.isBuffer(data), 'got a buffer')
+    t.equal(0, data.length, 'got a zero-length buffer')
+    t.end()
+  }).end()
+})
+
+tape('unicode string', function (t) {
+  t.plan(2)
+  var inp1 = '\u2600'
+    , inp2 = '\u2603'
+    , exp = inp1 + ' and ' + inp2
+    , bl = BufferList()
+  bl.write(inp1)
+  bl.write(' and ')
+  bl.write(inp2)
+  t.equal(exp, bl.toString())
+  t.equal(new Buffer(exp).toString('hex'), bl.toString('hex'))
+})
+
+tape('should emit finish', function (t) {
+  var source = BufferList()
+    , dest = BufferList()
+
+  source.write('hello')
+  source.pipe(dest)
+
+  dest.on('finish', function () {
+    t.equal(dest.toString('utf8'), 'hello')
+    t.end()
+  })
+})
+
+tape('basic copy', function (t) {
+  var buf  = crypto.randomBytes(1024)
+    , buf2 = new Buffer(1024)
+    , b    = BufferList(buf)
+
+  b.copy(buf2)
+  t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('copy after many appends', function (t) {
+  var buf  = crypto.randomBytes(512)
+    , buf2 = new Buffer(1024)
+    , b    = BufferList(buf)
+
+  b.append(buf)
+  b.copy(buf2)
+  t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('copy at a precise position', function (t) {
+  var buf  = crypto.randomBytes(1004)
+    , buf2 = new Buffer(1024)
+    , b    = BufferList(buf)
+
+  b.copy(buf2, 20)
+  t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('copy starting from a precise location', function (t) {
+  var buf  = crypto.randomBytes(10)
+    , buf2 = new Buffer(5)
+    , b    = BufferList(buf)
+
+  b.copy(buf2, 0, 5)
+  t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('copy in an interval', function (t) {
+  var rnd      = crypto.randomBytes(10)
+    , b        = BufferList(rnd) // put the random bytes there
+    , actual   = new Buffer(3)
+    , expected = new Buffer(3)
+
+  rnd.copy(expected, 0, 5, 8)
+  b.copy(actual, 0, 5, 8)
+
+  t.equal(actual.toString('hex'), expected.toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('copy an interval between two buffers', function (t) {
+  var buf      = crypto.randomBytes(10)
+    , buf2     = new Buffer(10)
+    , b        = BufferList(buf)
+
+  b.append(buf)
+  b.copy(buf2, 0, 5, 15)
+
+  t.equal(b.slice(5, 15).toString('hex'), buf2.toString('hex'), 'same buffer')
+  t.end()
+})
+
+tape('duplicate', function (t) {
+  t.plan(2)
+
+  var bl = new BufferList('abcdefghij\xff\x00')
+    , dup = bl.duplicate()
+
+  t.equal(bl.prototype, dup.prototype)
+  t.equal(bl.toString('hex'), dup.toString('hex'))
+})
+
+tape('destroy no pipe', function (t) {
+  t.plan(2)
+
+  var bl = new BufferList('alsdkfja;lsdkfja;lsdk')
+  bl.destroy()
+
+  t.equal(bl._bufs.length, 0)
+  t.equal(bl.length, 0)
+})
+
+!process.browser && tape('destroy with pipe before read end', function (t) {
+  t.plan(2)
+
+  var bl = new BufferList()
+  fs.createReadStream(__dirname + '/test.js')
+    .pipe(bl)
+
+  bl.destroy()
+
+  t.equal(bl._bufs.length, 0)
+  t.equal(bl.length, 0)
+
+})
+
+!process.browser && tape('destroy with pipe before read end with race', function (t) {
+  t.plan(2)
+
+  var bl = new BufferList()
+  fs.createReadStream(__dirname + '/test.js')
+    .pipe(bl)
+
+  setTimeout(function () {
+    bl.destroy()
+    setTimeout(function () {
+      t.equal(bl._bufs.length, 0)
+      t.equal(bl.length, 0)
+    }, 500)
+  }, 500)
+})
+
+!process.browser && tape('destroy with pipe after read end', function (t) {
+  t.plan(2)
+
+  var bl = new BufferList()
+  fs.createReadStream(__dirname + '/test.js')
+    .on('end', onEnd)
+    .pipe(bl)
+
+  function onEnd () {
+    bl.destroy()
+
+    t.equal(bl._bufs.length, 0)
+    t.equal(bl.length, 0)
+  }
+})
+
+!process.browser && tape('destroy with pipe while writing to a destination', function (t) {
+  t.plan(4)
+
+  var bl = new BufferList()
+    , ds = new BufferList()
+
+  fs.createReadStream(__dirname + '/test.js')
+    .on('end', onEnd)
+    .pipe(bl)
+
+  function onEnd () {
+    bl.pipe(ds)
+
+    setTimeout(function () {
+      bl.destroy()
+
+      t.equals(bl._bufs.length, 0)
+      t.equals(bl.length, 0)
+
+      ds.destroy()
+
+      t.equals(bl._bufs.length, 0)
+      t.equals(bl.length, 0)
+
+    }, 100)
+  }
+})
+
+!process.browser && tape('handle error', function (t) {
+  t.plan(2)
+  fs.createReadStream('/does/not/exist').pipe(BufferList(function (err, data) {
+    t.ok(err instanceof Error, 'has error')
+    t.notOk(data, 'no data')
+  }))
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-bl.git



More information about the Pkg-javascript-commits mailing list