as-buffers

0.3.0 • Public • Published

as-buffers

as-buffers provides some Buffer types for reading/writing string/bytes efficiently and simply.

Usage

There are 2 useful buffer classes here: BytesBuffer and StringBuffer.

  • BytesBuffer provides bytes related/endian related methods.
  • StringBuffer(is forked from MaxGraey) provides string (UTF16) related methods.

Write/Read bytes

let buf = BytesBuffer.wrap(new ArrayBuffer(0));
let val = 0x11 as i8;
buf.writeNumberBE<i8>(val);
let res = buf.readNumberBE<i8>(0);
expect(res).toBe(val);

Write/Read string

let buf = new StringBuffer();
buf.write("hello");
expect(buf.toString()).toBe("hello");

More usages

In addition to some safe methods, they also have some unsafe methods to improve performance. You need to pay attention to the buffer capacity and read/write offset.

See unit tests and source comments.

/as-buffers/

    Package Sidebar

    Install

    npm i as-buffers

    Weekly Downloads

    3

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    52.2 kB

    Total Files

    11

    Last publish

    Collaborators

    • yjhmelody