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

1.2.2 • Public • Published

byte-rw

Reading and writing at the byte level is easy with byte-rw. It exposes two interfaces like the DataView object but is adaptable for streams or other implementations.

const littleEndian = true

const writer_inMemory = new DataViewByteWriterChunkedDynamic(littleEndian)
writeData(writer_inMemory)
const data = writer_inMemory.combineChunks() // ArrayBuffer
console.log(data)

const stream: WritableStream = ...
const writer_stream = new StreamByteWriter(stream)
writeData(writer_stream)

function writeData(writer: ByteWriter) {
    const endianness = writer.littleEndian
    writer.writeUint16(0xABCD)
    writer.writeUint16(0x1234)

    writer.littleEndian = false
    writer.writeUint32(0xCC0011FF)

    writer.littleEndian = endianness
}

See also the ByteBuffer for another buffer interface. It must have well more performance and is more mature though appears limited to working with in-memory buffers; this package may have more flexibility and can work with streams.

Appreciation

Mocha + typescript + ES modules: Henry Ruhs

Function annotations largely adapted from type declarations in lib.es5.d.ts.

Package Sidebar

Install

npm i byte-rw

Weekly Downloads

4

Version

1.2.2

License

MIT

Unpacked Size

145 kB

Total Files

104

Last publish

Collaborators

  • i12345