Class: BufferWriter

utils.BufferWriter

new BufferWriter()

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.

Source:

Methods

copy(value, start, end)

Copy bytes.

Parameters:
Name Type Description
value Buffer
start Number
end Number
Source:

destroy()

Destroy the buffer writer. Remove references to ops.

Source:

fill(value, size)

Fill N bytes with value.

Parameters:
Name Type Description
value Number
size Number
Source:

getSize() → {Number}

Get size of data written so far.

Source:
Returns:
Type
Number

render(keepnullable) → {Buffer}

Allocate and render the final buffer.

Parameters:
Name Type Attributes Description
keep Boolean <nullable>

Do not destroy the writer.

Source:
Returns:

Rendered buffer.

Type
Buffer

seek(offset)

Seek to relative offset.

Parameters:
Name Type Description
offset Number
Source:

write8(value)

Write int8.

Parameters:
Name Type Description
value Number
Source:

write16(value)

Write int16le.

Parameters:
Name Type Description
value Number
Source:

write16BE(value)

Write int16be.

Parameters:
Name Type Description
value Number
Source:

write32(value)

Write int32le.

Parameters:
Name Type Description
value Number
Source:

write32BE(value)

Write int32be.

Parameters:
Name Type Description
value Number
Source:

write64(value)

Write int64le.

Parameters:
Name Type Description
value Number
Source:

write64BE(value)

Write int64be.

Parameters:
Name Type Description
value Number
Source:

write64BEBN(value)

Write int64be.

Parameters:
Name Type Description
value BN
Source:

write64BN(value)

Write int64le.

Parameters:
Name Type Description
value BN
Source:

writeBytes(value)

Write bytes.

Parameters:
Name Type Description
value Buffer
Source:

writeChecksum()

Calculate and write a checksum for the data written so far.

Source:

writeDouble(value)

Write double le.

Parameters:
Name Type Description
value Number
Source:

writeDoubleBE(value)

Write double be.

Parameters:
Name Type Description
value Number
Source:

writeFloat(value)

Write float le.

Parameters:
Name Type Description
value Number
Source:

writeFloatBE(value)

Write float be.

Parameters:
Name Type Description
value Number
Source:

writeHash(value)

Write a 32 byte hash.

Parameters:
Name Type Description
value Hash
Source:

writeNullString(value, encnullable)

Write a null-terminated string.

Parameters:
Name Type Attributes Description
value String | Buffer
enc String <nullable>

Any buffer-supported encoding.

Source:

writeString(value, encnullable)

Write string to buffer.

Parameters:
Name Type Attributes Description
value String
enc String <nullable>

Any buffer-supported encoding.

Source:

writeU8(value)

Write uint8.

Parameters:
Name Type Description
value Number
Source:

writeU16(value)

Write uint16le.

Parameters:
Name Type Description
value Number
Source:

writeU16BE(value)

Write uint16be.

Parameters:
Name Type Description
value Number
Source:

writeU32(value)

Write uint32le.

Parameters:
Name Type Description
value Number
Source:

writeU32BE(value)

Write uint32be.

Parameters:
Name Type Description
value Number
Source:

writeU64(value)

Write uint64le.

Parameters:
Name Type Description
value Number
Source:

writeU64BE(value)

Write uint64be.

Parameters:
Name Type Description
value Number
Source:

writeU64BEBN(value)

Write uint64be.

Parameters:
Name Type Description
value BN
Source:

writeU64BN(value)

Write uint64le.

Parameters:
Name Type Description
value BN
Source:

writeVarBytes(value)

Write bytes with a varint length before them.

Parameters:
Name Type Description
value Buffer
Source:

writeVarint(value)

Write a varint.

Parameters:
Name Type Description
value Number
Source:

writeVarint2(value)

Write a varint (type 2).

Parameters:
Name Type Description
value Number
Source:

writeVarint2BN(value)

Write a varint (type 2).

Parameters:
Name Type Description
value BN
Source:

writeVarintBN(value)

Write a varint.

Parameters:
Name Type Description
value BN
Source:

writeVarString(value, encnullable)

Write a string with a varint length before it.

Parameters:
Name Type Attributes Description
value String
enc String <nullable>

Any buffer-supported encoding.

Source: