simple-buffer-cursor
Simplify reading and writing to buffers by internally maintaining the position. This library exposes a wrapper for a buffer that uses similar read and write methods to those found in the Node Buffer API.
Usage:
npm install simple-buffer-cursor
const BufferCursor = ; let buffer = ;buffer;buffer;buffer;buffer;bufferposition = 0;console;console;console;console;
API
-
position: number
- the current buffer cursor position -
eof: bool
- whether the current position is at the end of the buffer -
buffer: Buffer
- the underlying buffer -
readUInt8(): number
- reads 1 byte -
readUInt16LE(): number
- reads 2 bytes as 16-bit little-endian unsigned integer -
readUInt16BE(): number
- reads 2 bytes as 16-bit big-endian unsigned integer -
readUInt32LE(): number
- reads 4 bytes as 32-bit little-endian unsigned integer -
readUInt32BE(): number
- reads 4 bytes as 32-bit big-endian unsigned integer -
readBytes([len]): Buffer
- reads the optionally specified number of bytes. If no length is supplied, it reads to the end of the buffer. -
writeUInt8(number): undefined
- writes 1 byte -
writeUInt16LE(number): undefined
- writes a number as a 16-bit little-endian unsigned integer -
writeUInt16BE(number): undefined
- writes a number as a 16-bit big-endian unsigned integer -
writeUInt32LE(number): undefined
- writes a number as a 32-bit little-endian unsigned integer -
writeUInt32BE(number): undefined
- writes a number as a 32-bit big-endian unsigned integer -
writeBytes(buffer): undefined
- writes the supplied buffer to the cursor buffer