1.2.2 • Published 11 months ago

byte-rw v1.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

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.

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.0.0

11 months ago