Skip to main content
Version: 11.x.x

📦 parser-byte-length

| npm | github |

import { ByteLengthParser } from '@serialport/parser-byte-length'
// or
const { ByteLengthParser } = require('@serialport/parser-byte-length')

Emit data every number of bytes.

A transform stream that emits data as a buffer after a specific number of bytes are received. Runs in O(n) time.

Constructor Arguments​

interface ByteLengthOptions extends TransformOptions {
/** the number of bytes on each data event */
length: number
}

Example​

const { SerialPort } = require('serialport')
const { ByteLengthParser } = require('@serialport/parser-byte-length')
const port = new SerialPort({ path: '/dev/ROBOT', baudRate: 14400 })

const parser = port.pipe(new ByteLengthParser({ length: 8 }))
parser.on('data', console.log) // will have 8 bytes per data event