Nanoscale Parts Manufacturing

    as-buffers

    0.1.2 • 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.

    Install

    npm i as-buffers

    DownloadsWeekly Downloads

    37

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    57.9 kB

    Total Files

    12

    Last publish

    Collaborators

    • yjhmelody