bitcoin-bufferlist
Advanced tools
Comparing version 0.1.0 to 1.0.0
33
index.js
@@ -11,17 +11,28 @@ // heavily inspired from github.com/rvagg/bl | ||
if (Buffer.isBuffer(s)) | ||
if (!!s) | ||
this.append(s) | ||
else if (Array.isArray(s)) { | ||
s.forEach(function (b) { | ||
Buffer.isBuffer(b) && this.append(b) | ||
}.bind(this)) | ||
} | ||
} | ||
BufferList.prototype.append = function (buf) { | ||
var isBuffer = Buffer.isBuffer(buf) || | ||
buf instanceof BufferList | ||
BufferList.prototype.append = function (s, enc) { | ||
this._bufs.push(isBuffer ? buf : new Buffer(buf)) | ||
this.length += buf.length | ||
if (Buffer.isBuffer(s) || s instanceof BufferList) { | ||
this._bufs.push(s) | ||
this.length += s.length | ||
} else if ('number' === typeof s) { | ||
this._bufs.push(new Buffer([s])) | ||
this.length += this._bufs[this._bufs.length - 1].length | ||
} else if ('string' === typeof s) { | ||
this._bufs.push(new Buffer(s, enc)) | ||
this.length += this._bufs[this._bufs.length - 1].length | ||
} else if (Array.isArray(s)) { | ||
if (Buffer.isBuffer(s[0])) { | ||
s.forEach(function (buf) { | ||
this._bufs.push(buf) | ||
this.length += buf.length | ||
}.bind(this)) | ||
} else { | ||
this._bufs.push(new Buffer(s)) | ||
this.length += this._bufs[this._bufs.length - 1].length | ||
} | ||
} | ||
return this | ||
@@ -28,0 +39,0 @@ } |
{ | ||
"name": "bitcoin-bufferlist", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "A storage object for Node Buffers with handy methods for making bitcoin apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,5 +21,8 @@ # bitcoin-bufferlist *(Bitcoin BufferList)* | ||
bl.append(new Buffer('efg')) | ||
bl.append('hi') // bl will also accept & convert Strings | ||
bl.append(new Buffer('j')) | ||
bl.append(new Buffer([ 0x3, 0x4 ])) | ||
bl.append('hi') // bl will also accept & convert Strings | ||
bl.append('00aa', 'hex') // bl will also accept & convert hex Strings | ||
bl.append(0xff) // bl will also accept & convert Numbers | ||
bl.append([118, 169]) // bl will also accept & convert Arrays | ||
@@ -40,3 +43,2 @@ console.log(bl.length) // 12 | ||
// other standard Buffer readables | ||
console.log(bl.readUInt16BE(10)) // 0x0304 | ||
console.log(bl.readUInt16LE(10)) // 0x0403 | ||
@@ -47,3 +49,3 @@ ``` | ||
* <a href="#ctor"><code><b>new BufferList([ callback ])</b></code></a> | ||
* <a href="#ctor"><code><b>new BufferList([s])</b></code></a> | ||
* <a href="#length"><code>bl.<b>length</b></code></a> | ||
@@ -54,7 +56,15 @@ * <a href="#append"><code>bl.<b>append(buffer)</b></code></a> | ||
* <a href="#copy"><code>bl.<b>copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])</b></code></a> | ||
* <a href="#duplicate"><code>bl.<b>duplicate()</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> | ||
* <a href="#streams">Streams</a> | ||
* <a href="#readXX">, <code>bl.<b>readUInt64LE()</b>, | ||
<code>bl.<b>readUInt32LE()</b></code>, | ||
<code>bl.<b>readUInt32LE()</b></code>, | ||
<code>bl.<b>readUInt16LE()</b></code>, | ||
<code>bl.<b>readUInt8()</b></code></a>, | ||
<code>bl.<b>readVarInt(offset)</b></code></a>, | ||
* <a href="#writeXX">, <code>bl.<b>writeUInt64LE()</b>, | ||
<code>bl.<b>writeUInt32LE()</b></code>, | ||
<code>bl.<b>writeUInt32LE()</b></code>, | ||
<code>bl.<b>writeUInt16LE()</b></code>, | ||
<code>bl.<b>writeUInt8()</b></code></a>, | ||
<code>bl.<b>writeVarInt(n)</b></code></a>, | ||
@@ -61,0 +71,0 @@ -------------------------------------------------------- |
@@ -234,3 +234,3 @@ var BufferList = require('../') | ||
tape.only('test readVarInt', function (t) { | ||
tape('test readVarInt', function (t) { | ||
var buf1 = new Buffer('02', 'hex') | ||
@@ -237,0 +237,0 @@ , buf2 = new Buffer('fdfe00', 'hex') |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21887
465
0
139