util: minor changes to static writer.
This commit is contained in:
parent
df4b07304b
commit
8108ff3eb5
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -53,7 +53,6 @@ var FILL = 24;
|
||||
* without actually serializing any data.
|
||||
* @exports BufferWriter
|
||||
* @constructor
|
||||
* @param {(BufferWriter|Object)?} options
|
||||
*/
|
||||
|
||||
function BufferWriter() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user