Nietzsche's Preposterous Moustache

    bytebuf
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.1 • Public • Published

    bytebuf

    A byte buffer for encoding and decoding binary data in JavaScript. Supports the major web browsers, NodeJS, Deno, and Cloudflare Workers.

    Install

    npm i bytebuf

    Usage

    import { ByteBuf } from "bytebuf"
    
    const data = new Uint8Array(1024)
    const buffer = ByteBuf.from(data)
    
    buffer.writeInt32(16)
    buffer.writeString("Encoding is fun!")
    buffer.setInt16(4, 25924, true)
    buffer.writeVarInt(49)
    
    console.log(buffer.byteOffset) // 21
    buffer.reset()
    
    const byteLength = buffer.readInt32() // 16
    console.log(buffer.readString(byteLength)) // "Decoding is fun!"
    console.log(buffer.getVarInt(20)) // { value: 49, byteLength: 1 }

    Install

    npm i bytebuf

    DownloadsWeekly Downloads

    1

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    54.9 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar