Buffer utils that allow you to read and write bytes, strings, ints and floats sequentially.
BufferWriter
var BufferWriter = BufferWriter; var bw = ; // Writes sequentially.bw ; // chaining allowed. // Writes a bufferbw; // Writes a stringbw; // Gets the number of bytes written.var bytesWritten = bwsize; // Gets the contents and resets to empty.var contents = bw; // now bw.size() === 0
BufferReader
var BufferReader = BufferReader; // Wrapper over the buffer that keeps track of the current offset.var br = contents; // Read integers sequentially.// Supports all readInt*, readUInt*, readFloat*, readDouble* from Buffer.var i8 = br; // 0x12var i16 = br; // 0x1234 // Reads a chunk of bytes.// Modifying `buf` will modify `contents` since it is a `slice` of// `contents`.var buf = br; // Reads a stringvar str = br; // hello world // Gets the number of bytes left.var bytesLeft = br; // 0
RetainedBuffer
This is useful for reading a stream of data that is non-seekable and you do not want to store the entire stream in memory (e.g., when the data is huge). This util always retains the last X number of bytes read as you feed data into it, useful for reading variable-sized data followed by a fix-sized footer structure.
var retainedBuf = 16; // retain 16 bytes file;