capnp-split
Split up a capnp stream into its individual messages.
Installation
npm i --save capnp-split
or
yarn add capnp-split
Usage
const CapnpStream = ; var msgStream = ;msgStream; fs;
API
new CapnpStream()
=> WritableStream
Creates a new writable stream that takes in buffers and emits a message
event whenever a whole capnp message is readable. Buffers the rest for the next chunk of data.
CapnpStream.readSize(buff, offset)
=> int
Read the total size of the message starting at offset
. This method does not esure that the buffer is long enough to contain the message.
buff
: (Buffer
) The buffer to look at for the size informationoffset
: (optionalNumber
) Defaults to 0. An offset position in bytes to read the size data from.
CapnpStream.readMessage(buff, offset)
=> Buffer
Read the actual message starting at offset
. The result buffer will be a .slice
of the original, meaning the data will not be copied and modifications made to the result will affect the original buffer.
buff
: (Buffer
) The buffer containing the message dataoffset
: (optionalNumber
) Defaults to 0. An offset position in bytes to read the data from.
License
MIT