Documentation
¶
Overview ¶
Package xmodem implements the XMODEM file transfer protocol with support for XMODEM-128 (checksum), XMODEM-CRC, and XMODEM-1K variants.
Index ¶
Constants ¶
const ( SOH = 0x01 // Start of Header (128-byte blocks) STX = 0x02 // Start of Text (1024-byte blocks) EOT = 0x04 // End of Transmission ACK = 0x06 // Acknowledge DLE = 0x10 // Data Link Escape NAK = 0x15 // Negative Acknowledge CAN = 0x18 // Cancel SUB = 0x1A // Substitute (default padding byte) CRC = 'C' // CRC mode request )
XMODEM protocol control bytes.
Variables ¶
var ( // ErrTransferCanceled indicates the transfer was canceled by the remote end // or aborted due to too many errors. ErrTransferCanceled = errors.New("transfer canceled") // ErrSequenceMismatch indicates a received block had an unexpected sequence number. ErrSequenceMismatch = errors.New("sequence number mismatch") // ErrChecksumMismatch indicates a received block failed checksum or CRC verification. ErrChecksumMismatch = errors.New("checksum mismatch") )
Functions ¶
This section is empty.
Types ¶
type Port ¶
type Port interface {
io.ReadWriter
Flush() error
}
Port abstracts a serial port for reading, writing, and flushing. *serial.Port satisfies this interface.
type Xmodem ¶
type Xmodem struct {
Padding byte
Mode Mode
Timeout time.Duration
// contains filtered or unexported fields
}
Xmodem manages an XMODEM file transfer over a Port.
func NewWithPort ¶
NewWithPort creates an Xmodem instance from an existing serial port.
func NewWithReadWriter ¶
NewWithReadWriter creates an Xmodem instance from any Port implementation. This is useful for testing or non-serial transports.
func (Xmodem) Receive ¶
Receive accepts an incoming XMODEM transfer and writes the received data to w. The receiver initiates by sending 'C' (for CRC/1K modes) or NAK (for checksum mode) to the sender. Blocks are verified and acknowledged until the sender signals end of transmission with EOT.
Note: the received data may include trailing padding bytes (default SUB/0x1A) that the sender used to fill the last block. The caller is responsible for stripping padding if the original file size is known.