FrameStreamHandler
Defined in: packages/protocol/src/frame-buffer.ts:120
Callback interface for streaming mode.
Use streaming mode when:
- Payloads are very large (100MB+)
- You want to write directly to disk as data arrives
- You want to pipe to another socket
- You need minimal memory footprint
- You need lowest possible latency
Methods
Section titled “Methods”onError()?
Section titled “onError()?”
optionalonError(error,header?):void
Defined in: packages/protocol/src/frame-buffer.ts:177
Called when an error occurs during frame parsing.
IMPORTANT: After onError, the stream is in an undefined state. Binary protocol errors (malformed header, size mismatch) typically mean the stream is corrupted and cannot be recovered.
Recommended action: Close the connection!
onError(error, header) { console.error('Frame error:', error); socket.destroy(); // Cannot recover from binary corruption}Parameters
Section titled “Parameters”Error
The error that occurred
header?
Section titled “header?”Partial header if available (undefined if error during header parse)
Returns
Section titled “Returns”void
onFrameEnd()
Section titled “onFrameEnd()”onFrameEnd(
header):void
Defined in: packages/protocol/src/frame-buffer.ts:157
Called when frame is complete. All payload chunks have been delivered.
Use this to:
- Close output file
- Finalize processing
- Emit completion event
Parameters
Section titled “Parameters”header
Section titled “header”The frame header (same as onFrameStart)
Returns
Section titled “Returns”void
onFrameStart()
Section titled “onFrameStart()”onFrameStart(
header):void
Defined in: packages/protocol/src/frame-buffer.ts:132
Called when frame header is parsed. You know the methodId, requestId, flags, and total payload size.
Use this to:
- Open output file
- Prepare destination buffer
- Initialize processing state
Parameters
Section titled “Parameters”header
Section titled “header”Decoded frame header
Returns
Section titled “Returns”void
onPayloadChunk()
Section titled “onPayloadChunk()”onPayloadChunk(
chunk,offset,isLast):void
Defined in: packages/protocol/src/frame-buffer.ts:144
Called for each payload chunk as it arrives.
IMPORTANT: Process immediately or copy! The chunk buffer may be reused after this call returns.
Parameters
Section titled “Parameters”Buffer
Raw payload bytes (process or copy immediately!)
offset
Section titled “offset”number
Byte offset within total payload (for tracking progress)
isLast
Section titled “isLast”boolean
True if this is the final chunk of the frame
Returns
Section titled “Returns”void