Interface: FrameReaderOptions
Options for FrameReader.
All tolerance opts default to false, every framing deviation throws unless
explicitly enabled. Server-level defaults (allowFsOnly, allowLfAfterFs, allowLeadingWhitespace)
are applied by the server when constructing readers.
Example
const opts: FrameReaderOptions = {
onFrame: (payload, byteOffset, warnings) => process(payload, byteOffset, warnings),
onWarning: (w) => logger.warn(w),
maxFrameSizeBytes: 4 * 1024 * 1024, // 4 MiB limit
allowFsOnly: true,
allowLfAfterFs: true,
};
Properties
allowFsOnly?
optionalallowFsOnly?:boolean
Tolerate FS without trailing CR; emits MLLP_FS_WITHOUT_CR.
allowLeadingWhitespace?
optionalallowLeadingWhitespace?:boolean
Tolerate SP/TAB/LF/CR before VT; emits MLLP_LEADING_WHITESPACE.
allowLfAfterFs?
optionalallowLfAfterFs?:boolean
Tolerate FS+LF instead of FS+CR; emits MLLP_LF_AFTER_FS.
allowMissingLeadingVt?
optionalallowMissingLeadingVt?:boolean
Tolerate missing leading VT; emits MLLP_MISSING_LEADING_VT.
maxFrameSizeBytes?
optionalmaxFrameSizeBytes?:number
Maximum accumulated payload bytes before MllpFramingError('MLLP_FRAME_TOO_LARGE').
Default: 16 MiB (DoS prevention).
onFrame
onFrame: (
payload,byteOffset,warnings) =>void
Called synchronously during push() for each complete MLLP payload.
Parameters
payload
Buffer
Raw MLLP payload bytes (framing stripped).
byteOffset
number
Stream byte offset of the VT byte that opened this frame.
Monotonic across the connection lifetime; reset to 0 by reset().
warnings
readonly MllpWarning[]
Framing warnings emitted during decoding of this specific frame. Empty array when no tolerance deviations were detected.
Returns
void
onWarning?
optionalonWarning?: (w) =>void
Called for each tolerated framing deviation. Wrapped in try/catch. A throwing handler will not corrupt FSM state.
Parameters
w
Returns
void
strict?
optionalstrict?:boolean
When true, escalates the following tolerances to thrown MllpFramingError
even if individual opt-ins (allowFsOnly, allowLfAfterFs, allowMissingLeadingVt,
allowLeadingWhitespace) are enabled:
MLLP_MISSING_LEADING_VTMLLP_FS_WITHOUT_CRMLLP_LF_AFTER_FSMLLP_LEADING_WHITESPACE(leading whitespace escalates asMLLP_MISSING_LEADING_VT)
MLLP_EMPTY_PAYLOAD and MLLP_TRAILING_BYTES remain warnings even in strict mode.
Example
// Hardened enforcement, no tolerance, all violations throw
const reader = new FrameReader({ onFrame: fn, strict: true });