This module makes it easy to send and receive length-prefixed byte arrays over streams.
import { lpStream } from 'it-length-prefixed-stream'const stream = lpStream(duplex)// read the next length-prefixed chunkconst bytes = await stream.read()// write a length-prefixed chunkawait stream.write(Uint8Array.from([0, 1, 2, 3, 4]))// write several chunks, all individually length-prefixedawait stream.writeV([ Uint8Array.from([0, 1, 2, 3, 4]), Uint8Array.from([5, 6, 7, 8, 9])]) Copy
import { lpStream } from 'it-length-prefixed-stream'const stream = lpStream(duplex)// read the next length-prefixed chunkconst bytes = await stream.read()// write a length-prefixed chunkawait stream.write(Uint8Array.from([0, 1, 2, 3, 4]))// write several chunks, all individually length-prefixedawait stream.writeV([ Uint8Array.from([0, 1, 2, 3, 4]), Uint8Array.from([5, 6, 7, 8, 9])])
This module makes it easy to send and receive length-prefixed byte arrays over streams.
Example