util: minor changes to static writer.

This commit is contained in:
Christopher Jeffrey 2016-12-12 05:38:43 -08:00
parent df4b07304b
commit 8108ff3eb5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 7 additions and 14 deletions

View File

@ -11,18 +11,9 @@ var encoding = require('./encoding');
var crypto = require('../crypto/crypto'); var crypto = require('../crypto/crypto');
/** /**
* An object that allows writing of buffers in a * Statically allocated buffer writer.
* 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
* @constructor * @constructor
* @param {(StaticWriter|Object)?} options * @param {Number} size
*/ */
function StaticWriter(size) { function StaticWriter(size) {
@ -320,7 +311,9 @@ StaticWriter.prototype.writeBytes = function writeBytes(value) {
if (value.length === 0) if (value.length === 0)
return; 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() { StaticWriter.prototype.writeChecksum = function writeChecksum() {
var data = this.data.slice(0, this.written); var data = this.data.slice(0, this.written);
var hash = crypto.hash256(data); 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;
}; };
/** /**

View File

@ -53,7 +53,6 @@ var FILL = 24;
* without actually serializing any data. * without actually serializing any data.
* @exports BufferWriter * @exports BufferWriter
* @constructor * @constructor
* @param {(BufferWriter|Object)?} options
*/ */
function BufferWriter() { function BufferWriter() {