diff --git a/lib/utils/staticwriter.js b/lib/utils/staticwriter.js index 5fa8e23e..de4f3625 100644 --- a/lib/utils/staticwriter.js +++ b/lib/utils/staticwriter.js @@ -11,18 +11,9 @@ var encoding = require('./encoding'); var crypto = require('../crypto/crypto'); /** - * An object that allows writing of buffers in a - * sane manner. This buffer writer is extremely - * optimized since it does not actually write - * anything until `render` is called. It makes - * one allocation: at the end, once it knows the - * size of the buffer to be allocated. Because - * of this, it can also act as a size calculator - * which is useful for guaging block size - * without actually serializing any data. - * @exports StaticWriter + * Statically allocated buffer writer. * @constructor - * @param {(StaticWriter|Object)?} options + * @param {Number} size */ function StaticWriter(size) { @@ -320,7 +311,9 @@ StaticWriter.prototype.writeBytes = function writeBytes(value) { if (value.length === 0) return; - this.written += value.copy(this.data, this.written); + value.copy(this.data, this.written); + + this.written += value.length; }; /** @@ -402,7 +395,8 @@ StaticWriter.prototype.writeNullString = function writeNullString(value, enc) { StaticWriter.prototype.writeChecksum = function writeChecksum() { var data = this.data.slice(0, this.written); var hash = crypto.hash256(data); - this.written += hash.copy(this.data, this.written, 0, 4); + hash.copy(this.data, this.written, 0, 4); + this.written += 4; }; /** diff --git a/lib/utils/writer.js b/lib/utils/writer.js index 0a709142..6355aa73 100644 --- a/lib/utils/writer.js +++ b/lib/utils/writer.js @@ -53,7 +53,6 @@ var FILL = 24; * without actually serializing any data. * @exports BufferWriter * @constructor - * @param {(BufferWriter|Object)?} options */ function BufferWriter() {