Skip to content

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

optional onError(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
}

Error

The error that occurred

FrameHeader

Partial header if available (undefined if error during header parse)

void


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

FrameHeader

The frame header (same as onFrameStart)

void


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

FrameHeader

Decoded frame header

void


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.

Buffer

Raw payload bytes (process or copy immediately!)

number

Byte offset within total payload (for tracking progress)

boolean

True if this is the final chunk of the frame

void